Skip to content

Commit d099a39

Browse files
committed
Fix theme change drop shadow effect issue & Add theme description
1 parent 94774b2 commit d099a39

File tree

1 file changed

+74
-12
lines changed

1 file changed

+74
-12
lines changed

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

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,64 @@
22
using System.Linq;
33
using CommunityToolkit.Mvvm.DependencyInjection;
44
using Flow.Launcher.Core.Resource;
5+
using Flow.Launcher.Infrastructure.UserSettings;
56

67
namespace Flow.Launcher.Plugin.Sys
78
{
89
public class ThemeSelector
910
{
1011
public const string Keyword = "fltheme";
1112

13+
private readonly Settings _settings;
1214
private readonly Theme _theme;
1315
private readonly PluginInitContext _context;
1416

17+
#region Theme Selection
18+
19+
// Theme select codes from SettingsPaneThemeViewModel.cs
20+
21+
private Theme.ThemeData _selectedTheme;
22+
private Theme.ThemeData SelectedTheme
23+
{
24+
get => _selectedTheme ??= Themes.Find(v => v.FileNameWithoutExtension == _theme.CurrentTheme);
25+
set
26+
{
27+
_selectedTheme = value;
28+
_theme.ChangeTheme(value.FileNameWithoutExtension);
29+
30+
if (_theme.BlurEnabled && _settings.UseDropShadowEffect)
31+
DropShadowEffect = false;
32+
}
33+
}
34+
35+
private List<Theme.ThemeData> Themes => _theme.LoadAvailableThemes();
36+
37+
private bool DropShadowEffect
38+
{
39+
get => _settings.UseDropShadowEffect;
40+
set
41+
{
42+
if (_theme.BlurEnabled && value)
43+
{
44+
_context.API.ShowMsgBox(_context.API.GetTranslation("shadowEffectNotAllowed"));
45+
return;
46+
}
47+
48+
if (value)
49+
{
50+
_theme.AddDropShadowEffectToCurrentTheme();
51+
}
52+
else
53+
{
54+
_theme.RemoveDropShadowEffectFromCurrentTheme();
55+
}
56+
57+
_settings.UseDropShadowEffect = value;
58+
}
59+
}
60+
61+
#endregion
62+
1563
public ThemeSelector(PluginInitContext context)
1664
{
1765
_context = context;
@@ -20,52 +68,66 @@ public ThemeSelector(PluginInitContext context)
2068

2169
public List<Result> Query(Query query)
2270
{
23-
var themes = _theme.LoadAvailableThemes().Select(x => x.FileNameWithoutExtension);
24-
25-
string search = query.SecondToEndSearch;
26-
71+
var search = query.SecondToEndSearch;
2772
if (string.IsNullOrWhiteSpace(search))
2873
{
29-
return themes.Select(CreateThemeResult)
74+
return Themes.Select(CreateThemeResult)
3075
.OrderBy(x => x.Title)
3176
.ToList();
3277
}
3378

34-
return themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme)))
79+
return Themes.Select(theme => (theme, matchResult: _context.API.FuzzySearch(search, theme.Name)))
3580
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
3681
.Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData))
3782
.OrderBy(x => x.Title)
3883
.ToList();
3984
}
4085

41-
private Result CreateThemeResult(string theme) => CreateThemeResult(theme, 0, null);
86+
private Result CreateThemeResult(Theme.ThemeData theme) => CreateThemeResult(theme, 0, null);
4287

43-
private Result CreateThemeResult(string theme, int score, IList<int> highlightData)
88+
private Result CreateThemeResult(Theme.ThemeData theme, int score, IList<int> highlightData)
4489
{
90+
string themeName = theme.Name;
4591
string title;
46-
if (theme == _theme.CurrentTheme)
92+
if (theme == SelectedTheme)
4793
{
48-
title = $"{theme} ★";
94+
title = $"{theme.Name} ★";
4995
// Set current theme to the top
5096
score = 2000;
5197
}
5298
else
5399
{
54-
title = theme;
100+
title = theme.Name;
55101
// Set them to 1000 so that they are higher than other non-theme records
56102
score = 1000;
57103
}
58104

105+
string description = string.Empty;
106+
if (theme.IsDark == true)
107+
{
108+
description += _context.API.GetTranslation("TypeIsDarkToolTip");
109+
if (theme.HasBlur == true)
110+
{
111+
description += "";
112+
description += _context.API.GetTranslation("TypeHasBlurToolTip");
113+
}
114+
}
115+
else if (theme.HasBlur == true)
116+
{
117+
description += _context.API.GetTranslation("TypeHasBlurToolTip");
118+
}
119+
59120
return new Result
60121
{
61122
Title = title,
62123
TitleHighlightData = highlightData,
124+
SubTitle = description,
63125
IcoPath = "Images\\theme_selector.png",
64126
Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue790"),
65127
Score = score,
66128
Action = c =>
67129
{
68-
_theme.ChangeTheme(theme);
130+
SelectedTheme = theme;
69131
_context.API.ReQuery();
70132
return false;
71133
}

0 commit comments

Comments
 (0)