mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge pull request #592 from Cheerpipe/try_icon
Fixed tray icon color not matching the system theme but the app theme
This commit is contained in:
commit
4ab8459927
@ -71,7 +71,7 @@ namespace Artemis.UI.Providers
|
|||||||
Execute.OnUIThreadSync(() =>
|
Execute.OnUIThreadSync(() =>
|
||||||
{
|
{
|
||||||
using FileStream stream = File.OpenWrite(imagePath);
|
using FileStream stream = File.OpenWrite(imagePath);
|
||||||
GetEncoderForIcon(icon, _themeWatcher.GetWindowsTheme() == ThemeWatcher.WindowsTheme.Dark ? Colors.White : Colors.Black).Save(stream);
|
GetEncoderForIcon(icon, _themeWatcher.GetSystemTheme() == ThemeWatcher.WindowsTheme.Dark ? Colors.White : Colors.Black).Save(stream);
|
||||||
});
|
});
|
||||||
|
|
||||||
new ToastContentBuilder()
|
new ToastContentBuilder()
|
||||||
|
|||||||
@ -51,9 +51,11 @@ namespace Artemis.UI.Screens
|
|||||||
_themeWatcher = new ThemeWatcher();
|
_themeWatcher = new ThemeWatcher();
|
||||||
_colorScheme = settingsService.GetSetting("UI.ColorScheme", ApplicationColorScheme.Automatic);
|
_colorScheme = settingsService.GetSetting("UI.ColorScheme", ApplicationColorScheme.Automatic);
|
||||||
_colorScheme.SettingChanged += ColorSchemeOnSettingChanged;
|
_colorScheme.SettingChanged += ColorSchemeOnSettingChanged;
|
||||||
_themeWatcher.ThemeChanged += ThemeWatcherOnThemeChanged;
|
_themeWatcher.SystemThemeChanged += _themeWatcher_SystemThemeChanged;
|
||||||
|
_themeWatcher.AppsThemeChanged += _themeWatcher_AppsThemeChanged;
|
||||||
|
|
||||||
ApplyColorSchemeSetting();
|
ApplyColorSchemeSetting();
|
||||||
|
ApplyTryIconTheme(_themeWatcher.GetSystemTheme());
|
||||||
|
|
||||||
windowService.ConfigureMainWindowProvider(this);
|
windowService.ConfigureMainWindowProvider(this);
|
||||||
bool autoRunning = Bootstrapper.StartupArguments.Contains("--autorun");
|
bool autoRunning = Bootstrapper.StartupArguments.Contains("--autorun");
|
||||||
@ -170,28 +172,31 @@ namespace Artemis.UI.Screens
|
|||||||
private void ApplyColorSchemeSetting()
|
private void ApplyColorSchemeSetting()
|
||||||
{
|
{
|
||||||
if (_colorScheme.Value == ApplicationColorScheme.Automatic)
|
if (_colorScheme.Value == ApplicationColorScheme.Automatic)
|
||||||
ApplyWindowsTheme(_themeWatcher.GetWindowsTheme());
|
ApplyUITheme(_themeWatcher.GetAppsTheme());
|
||||||
else
|
else
|
||||||
ChangeMaterialColors(_colorScheme.Value);
|
ChangeMaterialColors(_colorScheme.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyWindowsTheme(ThemeWatcher.WindowsTheme windowsTheme)
|
private void ApplyUITheme(ThemeWatcher.WindowsTheme theme)
|
||||||
{
|
{
|
||||||
Execute.PostToUIThread(() =>
|
|
||||||
{
|
|
||||||
Icon = windowsTheme == ThemeWatcher.WindowsTheme.Dark
|
|
||||||
? new BitmapImage(new Uri("pack://application:,,,/Artemis.UI;component/Resources/Images/Logo/bow-white.ico"))
|
|
||||||
: new BitmapImage(new Uri("pack://application:,,,/Artemis.UI;component/Resources/Images/Logo/bow-black.ico"));
|
|
||||||
});
|
|
||||||
|
|
||||||
if (_colorScheme.Value != ApplicationColorScheme.Automatic)
|
if (_colorScheme.Value != ApplicationColorScheme.Automatic)
|
||||||
return;
|
return;
|
||||||
if (windowsTheme == ThemeWatcher.WindowsTheme.Dark)
|
if (theme == ThemeWatcher.WindowsTheme.Dark)
|
||||||
ChangeMaterialColors(ApplicationColorScheme.Dark);
|
ChangeMaterialColors(ApplicationColorScheme.Dark);
|
||||||
else
|
else
|
||||||
ChangeMaterialColors(ApplicationColorScheme.Light);
|
ChangeMaterialColors(ApplicationColorScheme.Light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplyTryIconTheme(ThemeWatcher.WindowsTheme theme)
|
||||||
|
{
|
||||||
|
Execute.PostToUIThread(() =>
|
||||||
|
{
|
||||||
|
Icon = theme == ThemeWatcher.WindowsTheme.Dark
|
||||||
|
? new BitmapImage(new Uri("pack://application:,,,/Artemis.UI;component/Resources/Images/Logo/bow-white.ico"))
|
||||||
|
: new BitmapImage(new Uri("pack://application:,,,/Artemis.UI;component/Resources/Images/Logo/bow-black.ico"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void ChangeMaterialColors(ApplicationColorScheme colorScheme)
|
private void ChangeMaterialColors(ApplicationColorScheme colorScheme)
|
||||||
{
|
{
|
||||||
PaletteHelper paletteHelper = new();
|
PaletteHelper paletteHelper = new();
|
||||||
@ -203,9 +208,14 @@ namespace Artemis.UI.Screens
|
|||||||
extensionsPaletteHelper.SetLightDark(colorScheme == ApplicationColorScheme.Dark);
|
extensionsPaletteHelper.SetLightDark(colorScheme == ApplicationColorScheme.Dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThemeWatcherOnThemeChanged(object sender, WindowsThemeEventArgs e)
|
private void _themeWatcher_AppsThemeChanged(object sender, WindowsThemeEventArgs e)
|
||||||
{
|
{
|
||||||
ApplyWindowsTheme(e.Theme);
|
ApplyUITheme(e.Theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void _themeWatcher_SystemThemeChanged(object sender, WindowsThemeEventArgs e)
|
||||||
|
{
|
||||||
|
ApplyTryIconTheme(e.Theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ColorSchemeOnSettingChanged(object sender, EventArgs e)
|
private void ColorSchemeOnSettingChanged(object sender, EventArgs e)
|
||||||
|
|||||||
@ -11,7 +11,8 @@ namespace Artemis.UI.Utilities
|
|||||||
{
|
{
|
||||||
private const string RegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
|
private const string RegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
|
||||||
|
|
||||||
private const string RegistryValueName = "AppsUseLightTheme";
|
private const string appsThemeRegistryValueName = "AppsUseLightTheme";
|
||||||
|
private const string systemThemeRegistryValueName = "SystemUsesLightTheme";
|
||||||
|
|
||||||
public ThemeWatcher()
|
public ThemeWatcher()
|
||||||
{
|
{
|
||||||
@ -21,24 +22,44 @@ namespace Artemis.UI.Utilities
|
|||||||
public void WatchTheme()
|
public void WatchTheme()
|
||||||
{
|
{
|
||||||
WindowsIdentity currentUser = WindowsIdentity.GetCurrent();
|
WindowsIdentity currentUser = WindowsIdentity.GetCurrent();
|
||||||
string query = string.Format(
|
string appsThemequery = string.Format(
|
||||||
CultureInfo.InvariantCulture,
|
CultureInfo.InvariantCulture,
|
||||||
@"SELECT * FROM RegistryValueChangeEvent WHERE Hive = 'HKEY_USERS' AND KeyPath = '{0}\\{1}' AND ValueName = '{2}'",
|
@"SELECT * FROM RegistryValueChangeEvent WHERE Hive = 'HKEY_USERS' AND KeyPath = '{0}\\{1}' AND ValueName = '{2}'",
|
||||||
currentUser.User.Value,
|
currentUser.User.Value,
|
||||||
RegistryKeyPath.Replace(@"\", @"\\"),
|
RegistryKeyPath.Replace(@"\", @"\\"),
|
||||||
RegistryValueName);
|
appsThemeRegistryValueName);
|
||||||
|
|
||||||
|
string systemThemequery = string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
@"SELECT * FROM RegistryValueChangeEvent WHERE Hive = 'HKEY_USERS' AND KeyPath = '{0}\\{1}' AND ValueName = '{2}'",
|
||||||
|
currentUser.User.Value,
|
||||||
|
RegistryKeyPath.Replace(@"\", @"\\"),
|
||||||
|
systemThemeRegistryValueName);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ManagementEventWatcher watcher = new(query);
|
// For Apps theme
|
||||||
watcher.EventArrived += (sender, args) =>
|
ManagementEventWatcher appsThemWatcher = new(appsThemequery);
|
||||||
|
appsThemWatcher.EventArrived += (_, _) =>
|
||||||
{
|
{
|
||||||
WindowsTheme newWindowsTheme = GetWindowsTheme();
|
WindowsTheme newWindowsTheme = GetAppsTheme();
|
||||||
OnThemeChanged(new WindowsThemeEventArgs(newWindowsTheme));
|
OnAppsThemeChanged(new WindowsThemeEventArgs(newWindowsTheme));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start listening for events
|
// Start listening for apps theme events
|
||||||
watcher.Start();
|
appsThemWatcher.Start();
|
||||||
|
|
||||||
|
|
||||||
|
// For System theme
|
||||||
|
ManagementEventWatcher systemThemWatcher = new(systemThemequery);
|
||||||
|
systemThemWatcher.EventArrived += (_, _) =>
|
||||||
|
{
|
||||||
|
WindowsTheme newWindowsTheme = GetSystemTheme();
|
||||||
|
OnSystemThemeChanged(new WindowsThemeEventArgs(newWindowsTheme));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Start listening for system theme events
|
||||||
|
systemThemWatcher.Start();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@ -46,11 +67,11 @@ namespace Artemis.UI.Utilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WindowsTheme GetWindowsTheme()
|
private WindowsTheme GetTheme(string themeKeyName)
|
||||||
{
|
{
|
||||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RegistryKeyPath))
|
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RegistryKeyPath))
|
||||||
{
|
{
|
||||||
object registryValueObject = key?.GetValue(RegistryValueName);
|
object registryValueObject = key?.GetValue(themeKeyName);
|
||||||
if (registryValueObject == null) return WindowsTheme.Light;
|
if (registryValueObject == null) return WindowsTheme.Light;
|
||||||
|
|
||||||
int registryValue = (int)registryValueObject;
|
int registryValue = (int)registryValueObject;
|
||||||
@ -59,12 +80,27 @@ namespace Artemis.UI.Utilities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public event EventHandler<WindowsThemeEventArgs> ThemeChanged;
|
public WindowsTheme GetAppsTheme()
|
||||||
|
|
||||||
|
|
||||||
protected virtual void OnThemeChanged(WindowsThemeEventArgs e)
|
|
||||||
{
|
{
|
||||||
ThemeChanged?.Invoke(this, e);
|
return GetTheme(appsThemeRegistryValueName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WindowsTheme GetSystemTheme()
|
||||||
|
{
|
||||||
|
return GetTheme(systemThemeRegistryValueName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public event EventHandler<WindowsThemeEventArgs> AppsThemeChanged;
|
||||||
|
public event EventHandler<WindowsThemeEventArgs> SystemThemeChanged;
|
||||||
|
|
||||||
|
protected virtual void OnAppsThemeChanged(WindowsThemeEventArgs e)
|
||||||
|
{
|
||||||
|
AppsThemeChanged?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnSystemThemeChanged(WindowsThemeEventArgs e)
|
||||||
|
{
|
||||||
|
SystemThemeChanged?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum WindowsTheme
|
public enum WindowsTheme
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user