Skip to content

Commit 9b9704e

Browse files
committed
Improve settings panel theme page & theme selector
1 parent 358b1fd commit 9b9704e

File tree

2 files changed

+17
-44
lines changed

2 files changed

+17
-44
lines changed

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,23 @@ public partial class SettingsPaneThemeViewModel : BaseModel
2828
public static string LinkHowToCreateTheme => @"https://www.flowlauncher.com/theme-builder/";
2929
public static string LinkThemeGallery => "https://github.com/Flow-Launcher/Flow.Launcher/discussions/1438";
3030

31-
private List<Theme.ThemeData> _themes;
32-
public List<Theme.ThemeData> Themes => _themes ??= _theme.LoadAvailableThemes();
31+
private List<ThemeData> _themes;
32+
public List<ThemeData> Themes => _themes ??= App.API.GetAvailableThemes();
3333

34-
private Theme.ThemeData _selectedTheme;
35-
public Theme.ThemeData SelectedTheme
34+
private ThemeData _selectedTheme;
35+
public ThemeData SelectedTheme
3636
{
37-
get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == _theme.GetCurrentTheme());
37+
get => _selectedTheme ??= Themes.Find(v => v == App.API.GetCurrentTheme());
3838
set
3939
{
4040
_selectedTheme = value;
41-
_theme.ChangeTheme(value.FileNameWithoutExtension);
41+
App.API.SetCurrentTheme(value);
4242

4343
// Update UI state
4444
OnPropertyChanged(nameof(BackdropType));
4545
OnPropertyChanged(nameof(IsBackdropEnabled));
4646
OnPropertyChanged(nameof(IsDropShadowEnabled));
4747
OnPropertyChanged(nameof(DropShadowEffect));
48-
49-
_ = _theme.RefreshFrameAsync();
5048
}
5149
}
5250

Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System.Collections.Generic;
22
using System.Linq;
3-
using CommunityToolkit.Mvvm.DependencyInjection;
4-
using Flow.Launcher.Core.Resource;
53

64
namespace Flow.Launcher.Plugin.Sys
75
{
@@ -11,61 +9,38 @@ public class ThemeSelector
119

1210
private readonly PluginInitContext _context;
1311

14-
// Do not initialize it in the constructor, because it will cause null reference in
15-
// var dicts = Application.Current.Resources.MergedDictionaries; line of Theme
16-
private Theme theme = null;
17-
private Theme Theme => theme ??= Ioc.Default.GetRequiredService<Theme>();
18-
19-
#region Theme Selection
20-
21-
// Theme select codes simplified from SettingsPaneThemeViewModel.cs
22-
23-
private Theme.ThemeData _selectedTheme;
24-
public Theme.ThemeData SelectedTheme
25-
{
26-
get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == Theme.GetCurrentTheme());
27-
set
28-
{
29-
_selectedTheme = value;
30-
Theme.ChangeTheme(value.FileNameWithoutExtension);
31-
32-
_ = Theme.RefreshFrameAsync();
33-
}
34-
}
35-
36-
private List<Theme.ThemeData> Themes => Theme.LoadAvailableThemes();
37-
38-
#endregion
39-
4012
public ThemeSelector(PluginInitContext context)
4113
{
4214
_context = context;
4315
}
4416

4517
public List<Result> Query(Query query)
4618
{
19+
var themes = _context.API.GetAvailableThemes();
20+
var selectedTheme = _context.API.GetCurrentTheme();
21+
4722
var search = query.SecondToEndSearch;
4823
if (string.IsNullOrWhiteSpace(search))
4924
{
50-
return Themes.Select(CreateThemeResult)
25+
return themes.Select(x => CreateThemeResult(x, selectedTheme))
5126
.OrderBy(x => x.Title)
5227
.ToList();
5328
}
5429

55-
return Themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme.Name)))
30+
return themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme.Name)))
5631
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
57-
.Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData))
32+
.Select(x => CreateThemeResult(x.theme, selectedTheme, x.matchResult.Score, x.matchResult.MatchData))
5833
.OrderBy(x => x.Title)
5934
.ToList();
6035
}
6136

62-
private Result CreateThemeResult(Theme.ThemeData theme) => CreateThemeResult(theme, 0, null);
37+
private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme) => CreateThemeResult(theme, selectedTheme, 0, null);
6338

64-
private Result CreateThemeResult(Theme.ThemeData theme, int score, IList<int> highlightData)
39+
private Result CreateThemeResult(ThemeData theme, ThemeData selectedTheme, int score, IList<int> highlightData)
6540
{
66-
string themeName = theme.Name;
41+
var themeName = theme.FileNameWithoutExtension;
6742
string title;
68-
if (theme == SelectedTheme)
43+
if (theme == selectedTheme)
6944
{
7045
title = $"{theme.Name} ★";
7146
// Set current theme to the top
@@ -101,7 +76,7 @@ private Result CreateThemeResult(Theme.ThemeData theme, int score, IList<int> hi
10176
Score = score,
10277
Action = c =>
10378
{
104-
SelectedTheme = theme;
79+
_context.API.SetCurrentTheme(theme);
10580
_context.API.ReQuery();
10681
return false;
10782
}

0 commit comments

Comments
 (0)