Skip to content

Commit f78521e

Browse files
committed
Merge branch 'add-theme-metadata' into 240518Adjusthemes
2 parents a8fae4d + 4ec7647 commit f78521e

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Xml;
56
using System.Runtime.InteropServices;
67
using System.Windows;
78
using System.Windows.Controls;
@@ -219,17 +220,60 @@ private ResourceDictionary GetCurrentResourceDictionary( )
219220
return GetResourceDictionary(Settings.Theme);
220221
}
221222

222-
public List<string> LoadAvailableThemes()
223+
public List<ThemeData> LoadAvailableThemes()
223224
{
224-
List<string> themes = new List<string>();
225+
List<ThemeData> themes = new List<ThemeData>();
225226
foreach (var themeDirectory in _themeDirectories)
226227
{
227-
themes.AddRange(
228-
Directory.GetFiles(themeDirectory)
229-
.Where(filePath => filePath.EndsWith(Extension) && !filePath.EndsWith("Base.xaml"))
230-
.ToList());
228+
var filePaths = Directory
229+
.GetFiles(themeDirectory)
230+
.Where(filePath => filePath.EndsWith(Extension) && !filePath.EndsWith("Base.xaml"))
231+
.Select(GetThemeDataFromPath);
232+
themes.AddRange(filePaths);
231233
}
232-
return themes.OrderBy(o => o).ToList();
234+
235+
return themes.OrderBy(o => o.Name).ToList();
236+
}
237+
238+
private ThemeData GetThemeDataFromPath(string path)
239+
{
240+
using var reader = XmlReader.Create(path);
241+
reader.Read();
242+
243+
var extensionlessName = Path.GetFileNameWithoutExtension(path);
244+
245+
if (reader.NodeType is not XmlNodeType.Comment)
246+
return new ThemeData(extensionlessName, extensionlessName);
247+
248+
var commentLines = reader.Value.Trim().Split('\n').Select(v => v.Trim());
249+
var themeData = new ThemeData(extensionlessName, extensionlessName);
250+
foreach (var line in commentLines)
251+
{
252+
if (line.StartsWith("Name:", StringComparison.OrdinalIgnoreCase))
253+
{
254+
themeData = themeData with { Name = line.Remove(0, "Name:".Length).Trim() };
255+
}
256+
else if (line.StartsWith("IsDark:", StringComparison.OrdinalIgnoreCase))
257+
{
258+
themeData = themeData with
259+
{
260+
IsDark = bool.Parse(
261+
line.Remove(0, "IsDark:".Length).Trim()
262+
)
263+
};
264+
}
265+
else if (line.StartsWith("BlurAmount:", StringComparison.OrdinalIgnoreCase))
266+
{
267+
themeData = themeData with
268+
{
269+
BlurAmount = int.Parse(
270+
line.Remove(0, "BlurAmount:".Length).Trim()
271+
)
272+
};
273+
}
274+
}
275+
276+
return themeData;
233277
}
234278

235279
private string GetThemePath(string themeName)
@@ -407,5 +451,7 @@ private void SetWindowAccent(Window w, AccentState state)
407451
Marshal.FreeHGlobal(accentPtr);
408452
}
409453
#endregion
454+
455+
public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, int? BlurAmount = null);
410456
}
411457
}

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ public double ResultSubItemFontSize
9191
get => Settings.ResultSubItemFontSize;
9292
set => Settings.ResultSubItemFontSize = value;
9393
}
94-
public List<string> Themes =>
95-
ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension).ToList();
94+
public List<Theme.ThemeData> Themes => ThemeManager.Instance.LoadAvailableThemes();
9695

9796

9897
public class ColorScheme

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@
409409
ItemsSource="{Binding Themes}"
410410
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
411411
ScrollViewer.VerticalScrollBarVisibility="Disabled"
412-
SelectedItem="{Binding SelectedTheme}">
412+
SelectedValue="{Binding SelectedTheme}"
413+
SelectedValuePath="FileNameWithoutExtension">
413414
<ListBox.ItemContainerStyle>
414415
<Style TargetType="ListBoxItem">
415416
<Setter Property="Background" Value="Transparent" />
@@ -474,7 +475,7 @@
474475
VerticalAlignment="Center"
475476
Focusable="True"
476477
FontSize="12"
477-
Text="{Binding}"
478+
Text="{Binding Name}"
478479
TextWrapping="Wrap" />
479480
</Grid>
480481
</DataTemplate>

Flow.Launcher/Themes/Win11System.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<!--
2+
Name: Windows 11
3+
IsDark: True
4+
BlurAmount: 0
5+
-->
16
<ResourceDictionary
27
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
38
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

0 commit comments

Comments
 (0)