Skip to content

Commit f58c950

Browse files
committed
Theme metadata adjustments
1 parent da38172 commit f58c950

File tree

9 files changed

+35
-36
lines changed

9 files changed

+35
-36
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace Flow.Launcher.Core.Resource
1818
{
1919
public class Theme
2020
{
21+
private const string ThemeMetadataNamePrefix = "Name:";
22+
private const string ThemeMetadataIsDarkPrefix = "IsDark:";
23+
private const string ThemeMetadataHasBlurPrefix = "HasBlur:";
24+
2125
private const int ShadowExtraMargin = 32;
2226

2327
private readonly List<string> _themeDirectories = new List<string>();
@@ -80,14 +84,14 @@ public bool ChangeTheme(string theme)
8084
{
8185
if (string.IsNullOrEmpty(path))
8286
throw new DirectoryNotFoundException("Theme path can't be found <{path}>");
83-
87+
8488
// reload all resources even if the theme itself hasn't changed in order to pickup changes
8589
// to things like fonts
8690
UpdateResourceDictionary(GetResourceDictionary(theme));
87-
91+
8892
Settings.Theme = theme;
8993

90-
94+
9195
//always allow re-loading default theme, in case of failure of switching to a new theme from default theme
9296
if (_oldTheme != theme || theme == defaultTheme)
9397
{
@@ -149,7 +153,7 @@ private ResourceDictionary GetThemeResourceDictionary(string theme)
149153
public ResourceDictionary GetResourceDictionary(string theme)
150154
{
151155
var dict = GetThemeResourceDictionary(theme);
152-
156+
153157
if (dict["QueryBoxStyle"] is Style queryBoxStyle &&
154158
dict["QuerySuggestionBoxStyle"] is Style querySuggestionBoxStyle)
155159
{
@@ -188,7 +192,7 @@ public ResourceDictionary GetResourceDictionary(string theme)
188192

189193
Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch };
190194
Array.ForEach(
191-
new[] { resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o
195+
new[] { resultItemStyle, resultItemSelectedStyle, resultHotkeyItemStyle, resultHotkeyItemSelectedStyle }, o
192196
=> Array.ForEach(setters, p => o.Setters.Add(p)));
193197
}
194198

@@ -246,34 +250,27 @@ private ThemeData GetThemeDataFromPath(string path)
246250
return new ThemeData(extensionlessName, extensionlessName);
247251

248252
var commentLines = reader.Value.Trim().Split('\n').Select(v => v.Trim());
249-
var themeData = new ThemeData(extensionlessName, extensionlessName);
253+
254+
var name = extensionlessName;
255+
bool? isDark = null;
256+
bool? hasBlur = null;
250257
foreach (var line in commentLines)
251258
{
252-
if (line.StartsWith("Name:", StringComparison.OrdinalIgnoreCase))
259+
if (line.StartsWith(ThemeMetadataNamePrefix, StringComparison.OrdinalIgnoreCase))
253260
{
254-
themeData = themeData with { Name = line.Remove(0, "Name:".Length).Trim() };
261+
name = line.Remove(0, ThemeMetadataNamePrefix.Length).Trim();
255262
}
256-
else if (line.StartsWith("IsDark:", StringComparison.OrdinalIgnoreCase))
263+
else if (line.StartsWith(ThemeMetadataIsDarkPrefix, StringComparison.OrdinalIgnoreCase))
257264
{
258-
themeData = themeData with
259-
{
260-
IsDark = bool.Parse(
261-
line.Remove(0, "IsDark:".Length).Trim()
262-
)
263-
};
265+
isDark = bool.Parse(line.Remove(0, ThemeMetadataIsDarkPrefix.Length).Trim());
264266
}
265-
else if (line.StartsWith("IsBlur:", StringComparison.OrdinalIgnoreCase))
267+
else if (line.StartsWith(ThemeMetadataHasBlurPrefix, StringComparison.OrdinalIgnoreCase))
266268
{
267-
themeData = themeData with
268-
{
269-
IsBlur = bool.Parse(
270-
line.Remove(0, "IsBlur:".Length).Trim()
271-
)
272-
};
269+
hasBlur = bool.Parse(line.Remove(0, ThemeMetadataHasBlurPrefix.Length).Trim());
273270
}
274271
}
275272

276-
return themeData;
273+
return new ThemeData(extensionlessName, name, isDark, hasBlur);
277274
}
278275

279276
private string GetThemePath(string themeName)
@@ -452,6 +449,6 @@ private void SetWindowAccent(Window w, AccentState state)
452449
}
453450
#endregion
454451

455-
public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, bool? IsBlur = null);
452+
public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, bool? HasBlur = null);
456453
}
457454
}

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public double ResultSubItemFontSize
9393
get => Settings.ResultSubItemFontSize;
9494
set => Settings.ResultSubItemFontSize = value;
9595
}
96-
public List<Theme.ThemeData> Themes => ThemeManager.Instance.LoadAvailableThemes();
96+
97+
private List<Theme.ThemeData> _themes;
98+
public List<Theme.ThemeData> Themes => _themes ??= ThemeManager.Instance.LoadAvailableThemes();
9799

