Fix clock panel font issue & Improve preview performance & Improve code quality

This commit is contained in:
Jack251970 2025-04-24 19:56:31 +08:00
parent 89127895d0
commit 8463304bd4
3 changed files with 59 additions and 55 deletions

View file

@ -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<Theme>();
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<Result>
{
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<Result>
{
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]

View file

@ -331,20 +331,22 @@
IsReadOnly="True"
Style="{DynamicResource QueryBoxStyle}"
Text="{DynamicResource hiThere}" />
</Border>
<StackPanel
x:Name="ClockPanel"
IsHitTestVisible="False"
Style="{DynamicResource ClockPanel}"
Visibility="Visible">
<!-- Because these two textblock follow SettingWindowFont, we need to revert its font family explictly -->
<TextBlock
x:Name="ClockBox"
FontFamily="{Binding ClockPanelFont, Mode=OneTime}"
Style="{DynamicResource ClockBox}"
Text="{Binding ClockText}"
Visibility="{Binding UseClock, Converter={StaticResource BoolToVisibilityConverter}}" />
<TextBlock
x:Name="DateBox"
FontFamily="{Binding ClockPanelFont, Mode=OneTime}"
Style="{DynamicResource DateBox}"
Text="{Binding DateText}"
Visibility="{Binding UseDate, Converter={StaticResource BoolToVisibilityConverter}}" />

View file

@ -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<Settings>();
_viewModel = new SettingsPaneThemeViewModel(settings);
var theme = Ioc.Default.GetRequiredService<Theme>();
_viewModel = new SettingsPaneThemeViewModel(settings, theme);
DataContext = _viewModel;
InitializeComponent();
}