From 66020c403e3cd02ea1ebdf45a0b948005c575db5 Mon Sep 17 00:00:00 2001 From: Berry Wahlberg <40695099+BerryUIKI@users.noreply.github.com> Date: Fri, 18 Sep 2026 09:36:02 +0800 Subject: [PATCH] Fix dark mode bug on second instance dialog and SVG preview default theme (#1959, #1797) --- OPTIONS.md | 6 +++--- .../QuickLook.Plugin.ImageViewer/Plugin.cs | 6 ++++-- .../Webview/WebHandler.cs | 6 ++++-- QuickLook/App.xaml.cs | 12 ++++++++---- QuickLook/Helpers/MessageBoxPatcher.cs | 8 +++++++- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/OPTIONS.md b/OPTIONS.md index a5fd6b0cb..3505ee585 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -194,10 +194,10 @@ These keys are also stored in `QuickLook.config`. - `False` ### `` -- Default: `1` (`Dark`) +- Default: `0` (`None` / follow system) - Type: `Integer` -- Description: Remember the last theme used by the ImageViewer web preview. - - `0` = None +- Description: Remember the last theme used by the ImageViewer web preview. If not set or set to `0`, follows the system dark/light theme. + - `0` = None (Follow system theme) - `1` = Dark - `2` = Light - Example: diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs index 0dc6ad806..71876e35e 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs @@ -1,4 +1,4 @@ -// Copyright © 2017-2026 QL-Win Contributors +// Copyright © 2017-2026 QL-Win Contributors // // This file is part of QuickLook program. // @@ -243,7 +243,9 @@ public void Prepare(string path, ContextObject context) else context.PreferredSize = new Size(800, 600); - context.Theme = (Themes)SettingHelper.Get("LastTheme", 1, "QuickLook.Plugin.ImageViewer"); + var defaultTheme = (int)(OSThemeHelper.AppsUseDarkTheme() ? Themes.Dark : Themes.Light); + var theme = (Themes)SettingHelper.Get("LastTheme", defaultTheme, "QuickLook.Plugin.ImageViewer"); + context.Theme = theme == Themes.None ? (OSThemeHelper.AppsUseDarkTheme() ? Themes.Dark : Themes.Light) : theme; } public void View(string path, ContextObject context) diff --git a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/WebHandler.cs b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/WebHandler.cs index 39edb5bbc..f3e3ec029 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/WebHandler.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/WebHandler.cs @@ -1,4 +1,4 @@ -// Copyright © 2017-2026 QL-Win Contributors +// Copyright © 2017-2026 QL-Win Contributors // // This file is part of QuickLook program. // @@ -91,7 +91,9 @@ public static bool TryPrepare(string path, ContextObject context, out IWebMetaPr else context.PreferredSize = new Size(800, 600); - context.Theme = (Themes)SettingHelper.Get("LastTheme", 1, "QuickLook.Plugin.ImageViewer"); + var defaultTheme = (int)(OSThemeHelper.AppsUseDarkTheme() ? Themes.Dark : Themes.Light); + var theme = (Themes)SettingHelper.Get("LastTheme", defaultTheme, "QuickLook.Plugin.ImageViewer"); + context.Theme = theme == Themes.None ? (OSThemeHelper.AppsUseDarkTheme() ? Themes.Dark : Themes.Light) : theme; return true; } diff --git a/QuickLook/App.xaml.cs b/QuickLook/App.xaml.cs index 9184585ff..d515199be 100644 --- a/QuickLook/App.xaml.cs +++ b/QuickLook/App.xaml.cs @@ -228,10 +228,7 @@ protected override void OnStartup(StartupEventArgs e) base.OnStartup(e); // Set initial theme based on system settings - ThemeManager.Apply(OSThemeHelper.AppsUseDarkTheme() ? ApplicationTheme.Dark : ApplicationTheme.Light); - - // Initialize MessageBox patching - MessageBoxPatcher.Initialize(); + EnsureThemeAndMessageBoxPatcher(); CheckUpdate(); @@ -307,12 +304,19 @@ private bool EnsureFirstInstance(string[] args) } // Second instance: duplicate + EnsureThemeAndMessageBoxPatcher(); MessageBox.Show(TranslationHelper.Get("APP_SECOND_TEXT"), TranslationHelper.Get("APP_SECOND"), MessageBoxButton.OK, MessageBoxImage.Information); return false; } + private static void EnsureThemeAndMessageBoxPatcher() + { + ThemeManager.Apply(OSThemeHelper.AppsUseDarkTheme() ? ApplicationTheme.Dark : ApplicationTheme.Light); + MessageBoxPatcher.Initialize(); + } + private void CheckUpdate() { if (SettingHelper.Get("DisableAutoUpdateCheck", false)) diff --git a/QuickLook/Helpers/MessageBoxPatcher.cs b/QuickLook/Helpers/MessageBoxPatcher.cs index 40a01cf7a..41426e7be 100644 --- a/QuickLook/Helpers/MessageBoxPatcher.cs +++ b/QuickLook/Helpers/MessageBoxPatcher.cs @@ -1,4 +1,4 @@ -// Copyright © 2024 KamilDev +// Copyright © 2024 KamilDev // // This file is part of QuickLook program. // @@ -30,12 +30,18 @@ namespace QuickLook.Helpers; public static class MessageBoxPatcher { private static readonly Harmony Harmony = new("com.quicklook.messagebox.patch"); + private static bool _isInitialized; /// /// Initializes the MessageBox patch by applying Harmony patches to the MessageBox.Show method overloads. /// public static void Initialize() { + if (_isInitialized) + return; + + _isInitialized = true; + try { Type originalType = typeof(WindowsMessageBox);