diff --git a/EnvyUpdate/App.xaml.cs b/EnvyUpdate/App.xaml.cs index 2d0e158..185bc1d 100644 --- a/EnvyUpdate/App.xaml.cs +++ b/EnvyUpdate/App.xaml.cs @@ -19,17 +19,6 @@ namespace EnvyUpdate { protected override void OnStartup(StartupEventArgs e) { - // Remove placeholder light theme and apply system app theme - Wpf.Ui.Appearance.Accent.ApplySystemAccent(); - Application.Current.Resources.MergedDictionaries.RemoveAt(0); - ThemesDictionary themedict = new ThemesDictionary(); - if (Util.IsDarkTheme()) - themedict.Theme = Wpf.Ui.Appearance.ThemeType.Dark; - else - themedict.Theme = Wpf.Ui.Appearance.ThemeType.Light; - Application.Current.Resources.MergedDictionaries.Add(themedict); - // TODO: Watch for theme changes and dynamically update - // Listen to notification activation ToastNotificationManagerCompat.OnActivated += ToastNotificationManagerCompat_OnActivated; } diff --git a/EnvyUpdate/MainWindow.xaml.cs b/EnvyUpdate/MainWindow.xaml.cs index f7729a4..7f95351 100644 --- a/EnvyUpdate/MainWindow.xaml.cs +++ b/EnvyUpdate/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using Microsoft.Toolkit.Uwp.Notifications; +using Microsoft.Win32; using System; using System.IO; using System.Linq; @@ -54,6 +55,10 @@ namespace EnvyUpdate Environment.Exit(1); } + // Check dark theme + AdjustTheme(); + SystemEvents.UserPreferenceChanged += AdjustTheme; + // Delete installed legacy versions, required for people upgrading from very old versions. if (Directory.Exists(GlobalVars.appdata)) { @@ -114,5 +119,13 @@ namespace EnvyUpdate RootNavigation.Navigate(0); } } + + private void AdjustTheme(object sender = null, UserPreferenceChangedEventArgs e = null) + { + if (Util.IsDarkTheme()) + Wpf.Ui.Appearance.Theme.Apply(Wpf.Ui.Appearance.ThemeType.Dark, Wpf.Ui.Appearance.BackgroundType.Mica); + else + Wpf.Ui.Appearance.Theme.Apply(Wpf.Ui.Appearance.ThemeType.Light, Wpf.Ui.Appearance.BackgroundType.Mica); + } } } \ No newline at end of file