modified ThemeService
This commit is contained in:
@@ -17,13 +17,24 @@ public sealed class ThemeService : IThemeService, IDisposable
|
||||
@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize";
|
||||
|
||||
private readonly AppSettings _settings;
|
||||
private readonly Func<AppTheme> _detectSystemTheme;
|
||||
private readonly List<Window> _windows = [];
|
||||
private ResourceDictionary? _palette;
|
||||
private AppTheme _current;
|
||||
|
||||
public ThemeService(AppSettings settings)
|
||||
: this(settings, DetectSystemTheme)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes the source of the system theme explicitly: in tests it is not the registry
|
||||
/// that provides it.
|
||||
/// </summary>
|
||||
internal ThemeService(AppSettings settings, Func<AppTheme> detectSystemTheme)
|
||||
{
|
||||
_settings = settings;
|
||||
_detectSystemTheme = detectSystemTheme;
|
||||
_settings.PropertyChanged += OnSettingsChanged;
|
||||
SystemEvents.UserPreferenceChanged += OnUserPreferenceChanged;
|
||||
Apply();
|
||||
@@ -90,7 +101,7 @@ public sealed class ThemeService : IThemeService, IDisposable
|
||||
|
||||
private void Apply()
|
||||
{
|
||||
AppTheme theme = _settings.Theme == AppTheme.System ? DetectSystemTheme() : _settings.Theme;
|
||||
AppTheme theme = _settings.Theme == AppTheme.System ? _detectSystemTheme() : _settings.Theme;
|
||||
if (_palette is not null && theme == _current)
|
||||
{
|
||||
return;
|
||||
@@ -100,7 +111,7 @@ public sealed class ThemeService : IThemeService, IDisposable
|
||||
|
||||
var next = new ResourceDictionary
|
||||
{
|
||||
Source = new Uri($"pack://application:,,,/Themes/{theme}.xaml", UriKind.Absolute),
|
||||
Source = PaletteUri(theme),
|
||||
};
|
||||
|
||||
ICollection<ResourceDictionary> dictionaries = Application.Current.Resources.MergedDictionaries;
|
||||
@@ -119,6 +130,12 @@ public sealed class ThemeService : IThemeService, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
// The assembly name in the address is there on purpose: without it the dictionary
|
||||
// is looked up in the assembly the process started from, which is not always the
|
||||
// application itself
|
||||
internal static Uri PaletteUri(AppTheme theme) =>
|
||||
new($"pack://application:,,,/CursorLang;component/Themes/{theme}.xaml", UriKind.Absolute);
|
||||
|
||||
private void ApplyTitleBar(Window window) =>
|
||||
WindowThemeNative.SetDarkTitleBar(
|
||||
new WindowInteropHelper(window).Handle,
|
||||
|
||||
Reference in New Issue
Block a user