Skip to content

Commit

Permalink
Add poweruser option to override theme (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
srwi committed Sep 15, 2024
1 parent c9303d1 commit c24321b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
30 changes: 23 additions & 7 deletions EverythingToolbar/Behaviors/ThemeAwareness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public ThemeAwareness()
systemThemeWatcher.OnChangeValue += newValue =>
{
Dispatcher.Invoke(() => {
ApplyTheme((int)newValue == 1);
var theme = GetThemeFromRegistryValue((int)newValue);
ApplyTheme(theme);
});
};

Expand Down Expand Up @@ -88,13 +89,28 @@ private void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
}
}

private Theme GetThemeFromRegistryValue(int registryValue)
{
if (ToolbarSettings.User.ThemeOverride.ToLower() == "light")
{
return Theme.Light;
}
else if (ToolbarSettings.User.ThemeOverride.ToLower() == "dark")
{
return Theme.Dark;
}

return registryValue == 1 ? Theme.Light : Theme.Dark;
}

private void AutoApplyTheme()
{
var isLightTheme = (int)SystemThemeRegistryEntry.GetValue(0) == 1;
ApplyTheme(isLightTheme);
var themeValue = (int)SystemThemeRegistryEntry.GetValue(0);
var theme = GetThemeFromRegistryValue(themeValue);
ApplyTheme(theme);
}

private void ApplyTheme(bool isLightTheme)
private void ApplyTheme(Theme theme)
{
_currentResources.Clear();

Expand All @@ -112,7 +128,7 @@ private void ApplyTheme(bool isLightTheme)
AddResource(file.FullName);

// Apply color scheme according to Windows theme
var themeFileName = isLightTheme ? "Light.xaml" : "Dark.xaml";
var themeFileName = theme == Theme.Light ? "Light.xaml" : "Dark.xaml";
AddResource(Path.Combine(themeLocation, themeFileName));

// Apply ItemTemplate style
Expand All @@ -122,7 +138,7 @@ private void ApplyTheme(bool isLightTheme)
// Apply accent color
if (_settings != null)
{
if (isLightTheme)
if (theme == Theme.Light)
SetAccentColor(GetBrush(_settings.GetColorValue(UIColorType.AccentDark1)));
else
SetAccentColor(GetBrush(_settings.GetColorValue(UIColorType.AccentLight2)));
Expand All @@ -136,7 +152,7 @@ private void ApplyTheme(bool isLightTheme)
ResourceChanged?.Invoke(this, new ResourcesChangedEventArgs
{
NewResource = _currentResources,
NewTheme = isLightTheme ? Theme.Light : Theme.Dark
NewTheme = theme
});
}

Expand Down
16 changes: 16 additions & 0 deletions EverythingToolbar/ToolbarSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public interface IToolbarSettings

[Option(DefaultValue = 0)]
int OsBuildNumberOverride { get; set; }

[Option(DefaultValue = "")]
string ThemeOverride { get; set; }
}

public sealed class ToolbarSettingsWrapper : INotifyPropertyChanged
Expand Down Expand Up @@ -568,6 +571,19 @@ public int OsBuildNumberOverride
}
}
}

public string ThemeOverride
{
get => _settings.ThemeOverride;
set
{
if (_settings.ThemeOverride != value)
{
_settings.ThemeOverride = value;
OnPropertyChanged();
}
}
}
}

public abstract class ToolbarSettings
Expand Down

0 comments on commit c24321b

Please sign in to comment.