Fixed stackoverflow...

This commit is contained in:
Daniel Clark
2021-02-05 21:32:32 +00:00
parent b411f82243
commit 2be7a1128c
9 changed files with 61 additions and 49 deletions
@@ -1,30 +1,21 @@
using Microsoft.Win32;
using NotificationFlyout.Wpf.UI.Extensions;
using NotificationFlyout.Wpf.UI.Extensions;
using System;
namespace NotificationFlyout.Wpf.UI.Helpers
{
public static class SystemSettingsHelper
{
private static readonly string PersonalizeKey = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
public static SystemTheme DefaultSystemTheme => GetDefaultSystemTheme();
public static SystemTheme DefaultSystemTheme => GetDefaultSystemTheme();
private static SystemTheme GetDefaultSystemTheme()
{
return Environment.OSVersion.IsGreaterThan(OperatingSystemVersion.Windows10_1809) &&
ReadDword(PersonalizeKey, "SystemUsesLightTheme")
? SystemTheme.Light
: SystemTheme.Dark;
return Environment.OSVersion.IsGreaterThan(OperatingSystemVersion.Windows10_1809) && DoesSystemUsesLightTheme() ? SystemTheme.Light : SystemTheme.Dark;
}
private static bool ReadDword(string key, string valueName, int defaultValue = 0)
private static bool DoesSystemUsesLightTheme()
{
using var baseKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
using var subKey = baseKey.OpenSubKey(key);
return subKey.GetValue<int>(valueName, defaultValue) > 0;
var personalizeKey = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
return RegistryHelper.GetDwordValue<int>(personalizeKey, "SystemUsesLightTheme") > 0;
}
public static bool IsTransparencyEnabled => ReadDword(PersonalizeKey, "EnableTransparency");
}
}