Skip to content

Commit

Permalink
[PT Run] Fix theme setting (#30237)
Browse files Browse the repository at this point in the history
* [PT Run] Fix theme settings

* Do not react on theme change when OS theme is high contrast

* Fix initial theme set
  • Loading branch information
stefansjfw committed Dec 7, 2023
1 parent d0acc8e commit d61aa3a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/modules/launcher/PowerLauncher/App.xaml.cs
Expand Up @@ -23,6 +23,7 @@
using Wox.Infrastructure.UserSettings;
using Wox.Plugin;
using Wox.Plugin.Logger;
using Wpf.Ui.Appearance;
using Stopwatch = Wox.Infrastructure.Stopwatch;

namespace PowerLauncher
Expand Down Expand Up @@ -152,6 +153,9 @@ private void OnStartup(object sender, StartupEventArgs e)
_settingsReader.ReadSettingsOnChange();
_themeManager.ThemeChanged += OnThemeChanged;
OnThemeChanged(_settings.Theme, _settings.Theme);
textToLog.AppendLine("End PowerToys Run startup ---------------------------------------------------- ");
bootTime.Stop();
Expand Down Expand Up @@ -217,6 +221,37 @@ private void RegisterExitEvents()
/// <param name="newTheme">Current Theme</param>
private void OnThemeChanged(Theme oldTheme, Theme newTheme)
{
// If OS theme is high contrast, don't change theme.
if (SystemParameters.HighContrast)
{
return;
}

ApplicationTheme theme = ApplicationTheme.Unknown;

switch (newTheme)
{
case Theme.Dark:
theme = ApplicationTheme.Dark; break;
case Theme.Light:
theme = ApplicationTheme.Light; break;
case Theme.HighContrastWhite:
case Theme.HighContrastBlack:
case Theme.HighContrastOne:
case Theme.HighContrastTwo:
theme = ApplicationTheme.HighContrast; break;
default:
break;
}

_mainWindow?.Dispatcher.Invoke(() =>
{
if (theme != ApplicationTheme.Unknown)
{
ApplicationThemeManager.Apply(theme);
}
});

ImageLoader.UpdateIconPath(newTheme);
_mainVM.Query();
}
Expand Down

0 comments on commit d61aa3a

Please sign in to comment.