mirror of
https://github.com/knah/VRCMelonAssistant.git
synced 2024-09-29 08:41:43 +13:00
Apply default theme based on Windows settings
This commit is contained in:
parent
d85b887cf6
commit
1ce49aea6e
2 changed files with 39 additions and 5 deletions
|
@ -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.
|
||||
/// </summary>
|
||||
/// <param name="theme">Name of the theme.</param>
|
||||
/// <param name="element">Page that this is called on (Used for refreshing button icon colors).</param>
|
||||
public static void ApplyTheme(string theme)
|
||||
/// <param name="sendMessage">Send message to MainText (default: true).</param>
|
||||
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!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the theme set on Windows and applies it.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a ResourceDictionary from either Embedded Resources or from a file location.
|
||||
/// </summary>
|
||||
|
|
|
@ -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...";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue