Skip to content

Commit 8463304

Browse files
committed
Fix clock panel font issue & Improve preview performance & Improve code quality
1 parent 8912789 commit 8463304

File tree

3 files changed

+59
-55
lines changed

3 files changed

+59
-55
lines changed

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.IO;
77
using System.Linq;
88
using System.Windows.Media;
9-
using CommunityToolkit.Mvvm.DependencyInjection;
109
using CommunityToolkit.Mvvm.Input;
1110
using Flow.Launcher.Core.Resource;
1211
using Flow.Launcher.Helper;
@@ -22,10 +21,12 @@ namespace Flow.Launcher.SettingPages.ViewModels;
2221

2322
public partial class SettingsPaneThemeViewModel : BaseModel
2423
{
24+
public Settings Settings { get; }
25+
26+
private readonly Theme _theme;
27+
2528
private readonly string DefaultFont = Win32Helper.GetSystemDefaultFont();
2629
public string BackdropSubText => !Win32Helper.IsBackdropSupported() ? App.API.GetTranslation("BackdropTypeDisabledToolTip") : "";
27-
public Settings Settings { get; }
28-
private readonly Theme _theme = Ioc.Default.GetRequiredService<Theme>();
2930

3031
public static string LinkHowToCreateTheme => @"https://www.flowlauncher.com/theme-builder/";
3132
public static string LinkThemeGallery => "https://github.com/Flow-Launcher/Flow.Launcher/discussions/1438";
@@ -289,59 +290,14 @@ public bool UseDate
289290
set => Settings.UseDate = value;
290291
}
291292

293+
public FontFamily ClockPanelFont { get; }
294+
292295
public Brush PreviewBackground
293296
{
294297
get => WallpaperPathRetrieval.GetWallpaperBrush();
295298
}
296299

297-
public ResultsViewModel PreviewResults
298-
{
299-
get
300-
{
301-
var results = new List<Result>
302-
{
303-
new()
304-
{
305-
Title = App.API.GetTranslation("SampleTitleExplorer"),
306-
SubTitle = App.API.GetTranslation("SampleSubTitleExplorer"),
307-
IcoPath = Path.Combine(
308-
Constant.ProgramDirectory,
309-
@"Plugins\Flow.Launcher.Plugin.Explorer\Images\explorer.png"
310-
)
311-
},
312-
new()
313-
{
314-
Title = App.API.GetTranslation("SampleTitleWebSearch"),
315-
SubTitle = App.API.GetTranslation("SampleSubTitleWebSearch"),
316-
IcoPath = Path.Combine(
317-
Constant.ProgramDirectory,
318-
@"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png"
319-
)
320-
},
321-
new()
322-
{
323-
Title = App.API.GetTranslation("SampleTitleProgram"),
324-
SubTitle = App.API.GetTranslation("SampleSubTitleProgram"),
325-
IcoPath = Path.Combine(
326-
Constant.ProgramDirectory,
327-
@"Plugins\Flow.Launcher.Plugin.Program\Images\program.png"
328-
)
329-
},
330-
new()
331-
{
332-
Title = App.API.GetTranslation("SampleTitleProcessKiller"),
333-
SubTitle = App.API.GetTranslation("SampleSubTitleProcessKiller"),
334-
IcoPath = Path.Combine(
335-
Constant.ProgramDirectory,
336-
@"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png"
337-
)
338-
}
339-
};
340-
var vm = new ResultsViewModel(Settings);
341-
vm.AddResults(results, "PREVIEW");
342-
return vm;
343-
}
344-
}
300+
public ResultsViewModel PreviewResults { get; }
345301

346302
public FontFamily SelectedQueryBoxFont
347303
{
@@ -479,9 +435,53 @@ public FamilyTypeface SelectedResultSubFontFaces
479435

480436
public string ThemeImage => Constant.QueryTextBoxIconImagePath;
481437

482-
public SettingsPaneThemeViewModel(Settings settings)
438+
public SettingsPaneThemeViewModel(Settings settings, Theme theme)
483439
{
484440
Settings = settings;
441+
_theme = theme;
442+
ClockPanelFont = new FontFamily(DefaultFont);
443+
var results = new List<Result>
444+
{
445+
new()
446+
{
447+
Title = App.API.GetTranslation("SampleTitleExplorer"),
448+
SubTitle = App.API.GetTranslation("SampleSubTitleExplorer"),
449+
IcoPath = Path.Combine(
450+
Constant.ProgramDirectory,
451+
@"Plugins\Flow.Launcher.Plugin.Explorer\Images\explorer.png"
452+
)
453+
},
454+
new()
455+
{
456+
Title = App.API.GetTranslation("SampleTitleWebSearch"),
457+
SubTitle = App.API.GetTranslation("SampleSubTitleWebSearch"),
458+
IcoPath = Path.Combine(
459+
Constant.ProgramDirectory,
460+
@"Plugins\Flow.Launcher.Plugin.WebSearch\Images\web_search.png"
461+
)
462+
},
463+
new()
464+
{
465+
Title = App.API.GetTranslation("SampleTitleProgram"),
466+
SubTitle = App.API.GetTranslation("SampleSubTitleProgram"),
467+
IcoPath = Path.Combine(
468+
Constant.ProgramDirectory,
469+
@"Plugins\Flow.Launcher.Plugin.Program\Images\program.png"
470+
)
471+
},
472+
new()
473+
{
474+
Title = App.API.GetTranslation("SampleTitleProcessKiller"),
475+
SubTitle = App.API.GetTranslation("SampleSubTitleProcessKiller"),
476+
IcoPath = Path.Combine(
477+
Constant.ProgramDirectory,
478+
@"Plugins\Flow.Launcher.Plugin.ProcessKiller\Images\app.png"
479+
)
480+
}
481+
};
482+
var vm = new ResultsViewModel(Settings);
483+
vm.AddResults(results, "PREVIEW");
484+
PreviewResults = vm;
485485
}
486486

487487
[RelayCommand]

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,22 @@
331331
IsReadOnly="True"
332332
Style="{DynamicResource QueryBoxStyle}"
333333
Text="{DynamicResource hiThere}" />
334-
335334
</Border>
336335
<StackPanel
337336
x:Name="ClockPanel"
338337
IsHitTestVisible="False"
339338
Style="{DynamicResource ClockPanel}"
340339
Visibility="Visible">
340+
<!-- Because these two textblock follow SettingWindowFont, we need to revert its font family explictly -->
341341
<TextBlock
342342
x:Name="ClockBox"
343+
FontFamily="{Binding ClockPanelFont, Mode=OneTime}"
343344
Style="{DynamicResource ClockBox}"
344345
Text="{Binding ClockText}"
345346
Visibility="{Binding UseClock, Converter={StaticResource BoolToVisibilityConverter}}" />
346347
<TextBlock
347348
x:Name="DateBox"
349+
FontFamily="{Binding ClockPanelFont, Mode=OneTime}"
348350
Style="{DynamicResource DateBox}"
349351
Text="{Binding DateText}"
350352
Visibility="{Binding UseDate, Converter={StaticResource BoolToVisibilityConverter}}" />

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System.Windows.Navigation;
22
using CommunityToolkit.Mvvm.DependencyInjection;
3-
using Flow.Launcher.SettingPages.ViewModels;
3+
using Flow.Launcher.Core.Resource;
44
using Flow.Launcher.Infrastructure.UserSettings;
5+
using Flow.Launcher.SettingPages.ViewModels;
56
using Page = ModernWpf.Controls.Page;
67

78
namespace Flow.Launcher.SettingPages.Views;
@@ -15,7 +16,8 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
1516
if (!IsInitialized)
1617
{
1718
var settings = Ioc.Default.GetRequiredService<Settings>();
18-
_viewModel = new SettingsPaneThemeViewModel(settings);
19+
var theme = Ioc.Default.GetRequiredService<Theme>();
20+
_viewModel = new SettingsPaneThemeViewModel(settings, theme);
1921
DataContext = _viewModel;
2022
InitializeComponent();
2123
}

0 commit comments

Comments
 (0)