mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
UI - Fixed a possible startup freeze on Windows 11
This commit is contained in:
parent
ef4e5b4c3b
commit
26d8322b15
19
src/Artemis.UI/Services/Interfaces/IThemeService.cs
Normal file
19
src/Artemis.UI/Services/Interfaces/IThemeService.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Artemis.UI.Events;
|
||||
|
||||
namespace Artemis.UI.Services
|
||||
{
|
||||
public interface IThemeService : IArtemisUIService
|
||||
{
|
||||
WindowsTheme GetAppsTheme();
|
||||
WindowsTheme GetSystemTheme();
|
||||
event EventHandler<WindowsThemeEventArgs> AppsThemeChanged;
|
||||
event EventHandler<WindowsThemeEventArgs> SystemThemeChanged;
|
||||
|
||||
enum WindowsTheme
|
||||
{
|
||||
Light,
|
||||
Dark
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,32 +2,56 @@
|
||||
using System.Globalization;
|
||||
using System.Management;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Screens.Settings.Tabs.General;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Microsoft.Win32;
|
||||
using Serilog;
|
||||
|
||||
namespace Artemis.UI.Services
|
||||
{
|
||||
public class ThemeService : IThemeService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly PluginSetting<ApplicationColorScheme> _colorScheme;
|
||||
private const string RegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
|
||||
|
||||
private const string AppsThemeRegistryValueName = "AppsUseLightTheme";
|
||||
private const string SystemThemeRegistryValueName = "SystemUsesLightTheme";
|
||||
|
||||
public ThemeService(ISettingsService settingsService)
|
||||
public ThemeService(ISettingsService settingsService, ILogger logger)
|
||||
{
|
||||
WatchTheme();
|
||||
|
||||
_logger = logger;
|
||||
_colorScheme = settingsService.GetSetting("UI.ColorScheme", ApplicationColorScheme.Automatic);
|
||||
_colorScheme.SettingChanged += ColorSchemeOnSettingChanged;
|
||||
|
||||
ApplyColorSchemeSetting();
|
||||
AppsThemeChanged += OnAppsThemeChanged;
|
||||
|
||||
Task.Run(Initialize);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
WatchTheme();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Warning(e, "WatchTheme failed");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ApplyColorSchemeSetting();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Warning(e, "ApplyColorSchemeSetting failed");
|
||||
}
|
||||
}
|
||||
|
||||
public IThemeService.WindowsTheme GetAppsTheme()
|
||||
@ -159,18 +183,4 @@ namespace Artemis.UI.Services
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public interface IThemeService : IArtemisUIService
|
||||
{
|
||||
WindowsTheme GetAppsTheme();
|
||||
WindowsTheme GetSystemTheme();
|
||||
event EventHandler<WindowsThemeEventArgs> AppsThemeChanged;
|
||||
event EventHandler<WindowsThemeEventArgs> SystemThemeChanged;
|
||||
|
||||
enum WindowsTheme
|
||||
{
|
||||
Light,
|
||||
Dark
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user