Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions Flow.Launcher.Core/Resource/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -219,17 +220,60 @@ private ResourceDictionary GetCurrentResourceDictionary( )
return GetResourceDictionary(Settings.Theme);
}

public List<string> LoadAvailableThemes()
public List<ThemeData> LoadAvailableThemes()
{
List<string> themes = new List<string>();
List<ThemeData> themes = new List<ThemeData>();
foreach (var themeDirectory in _themeDirectories)
{
themes.AddRange(
Directory.GetFiles(themeDirectory)
.Where(filePath => filePath.EndsWith(Extension) && !filePath.EndsWith("Base.xaml"))
.ToList());
var filePaths = Directory
.GetFiles(themeDirectory)
.Where(filePath => filePath.EndsWith(Extension) && !filePath.EndsWith("Base.xaml"))
.Select(GetThemeDataFromPath);
themes.AddRange(filePaths);
}
return themes.OrderBy(o => o).ToList();

return themes.OrderBy(o => o.Name).ToList();
}

private ThemeData GetThemeDataFromPath(string path)
{
using var reader = XmlReader.Create(path);
reader.Read();

var extensionlessName = Path.GetFileNameWithoutExtension(path);

if (reader.NodeType is not XmlNodeType.Comment)
return new ThemeData(extensionlessName, extensionlessName);

var commentLines = reader.Value.Trim().Split('\n').Select(v => v.Trim());
var themeData = new ThemeData(extensionlessName, extensionlessName);
foreach (var line in commentLines)
{
if (line.StartsWith("Name:", StringComparison.OrdinalIgnoreCase))
{
themeData = themeData with { Name = line.Remove(0, "Name:".Length).Trim() };
}
else if (line.StartsWith("IsDark:", StringComparison.OrdinalIgnoreCase))
{
themeData = themeData with
{
IsDark = bool.Parse(
line.Remove(0, "IsDark:".Length).Trim()
)
};
}
else if (line.StartsWith("BlurAmount:", StringComparison.OrdinalIgnoreCase))
{
themeData = themeData with
{
BlurAmount = int.Parse(
line.Remove(0, "BlurAmount:".Length).Trim()
)
};
}
}

return themeData;
}

private string GetThemePath(string themeName)
Expand Down Expand Up @@ -407,5 +451,7 @@ private void SetWindowAccent(Window w, AccentState state)
Marshal.FreeHGlobal(accentPtr);
}
#endregion

public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, int? BlurAmount = null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public double ResultSubItemFontSize
get => Settings.ResultSubItemFontSize;
set => Settings.ResultSubItemFontSize = value;
}
public List<string> Themes =>
ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension).ToList();
public List<Theme.ThemeData> Themes => ThemeManager.Instance.LoadAvailableThemes();


public class ColorScheme
Expand Down
5 changes: 3 additions & 2 deletions Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@
ItemsSource="{Binding Themes}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectedItem="{Binding SelectedTheme}">
SelectedValue="{Binding SelectedTheme}"
SelectedValuePath="FileNameWithoutExtension">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent" />
Expand Down Expand Up @@ -474,7 +475,7 @@
VerticalAlignment="Center"
Focusable="True"
FontSize="12"
Text="{Binding}"
Text="{Binding Name}"
TextWrapping="Wrap" />
</Grid>
</DataTemplate>
Expand Down
5 changes: 5 additions & 0 deletions Flow.Launcher/Themes/Win11System.xaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
Name: Windows 11
IsDark: True
BlurAmount: 0
-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down