diff --git a/ModAssistant/Classes/Themes.cs b/ModAssistant/Classes/Themes.cs index 1eeef91..d85d70a 100644 --- a/ModAssistant/Classes/Themes.cs +++ b/ModAssistant/Classes/Themes.cs @@ -8,6 +8,7 @@ using ModAssistant.Pages; using System.Xml; using System.Windows.Markup; using System.Reflection; +using Microsoft.Win32; namespace ModAssistant { @@ -63,8 +64,8 @@ namespace ModAssistant /// Applies a loaded theme to ModAssistant. /// /// Name of the theme. - /// Page that this is called on (Used for refreshing button icon colors). - public static void ApplyTheme(string theme) + /// Send message to MainText (default: true). + public static void ApplyTheme(string theme, bool sendMessage = true) { if (loadedThemes.TryGetValue(theme, out ResourceDictionary newTheme)) { @@ -73,7 +74,10 @@ namespace ModAssistant Application.Current.Resources.MergedDictionaries.Insert(0, newTheme); Properties.Settings.Default.SelectedTheme = theme; Properties.Settings.Default.Save(); - MainWindow.Instance.MainText = $"Theme changed to {theme}."; + if (sendMessage) + { + MainWindow.Instance.MainText = $"Theme changed to {theme}."; + } ReloadIcons(); } else throw new ArgumentException($"{theme} does not exist."); @@ -104,6 +108,29 @@ namespace ModAssistant else MessageBox.Show("Template theme already exists!"); } + /// + /// Finds the theme set on Windows and applies it. + /// + public static void ApplyWindowsTheme() + { + using (RegistryKey key = Registry.CurrentUser + .OpenSubKey("Software").OpenSubKey("Microsoft") + .OpenSubKey("Windows").OpenSubKey("CurrentVersion") + .OpenSubKey("Themes").OpenSubKey("Personalize")) + { + object registryValueObject = key?.GetValue("AppsUseLightTheme"); + if (registryValueObject != null) + { + if ((int)registryValueObject <= 0) + { + ApplyTheme("Dark", false); + return; + } + } + ApplyTheme("Light", false); + } + } + /// /// Loads a ResourceDictionary from either Embedded Resources or from a file location. /// diff --git a/ModAssistant/MainWindow.xaml.cs b/ModAssistant/MainWindow.xaml.cs index 4907cb0..031aabc 100644 --- a/ModAssistant/MainWindow.xaml.cs +++ b/ModAssistant/MainWindow.xaml.cs @@ -63,11 +63,18 @@ namespace ModAssistant Themes.LoadThemes(); try { - Themes.ApplyTheme(Properties.Settings.Default.SelectedTheme); + if (Properties.Settings.Default.SelectedTheme != null) + { + Themes.ApplyTheme(Properties.Settings.Default.SelectedTheme, false); + } + else + { + Themes.ApplyWindowsTheme(); + } } catch (ArgumentException) { - Themes.ApplyTheme("Light"); + Themes.ApplyTheme("Light", false); MainText = "Theme not found, reverting to Light theme..."; }