From 8463304bd4811ed70a13d75b916153b12dd9fed0 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 24 Apr 2025 19:56:31 +0800 Subject: [PATCH] Fix clock panel font issue & Improve preview performance & Improve code quality --- .../ViewModels/SettingsPaneThemeViewModel.cs | 104 +++++++++--------- .../SettingPages/Views/SettingsPaneTheme.xaml | 4 +- .../Views/SettingsPaneTheme.xaml.cs | 6 +- 3 files changed, 59 insertions(+), 55 deletions(-) diff --git a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs index 1138b2869..d542eb019 100644 --- a/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs +++ b/Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs @@ -6,7 +6,6 @@ using System.Globalization; using System.IO; using System.Linq; using System.Windows.Media; -using CommunityToolkit.Mvvm.DependencyInjection; using CommunityToolkit.Mvvm.Input; using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; @@ -22,10 +21,12 @@ namespace Flow.Launcher.SettingPages.ViewModels; public partial class SettingsPaneThemeViewModel : BaseModel { + public Settings Settings { get; } + + private readonly Theme _theme; + private readonly string DefaultFont = Win32Helper.GetSystemDefaultFont(); public string BackdropSubText => !Win32Helper.IsBackdropSupported() ? App.API.GetTranslation("BackdropTypeDisabledToolTip") : ""; - public Settings Settings { get; } - private readonly Theme _theme = Ioc.Default.GetRequiredService(); public static string LinkHowToCreateTheme => @"https://www.flowlauncher.com/theme-builder/"; public static string LinkThemeGallery => "https://github.com/Flow-Launcher/Flow.Launcher/discussions/1438"; @@ -289,59 +290,14 @@ public partial class SettingsPaneThemeViewModel : BaseModel set => Settings.UseDate = value; } + public FontFamily ClockPanelFont { get; } + public Brush PreviewBackground { get => WallpaperPathRetrieval.GetWallpaperBrush(); } - public ResultsViewModel PreviewResults - { - get - { - var results = new List - { - new() - { - Title = App.API.GetTranslation("SampleTitleExplorer"), - SubTitle = App.API.GetTranslation("SampleSubTitleExplorer"), - IcoPath = Path.Combine( - Constant.ProgramDirectory, - @"Plugins\Flow.Launcher.Plugin.Explorer\Images\explorer.png" - ) - }, - new() - { - Title = App.API.GetTranslation("SampleTitleWebSearch"), - SubTitle = App.API.GetTranslation("SampleSubTitleWebSearch"), - IcoPath = Path.Combine( - Constant.ProgramDirectory, - @"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png" - ) - }, - new() - { - Title = App.API.GetTranslation("SampleTitleProgram"), - SubTitle = App.API.GetTranslation("SampleSubTitleProgram"), - IcoPath = Path.Combine( - Constant.ProgramDirectory, - @"Plugins\Flow.Launcher.Plugin.Program\Images\program.png" - ) - }, - new() - { - Title = App.API.GetTranslation("SampleTitleProcessKiller"), - SubTitle = App.API.GetTranslation("SampleSubTitleProcessKiller"), - IcoPath = Path.Combine( - Constant.ProgramDirectory, - @"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png" - ) - } - }; - var vm = new ResultsViewModel(Settings); - vm.AddResults(results, "PREVIEW"); - return vm; - } - } + public ResultsViewModel PreviewResults { get; } public FontFamily SelectedQueryBoxFont { @@ -479,9 +435,53 @@ public partial class SettingsPaneThemeViewModel : BaseModel public string ThemeImage => Constant.QueryTextBoxIconImagePath; - public SettingsPaneThemeViewModel(Settings settings) + public SettingsPaneThemeViewModel(Settings settings, Theme theme) { Settings = settings; + _theme = theme; + ClockPanelFont = new FontFamily(DefaultFont); + var results = new List + { + new() + { + Title = App.API.GetTranslation("SampleTitleExplorer"), + SubTitle = App.API.GetTranslation("SampleSubTitleExplorer"), + IcoPath = Path.Combine( + Constant.ProgramDirectory, + @"Plugins\Flow.Launcher.Plugin.Explorer\Images\explorer.png" + ) + }, + new() + { + Title = App.API.GetTranslation("SampleTitleWebSearch"), + SubTitle = App.API.GetTranslation("SampleSubTitleWebSearch"), + IcoPath = Path.Combine( + Constant.ProgramDirectory, + @"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png" + ) + }, + new() + { + Title = App.API.GetTranslation("SampleTitleProgram"), + SubTitle = App.API.GetTranslation("SampleSubTitleProgram"), + IcoPath = Path.Combine( + Constant.ProgramDirectory, + @"Plugins\Flow.Launcher.Plugin.Program\Images\program.png" + ) + }, + new() + { + Title = App.API.GetTranslation("SampleTitleProcessKiller"), + SubTitle = App.API.GetTranslation("SampleSubTitleProcessKiller"), + IcoPath = Path.Combine( + Constant.ProgramDirectory, + @"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png" + ) + } + }; + var vm = new ResultsViewModel(Settings); + vm.AddResults(results, "PREVIEW"); + PreviewResults = vm; } [RelayCommand] diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml index f7853515a..4640165f6 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml @@ -331,20 +331,22 @@ IsReadOnly="True" Style="{DynamicResource QueryBoxStyle}" Text="{DynamicResource hiThere}" /> - + diff --git a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs index f4c103ade..a1a0231a5 100644 --- a/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs +++ b/Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs @@ -1,7 +1,8 @@ using System.Windows.Navigation; using CommunityToolkit.Mvvm.DependencyInjection; -using Flow.Launcher.SettingPages.ViewModels; +using Flow.Launcher.Core.Resource; using Flow.Launcher.Infrastructure.UserSettings; +using Flow.Launcher.SettingPages.ViewModels; using Page = ModernWpf.Controls.Page; namespace Flow.Launcher.SettingPages.Views; @@ -15,7 +16,8 @@ public partial class SettingsPaneTheme : Page if (!IsInitialized) { var settings = Ioc.Default.GetRequiredService(); - _viewModel = new SettingsPaneThemeViewModel(settings); + var theme = Ioc.Default.GetRequiredService(); + _viewModel = new SettingsPaneThemeViewModel(settings, theme); DataContext = _viewModel; InitializeComponent(); }