Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions OPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ These keys are also stored in `QuickLook.config`.
- `<RenderSvgWeb>False</RenderSvgWeb>`

### `<LastTheme>`
- 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:
Expand Down
6 changes: 4 additions & 2 deletions QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017-2026 QL-Win Contributors
// Copyright © 2017-2026 QL-Win Contributors
//
// This file is part of QuickLook program.
//
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017-2026 QL-Win Contributors
// Copyright © 2017-2026 QL-Win Contributors
//
// This file is part of QuickLook program.
//
Expand Down Expand Up @@ -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;
}

Expand Down
12 changes: 8 additions & 4 deletions QuickLook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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))
Expand Down
8 changes: 7 additions & 1 deletion QuickLook/Helpers/MessageBoxPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2024 KamilDev
// Copyright © 2024 KamilDev
//
// This file is part of QuickLook program.
//
Expand Down Expand Up @@ -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;

/// <summary>
/// Initializes the MessageBox patch by applying Harmony patches to the MessageBox.Show method overloads.
/// </summary>
public static void Initialize()
{
if (_isInitialized)
return;

_isInitialized = true;

try
{
Type originalType = typeof(WindowsMessageBox);
Expand Down