Theme metadata adjustments

This commit is contained in:
Yusyuriv 2024-06-03 13:25:42 +06:00
parent da38172227
commit f58c95057a
No known key found for this signature in database
GPG key ID: A91C52E6F73148E0
9 changed files with 35 additions and 36 deletions

View file

@ -18,6 +18,10 @@ namespace Flow.Launcher.Core.Resource
{
public class Theme
{
private const string ThemeMetadataNamePrefix = "Name:";
private const string ThemeMetadataIsDarkPrefix = "IsDark:";
private const string ThemeMetadataHasBlurPrefix = "HasBlur:";
private const int ShadowExtraMargin = 32;
private readonly List<string> _themeDirectories = new List<string>();
@ -80,14 +84,14 @@ namespace Flow.Launcher.Core.Resource
{
if (string.IsNullOrEmpty(path))
throw new DirectoryNotFoundException("Theme path can't be found <{path}>");
// reload all resources even if the theme itself hasn't changed in order to pickup changes
// to things like fonts
UpdateResourceDictionary(GetResourceDictionary(theme));
Settings.Theme = theme;
//always allow re-loading default theme, in case of failure of switching to a new theme from default theme
if (_oldTheme != theme || theme == defaultTheme)
{
@ -149,7 +153,7 @@ namespace Flow.Launcher.Core.Resource
public ResourceDictionary GetResourceDictionary(string theme)
{
var dict = GetThemeResourceDictionary(theme);
if (dict["QueryBoxStyle"] is Style queryBoxStyle &&
dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle)
{
@ -188,7 +192,7 @@ namespace Flow.Launcher.Core.Resource
Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch };
Array.ForEach(
new[] { resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o
new[] { resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o
=> Array.ForEach(setters, p => o.Setters.Add(p)));
}
@ -246,34 +250,27 @@ namespace Flow.Launcher.Core.Resource
return new ThemeData(extensionlessName, extensionlessName);
var commentLines = reader.Value.Trim().Split('\n').Select(v => v.Trim());
var themeData = new ThemeData(extensionlessName, extensionlessName);
var name = extensionlessName;
bool? isDark = null;
bool? hasBlur = null;
foreach (var line in commentLines)
{
if (line.StartsWith("Name:", StringComparison.OrdinalIgnoreCase))
if (line.StartsWith(ThemeMetadataNamePrefix, StringComparison.OrdinalIgnoreCase))
{
themeData = themeData with { Name = line.Remove(0, "Name:".Length).Trim() };
name = line.Remove(0, ThemeMetadataNamePrefix.Length).Trim();
}
else if (line.StartsWith("IsDark:", StringComparison.OrdinalIgnoreCase))
else if (line.StartsWith(ThemeMetadataIsDarkPrefix, StringComparison.OrdinalIgnoreCase))
{
themeData = themeData with
{
IsDark = bool.Parse(
line.Remove(0, "IsDark:".Length).Trim()
)
};
isDark = bool.Parse(line.Remove(0, ThemeMetadataIsDarkPrefix.Length).Trim());
}
else if (line.StartsWith("IsBlur:", StringComparison.OrdinalIgnoreCase))
else if (line.StartsWith(ThemeMetadataHasBlurPrefix, StringComparison.OrdinalIgnoreCase))
{
themeData = themeData with
{
IsBlur = bool.Parse(
line.Remove(0, "IsBlur:".Length).Trim()
)
};
hasBlur = bool.Parse(line.Remove(0, ThemeMetadataHasBlurPrefix.Length).Trim());
}
}
return themeData;
return new ThemeData(extensionlessName, name, isDark, hasBlur);
}
private string GetThemePath(string themeName)
@ -452,6 +449,6 @@ namespace Flow.Launcher.Core.Resource
}
#endregion
public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, bool? IsBlur = null);
public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, bool? HasBlur = null);
}
}

View file

@ -93,7 +93,9 @@ public partial class SettingsPaneThemeViewModel : BaseModel
get => Settings.ResultSubItemFontSize;
set => Settings.ResultSubItemFontSize = value;
}
public List<Theme.ThemeData> Themes => ThemeManager.Instance.LoadAvailableThemes();
private List<Theme.ThemeData> _themes;
public List<Theme.ThemeData> Themes => _themes ??= ThemeManager.Instance.LoadAvailableThemes();
public class ColorScheme

View file

@ -396,7 +396,7 @@
VerticalAlignment="Center"
FontSize="12"
Glyph="&#xEB42;"
Visibility="{Binding SelectedTheme.IsBlur, Converter={StaticResource BoolToVisibilityConverter}}" />
Visibility="{Binding SelectedTheme.HasBlur, Converter={StaticResource BoolToVisibilityConverter}}" />
<TextBlock Text="{Binding SelectedTheme.Name}" />
</StackPanel>
</cc:ExCard.SideContent>
@ -442,7 +442,7 @@
VerticalAlignment="Center"
FontSize="12"
Glyph="&#xEB42;"
Visibility="{Binding IsBlur, Converter={StaticResource BoolToVisibilityConverter}}" />
Visibility="{Binding HasBlur, Converter={StaticResource BoolToVisibilityConverter}}" />
</StackPanel>
</Grid>
</DataTemplate>

View file

@ -1,7 +1,7 @@
<!--
Name: Blur Black Darker
IsDark: False
IsBlur: True
HasBlur: True
-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

View file

@ -1,7 +1,7 @@
<!--
Name: Blur Black
IsDark: False
IsBlur: True
HasBlur: True
-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@ -173,4 +173,4 @@
TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#FFFFFFFF" />
</Style>
</ResourceDictionary>
</ResourceDictionary>

View file

@ -1,7 +1,7 @@
<!--
Name: Blur White
IsDark: False
IsBlur: True
HasBlur: True
-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

View file

@ -1,7 +1,7 @@
<!--
Name: Circle
IsDark: True
IsBlur: False
HasBlur: False
-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@ -193,4 +193,4 @@
TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="#9da1aa" />
</Style>
</ResourceDictionary>
</ResourceDictionary>

View file

@ -1,7 +1,7 @@
<!--
Name: Windows 10
IsDark: True
IsBlur: False
HasBlur: False
-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

View file

@ -1,7 +1,7 @@
<!--
Name: Windows 11
IsDark: True
IsBlur: False
HasBlur: False
-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@ -215,4 +215,4 @@
TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
</Style>
</ResourceDictionary>
</ResourceDictionary>