Improve querying of app theme preference

This commit is contained in:
pizzaboxer 2024-09-15 18:26:42 +01:00
parent 83e3c487a9
commit 6e8faff624
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8

View File

@ -9,15 +9,10 @@ namespace Bloxstrap.Extensions
if (dialogTheme != Theme.Default)
return dialogTheme;
RegistryKey? key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
using var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
if (key is not null)
{
var value = key.GetValue("AppsUseLightTheme");
if (value is not null && (int)value == 0)
return Theme.Dark;
}
if (key?.GetValue("AppsUseLightTheme") is int value && value == 0)
return Theme.Dark;
return Theme.Light;
}