Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

feat(theme): apply Material You and adaptive monochrome per-variant in ThemeService

gtxPrime5f0b8e862f6b
diff --git a/src/Filee.App/Services/ThemeService.cs b/src/Filee.App/Services/ThemeService.cs
index 6c340179..0e490cea 100644
--- a/src/Filee.App/Services/ThemeService.cs
+++ b/src/Filee.App/Services/ThemeService.cs
@@ -18,6 +18,33 @@ public sealed class ThemeService(IPlatformServices platform)
public static readonly IReadOnlyList<string> Swatches =
["#7F77DD", "#1D9E75", "#D85A30", "#378ADD", "#D4537E", "#BA7517", "#639922", "#5F5E5A"];
+ /// <summary>Curated theme preset with coordinated light and dark accent colours.</summary>
+ public sealed record ThemePreset(string Key, string LightHex, string DarkHex)
+ {
+ public Color LightColor => Color.Parse(LightHex);
+ public Color DarkColor => Color.Parse(DarkHex);
+ public Color ActiveColor(bool isDark) => isDark ? DarkColor : LightColor;
+ }
+
+ /// <summary>Curated pastel and monochrome presets offered in the Theme page.</summary>
+ public static readonly IReadOnlyList<ThemePreset> Presets =
+ [
+ new("monochrome", "#1F1E1D", "#F1EFE8"),
+ new("lavender", "#7F77DD", "#BCAEE5"),
+ new("peach", "#E07A70", "#F29B91"),
+ new("mint", "#529B7D", "#88D5B1"),
+ new("rose", "#E86483", "#F79BB0"),
+ new("sky", "#5B8BE3", "#98B8F6"),
+ new("amber", "#CB852A", "#F0BA6A"),
+ new("sage", "#5A8E51", "#8DC983"),
+ ];
+
+ /// <summary>Currently applied theme style.</summary>
+ public ThemeStyle CurrentStyle { get; private set; } = ThemeStyle.Soft;
+
+ /// <summary>True when Material You is currently applied.</summary>
+ public bool IsMaterialYou => CurrentStyle == ThemeStyle.MaterialYou;
+
/// <summary>
/// theme.json colour names → the brushes in Styles/Soft.axaml they replace. Must cover exactly
/// <see cref="CustomTheme.Keys"/> (a test checks).
@@ -40,6 +67,8 @@ public sealed class ThemeService(IPlatformServices platform)
var app = Application.Current ?? throw new InvalidOperationException("No application.");
var res = app.Resources;
+ CurrentStyle = theme.Style;
+
app.RequestedThemeVariant = theme.Mode switch
{
ThemeMode.Light => ThemeVariant.Light,
@@ -47,15 +76,47 @@ public sealed class ThemeService(IPlatformServices platform)
_ => ThemeVariant.Default,
};
+ var accent = Color.TryParse(theme.Accent, out var parsed) ? parsed : Color.Parse(SoftPalette.DefaultAccent);
+
// Accent colour + derived shades, corner radii and the font order (shared with the installer).
- SoftPalette.ApplyAccent(res, Color.TryParse(theme.Accent, out var parsed) ? parsed : Color.Parse(SoftPalette.DefaultAccent));
+ SoftPalette.ApplyAccent(res, accent);
SoftPalette.ApplyCornerRadius(res, theme.CornerRadius);
res["AppFontFamily"] = SoftPalette.FontFamilyFor(language);
SoftPalette.ApplyFlowDirection(res, language);
- // Application.Resources is searched before the styles, so these theme dictionaries win over Soft.axaml's.
- ApplyCustom(res, ThemeVariant.Light, custom?.Light);
- ApplyCustom(res, ThemeVariant.Dark, custom?.Dark);
+ if (theme.Style == ThemeStyle.MaterialYou)
+ {
+ var lightPalette = MaterialYouPalette.Generate(accent, isDark: false);
+ var darkPalette = MaterialYouPalette.Generate(accent, isDark: true);
+
+ var lightDict = lightPalette.ToResourceDictionary();
+ var darkDict = darkPalette.ToResourceDictionary();
+
+ ApplyCustomOverrides(lightDict, custom?.Light);
+ ApplyCustomOverrides(darkDict, custom?.Dark);
+
+ res.ThemeDictionaries[ThemeVariant.Light] = lightDict;
+ res.ThemeDictionaries[ThemeVariant.Dark] = darkDict;
+ }
+ else
+ {
+ if (MaterialYouPalette.IsMonochrome(accent))
+ {
+ var lightDict = new ResourceDictionary();
+ var darkDict = new ResourceDictionary();
+ SoftPalette.ApplyMonochromeAccent(lightDict, isDark: false);
+ SoftPalette.ApplyMonochromeAccent(darkDict, isDark: true);
+ ApplyCustomOverrides(lightDict, custom?.Light);
+ ApplyCustomOverrides(darkDict, custom?.Dark);
+ res.ThemeDictionaries[ThemeVariant.Light] = lightDict;
+ res.ThemeDictionaries[ThemeVariant.Dark] = darkDict;
+ }
+ else
+ {
+ ApplyCustom(res, ThemeVariant.Light, custom?.Light);
+ ApplyCustom(res, ThemeVariant.Dark, custom?.Dark);
+ }
+ }
Motion.Configure(theme.ReduceMotion, () => platform.PrefersReducedMotion);
}
@@ -63,13 +124,18 @@ public sealed class ThemeService(IPlatformServices platform)
/// <summary>The UI font chain for <paramref name="language"/> (see <see cref="SoftPalette.FontFamilies"/>).</summary>
internal static string FontFamilies(string language) => SoftPalette.FontFamilies(language);
- /// <summary>Replaces (or, with no colours, removes) the user's colours for one variant.</summary>
- private static void ApplyCustom(IResourceDictionary res, ThemeVariant variant, IReadOnlyDictionary<string, string>? colors)
+ private static void ApplyCustomOverrides(IResourceDictionary dictionary, IReadOnlyDictionary<string, string>? colors)
{
- var dictionary = new ResourceDictionary();
foreach (var (name, value) in colors ?? new Dictionary<string, string>())
if (CustomBrushKeys.TryGetValue(name, out var key) && Color.TryParse(value, out var color))
dictionary[key] = new SolidColorBrush(color);
+ }
+
+ /// <summary>Replaces (or, with no colours, removes) the user's colours for one variant.</summary>
+ private static void ApplyCustom(IResourceDictionary res, ThemeVariant variant, IReadOnlyDictionary<string, string>? colors)
+ {
+ var dictionary = new ResourceDictionary();
+ ApplyCustomOverrides(dictionary, colors);
if (dictionary.Count == 0)
res.ThemeDictionaries.Remove(variant);