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
5 changes: 4 additions & 1 deletion QuickLook.Common/Helpers/SettingHelper.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 @@ -26,6 +26,9 @@ namespace QuickLook.Common.Helpers;

public static class SettingHelper
{
public const string KeyAppTheme = "AppTheme";
public const string KeyLastCanvasTheme = "LastCanvasTheme";

public static readonly string LocalDataPath =
IsPortableVersion()
? Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty,
Expand Down
6 changes: 3 additions & 3 deletions QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl x:Class="QuickLook.Plugin.ImageViewer.ImagePanel"
<UserControl x:Class="QuickLook.Plugin.ImageViewer.ImagePanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:animatedImage="clr-namespace:QuickLook.Plugin.ImageViewer.AnimatedImage"
Expand All @@ -24,7 +24,7 @@
<Rectangle.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=imagePanel, Path=Theme}" Value="{x:Static plugin:Themes.Dark}">
<DataTrigger Binding="{Binding ElementName=imagePanel, Path=CanvasTheme}" Value="{x:Static plugin:Themes.Dark}">
<Setter Property="Rectangle.Fill">
<Setter.Value>
<ImageBrush AlignmentY="Top"
Expand All @@ -38,7 +38,7 @@
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=imagePanel, Path=Theme}" Value="{x:Static plugin:Themes.Light}">
<DataTrigger Binding="{Binding ElementName=imagePanel, Path=CanvasTheme}" Value="{x:Static plugin:Themes.Light}">
<Setter Property="Rectangle.Fill">
<Setter.Value>
<ImageBrush AlignmentY="Top"
Expand Down
18 changes: 15 additions & 3 deletions QuickLook.Plugin/QuickLook.Plugin.ImageViewer/ImagePanel.xaml.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 @@ -107,6 +107,7 @@ internal ImagePanel(ContextObject context, MetaProvider meta) : this()

ShowMeta();
Theme = ContextObject.Theme;
CanvasTheme = (Themes)SettingHelper.Get(SettingHelper.KeyLastCanvasTheme, (int)Theme, "QuickLook.Plugin.ImageViewer");
}

public bool ZoomWithControlKey
Expand Down Expand Up @@ -140,6 +141,17 @@ public Themes Theme
}
}

private Themes _canvasTheme = Themes.Dark;
public Themes CanvasTheme
{
get => _canvasTheme;
set
{
_canvasTheme = value;
OnPropertyChanged();
}
}

public BitmapScalingMode RenderMode
{
get => _renderMode;
Expand Down Expand Up @@ -381,9 +393,9 @@ private void OnReverseColorOnClick(object sender, RoutedEventArgs e)

private void OnBackgroundColourOnClick(object sender, RoutedEventArgs e)
{
Theme = Theme == Themes.Dark ? Themes.Light : Themes.Dark;
CanvasTheme = CanvasTheme == Themes.Dark ? Themes.Light : Themes.Dark;

SettingHelper.Set("LastTheme", (int)Theme, "QuickLook.Plugin.ImageViewer");
SettingHelper.Set(SettingHelper.KeyLastCanvasTheme, (int)CanvasTheme, "QuickLook.Plugin.ImageViewer");
}

private void ShowMeta()
Expand Down
28 changes: 26 additions & 2 deletions QuickLook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@

namespace QuickLook;

public enum AppThemeMode
{
Auto = 0,
Light = 1,
Dark = 2
}

public partial class App : Application
{
public static readonly string LocalDataPath = SettingHelper.LocalDataPath;
Expand Down Expand Up @@ -227,8 +234,9 @@ protected override void OnStartup(StartupEventArgs e)
// Therefore, the time-consuming initialization code can't be placed before `OnStartup`
base.OnStartup(e);

// Set initial theme based on system settings
ThemeManager.Apply(OSThemeHelper.AppsUseDarkTheme() ? ApplicationTheme.Dark : ApplicationTheme.Light);
// Set initial theme based on system or user settings
var appTheme = SettingHelper.Get(SettingHelper.KeyAppTheme, (int)AppThemeMode.Auto, "QuickLook");
SetTheme((AppThemeMode)appTheme);

// Initialize MessageBox patching
MessageBoxPatcher.Initialize();
Expand Down Expand Up @@ -346,4 +354,20 @@ private void RunListener(StartupEventArgs e)
KeystrokeDispatcher.GetInstance();
PipeServerManager.GetInstance();
}

public static void SetTheme(AppThemeMode theme)
{
switch (theme)
{
case AppThemeMode.Light:
ThemeManager.Apply(ApplicationTheme.Light);
break;
case AppThemeMode.Dark:
ThemeManager.Apply(ApplicationTheme.Dark);
break;
default:
ThemeManager.Apply(OSThemeHelper.AppsUseDarkTheme() ? ApplicationTheme.Dark : ApplicationTheme.Light);
break;
}
}
}
16 changes: 16 additions & 0 deletions QuickLook/TrayIconManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal partial class TrayIconManager : IDisposable

private readonly TrayMenuItem _itemAutorun = null!;
private readonly TrayMenuItem _itemCloseOnLostFocus = null!;
private readonly TrayMenuItem _itemThemeCycle = null!;

private TrayIconManager()
{
Expand Down Expand Up @@ -70,6 +71,17 @@ private TrayIconManager()
Header = TranslationHelper.Get("Icon_OpenDataFolder"),
Command = new RelayCommand(() => Process.Start("explorer.exe", SettingHelper.LocalDataPath)),
},
_itemThemeCycle = new TrayMenuItem()
{
Header = TranslationHelper.Get("Icon_ThemeAuto", failsafe: "Theme: Auto"),
Command = new RelayCommand(() =>
{
var current = SettingHelper.Get(SettingHelper.KeyAppTheme, (int)AppThemeMode.Auto, "QuickLook");
var next = (AppThemeMode)((current + 1) % 3);
SettingHelper.Set(SettingHelper.KeyAppTheme, (int)next, "QuickLook");
App.SetTheme(next);
}),
},
_itemAutorun = new TrayMenuItem()
{
Header = TranslationHelper.Get("Icon_RunAtStartup"),
Expand Down Expand Up @@ -109,6 +121,10 @@ private TrayIconManager()
{
_itemAutorun.IsChecked = AutoStartupHelper.IsAutorun();
_itemCloseOnLostFocus.IsChecked = SettingHelper.Get("CloseOnLostFocus", false);
var theme = (AppThemeMode)SettingHelper.Get(SettingHelper.KeyAppTheme, (int)AppThemeMode.Auto, "QuickLook");
_itemThemeCycle.Header = theme == AppThemeMode.Light ? TranslationHelper.Get("Icon_ThemeLight", failsafe: "Theme: Light") :
theme == AppThemeMode.Dark ? TranslationHelper.Get("Icon_ThemeDark", failsafe: "Theme: Dark") :
TranslationHelper.Get("Icon_ThemeAuto", failsafe: "Theme: Auto");
};
}

Expand Down