mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge branch 'add-theme-metadata' into 240518Adjusthemes
This commit is contained in:
commit
f78521ea16
4 changed files with 62 additions and 11 deletions
|
|
@ -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;
|
||||
|
|
@ -219,17 +220,60 @@ namespace Flow.Launcher.Core.Resource
|
|||
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)
|
||||
|
|
@ -407,5 +451,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
Marshal.FreeHGlobal(accentPtr);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public record ThemeData(string FileNameWithoutExtension, string Name, bool? IsDark = null, int? BlurAmount = null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,8 +91,7 @@ public partial class SettingsPaneThemeViewModel : BaseModel
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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" />
|
||||
|
|
@ -474,7 +475,7 @@
|
|||
VerticalAlignment="Center"
|
||||
Focusable="True"
|
||||
FontSize="12"
|
||||
Text="{Binding}"
|
||||
Text="{Binding Name}"
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue