Skip to content

Commit d61aa3a

Browse files
authored
[PT Run] Fix theme setting (#30237)
* [PT Run] Fix theme settings * Do not react on theme change when OS theme is high contrast * Fix initial theme set
1 parent d0acc8e commit d61aa3a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/modules/launcher/PowerLauncher/App.xaml.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using Wox.Infrastructure.UserSettings;
2424
using Wox.Plugin;
2525
using Wox.Plugin.Logger;
26+
using Wpf.Ui.Appearance;
2627
using Stopwatch = Wox.Infrastructure.Stopwatch;
2728

2829
namespace PowerLauncher
@@ -152,6 +153,9 @@ private void OnStartup(object sender, StartupEventArgs e)
152153
_settingsReader.ReadSettingsOnChange();
153154

154155
_themeManager.ThemeChanged += OnThemeChanged;
156+
157+
OnThemeChanged(_settings.Theme, _settings.Theme);
158+
155159
textToLog.AppendLine("End PowerToys Run startup ---------------------------------------------------- ");
156160

157161
bootTime.Stop();
@@ -217,6 +221,37 @@ private void RegisterExitEvents()
217221
/// <param name="newTheme">Current Theme</param>
218222
private void OnThemeChanged(Theme oldTheme, Theme newTheme)
219223
{
224+
// If OS theme is high contrast, don't change theme.
225+
if (SystemParameters.HighContrast)
226+
{
227+
return;
228+
}
229+
230+
ApplicationTheme theme = ApplicationTheme.Unknown;
231+
232+
switch (newTheme)
233+
{
234+
case Theme.Dark:
235+
theme = ApplicationTheme.Dark; break;
236+
case Theme.Light:
237+
theme = ApplicationTheme.Light; break;
238+
case Theme.HighContrastWhite:
239+
case Theme.HighContrastBlack:
240+
case Theme.HighContrastOne:
241+
case Theme.HighContrastTwo:
242+
theme = ApplicationTheme.HighContrast; break;
243+
default:
244+
break;
245+
}
246+
247+
_mainWindow?.Dispatcher.Invoke(() =>
248+
{
249+
if (theme != ApplicationTheme.Unknown)
250+
{
251+
ApplicationThemeManager.Apply(theme);
252+
}
253+
});
254+
220255
ImageLoader.UpdateIconPath(newTheme);
221256
_mainVM.Query();
222257
}

0 commit comments

Comments
 (0)