Auto theme change

This commit is contained in:
seerge
2023-03-20 16:42:51 +01:00
parent d82f1c8d70
commit 1cd808de07
7 changed files with 112 additions and 46 deletions

View File

@@ -27,6 +27,7 @@ namespace GHelper
private static IntPtr ds;
private static long lastAuto;
private static long lastTheme;
// The main entry point for the application
public static void Main()
@@ -48,6 +49,8 @@ namespace GHelper
}
SystemEvents.UserPreferenceChanged += OnUserPreferenceChanged;
Application.EnableVisualStyles();
ds = settingsForm.Handle;
@@ -77,6 +80,30 @@ namespace GHelper
}
static void OnUserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastTheme) < 2000) return;
lastTheme = DateTimeOffset.Now.ToUnixTimeMilliseconds();
switch (e.Category)
{
case UserPreferenceCategory.General:
Debug.WriteLine("Theme Changed");
settingsForm.InitTheme();
if (settingsForm.fans is not null && settingsForm.fans.Text != "")
settingsForm.fans.InitTheme();
if (settingsForm.keyb is not null && settingsForm.keyb.Text != "")
settingsForm.keyb.InitTheme();
break;
}
}
static async void CheckForUpdates()
{