98100

99101
public class ColorScheme

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@
396396
VerticalAlignment="Center"
397397
FontSize="12"
398398
Glyph="&#xEB42;"
399-
Visibility="{Binding SelectedTheme.IsBlur, Converter={StaticResource BoolToVisibilityConverter}}" />
399+
Visibility="{Binding SelectedTheme.HasBlur, Converter={StaticResource BoolToVisibilityConverter}}" />
400400
<TextBlock Text="{Binding SelectedTheme.Name}" />
401401
</StackPanel>
402402
</cc:ExCard.SideContent>
@@ -442,7 +442,7 @@
442442
VerticalAlignment="Center"
443443
FontSize="12"
444444
Glyph="&#xEB42;"
445-
Visibility="{Binding IsBlur, Converter={StaticResource BoolToVisibilityConverter}}" />
445+
Visibility="{Binding HasBlur, Converter={StaticResource BoolToVisibilityConverter}}" />
446446
</StackPanel>
447447
</Grid>
448448
</DataTemplate>

Flow.Launcher/Themes/BlurBlack Darker.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
Name: Blur Black Darker
33
IsDark: False
4-
IsBlur: True
4+
HasBlur: True
55
-->
66
<ResourceDictionary
77
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

Flow.Launcher/Themes/BlurBlack.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
Name: Blur Black
33
IsDark: False
4-
IsBlur: True
4+
HasBlur: True
55
-->
66
<ResourceDictionary
77
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -173,4 +173,4 @@
173173
TargetType="{x:Type TextBlock}">
174174
<Setter Property="Foreground" Value="#FFFFFFFF" />
175175
</Style>
176-
</ResourceDictionary>
176+
</ResourceDictionary>

Flow.Launcher/Themes/BlurWhite.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
Name: Blur White
33
IsDark: False
4-
IsBlur: True
4+
HasBlur: True
55
-->
66
<ResourceDictionary
77
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

Flow.Launcher/Themes/Circle System.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
Name: Circle
33
IsDark: True
4-
IsBlur: False
4+
HasBlur: False
55
-->
66
<ResourceDictionary
77
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -193,4 +193,4 @@
193193
TargetType="{x:Type TextBlock}">
194194
<Setter Property="Foreground" Value="#9da1aa" />
195195
</Style>
196-
</ResourceDictionary>
196+
</ResourceDictionary>

Flow.Launcher/Themes/Win10System.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
Name: Windows 10
33
IsDark: True
4-
IsBlur: False
4+
HasBlur: False
55
-->
66
<ResourceDictionary
77
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

Flow.Launcher/Themes/Win11Light.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--
22
Name: Windows 11
33
IsDark: True
4-
IsBlur: False
4+
HasBlur: False
55
-->
66
<ResourceDictionary
77
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -215,4 +215,4 @@
215215
TargetType="{x:Type TextBlock}">
216216
<Setter Property="Foreground" Value="{DynamicResource Color05B}" />
217217
</Style>
218-
</ResourceDictionary>
218+
</ResourceDictionary>

0 commit comments

Comments
 (0)