From a28ee701b8a562c6974a4b6139055854881bc45c Mon Sep 17 00:00:00 2001 From: DB p Date: Thu, 17 Apr 2025 18:45:31 +0900 Subject: [PATCH 01/12] Add settingwindowfont config and menu --- .../UserSettings/Settings.cs | 21 ++++---- .../ViewModels/SettingsPaneAboutViewModel.cs | 49 +++++++++++++++++++ .../SettingPages/Views/SettingsPaneAbout.xaml | 46 ++++++++++++++--- .../Views/SettingsPaneAbout.xaml.cs | 22 ++++++++- Flow.Launcher/SettingWindow.xaml | 1 + Flow.Launcher/SettingWindow.xaml.cs | 1 + .../ViewModel/SettingWindowViewModel.cs | 26 +++++++++- 7 files changed, 147 insertions(+), 19 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 0bd1a809b7a..d91574bdc7a 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -65,19 +65,21 @@ public void Save() { "pt", "Noto Sans" } }; - public static string GetSystemDefaultFont() + public static string GetSystemDefaultFont(bool? useNoto = null) { try { - var culture = CultureInfo.CurrentCulture; - var language = culture.Name; // e.g., "zh-TW" - var langPrefix = language.Split('-')[0]; // e.g., "zh" - - // First, try to find by full name, and if not found, fallback to prefix - if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont)) + if (useNoto != false) { - if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont))) - return notoFont; + var culture = CultureInfo.CurrentCulture; + var language = culture.Name; // e.g., "zh-TW" + var langPrefix = language.Split('-')[0]; // e.g., "zh" + + if (TryGetNotoFont(language, out var notoFont) || TryGetNotoFont(langPrefix, out notoFont)) + { + if (Fonts.SystemFontFamilies.Any(f => f.Source.Equals(notoFont))) + return notoFont; + } } var font = SystemFonts.MessageFontFamily; @@ -162,6 +164,7 @@ public string Theme public string ResultSubFontStyle { get; set; } public string ResultSubFontWeight { get; set; } public string ResultSubFontStretch { get; set; } + public string SettingWindowFont { get; set; } = GetSystemDefaultFont(false); public bool UseGlyphIcons { get; set; } = true; public bool UseAnimation { get; set; } = true; public bool UseSound { get; set; } = true; diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs index 6cfb9830656..abc7a2d16f2 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneAboutViewModel.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows; +using System.Windows.Media; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core; using Flow.Launcher.Infrastructure; @@ -268,4 +270,51 @@ private static string BytesToReadableString(long bytes) return "0 B"; } + + public event PropertyChangedEventHandler PropertyChanged; + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private string _settingWindowFont; + + public string SettingWindowFont + { + get => _settings.SettingWindowFont; + set + { + if (_settings.SettingWindowFont != value) + { + _settings.SettingWindowFont = value; + OnPropertyChanged(nameof(SettingWindowFont)); + } + } + } + + [RelayCommand] + private void ResetSettingWindowFont() + { + string defaultFont = GetSystemDefaultFont(); + _settings.SettingWindowFont = defaultFont; + } + + public static string GetSystemDefaultFont() + { + try + { + var font = SystemFonts.MessageFontFamily; + if (font.FamilyNames.TryGetValue(System.Windows.Markup.XmlLanguage.GetLanguage("en-US"), out var englishName)) + { + return englishName; + } + + return font.Source ?? "Segoe UI"; + } + catch + { + return "Segoe UI"; + } + } + } diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml index f7deee7cfdc..b3991743d4f 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml @@ -12,6 +12,11 @@ d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> + + + + + - - - + + + + + + + + - - + + - + - - + + - + @@ -124,14 +125,14 @@ LastChildFill="True">