Skip to content

Commit 49a71d7

Browse files
committed
Move Theme Selector into Sys plugin
1 parent 5e69bd7 commit 49a71d7

File tree

7 files changed

+45
-62
lines changed

7 files changed

+45
-62
lines changed

Plugins/Flow.Launcher.Plugin.FlowThemeSelector/Flow.Launcher.Plugin.FlowThemeSelector.csproj

Lines changed: 0 additions & 37 deletions
This file was deleted.

Plugins/Flow.Launcher.Plugin.FlowThemeSelector/plugin.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

Plugins/Flow.Launcher.Plugin.Sys/Flow.Launcher.Plugin.Sys.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<ItemGroup>
3939
<ProjectReference Include="..\..\Flow.Launcher.Infrastructure\Flow.Launcher.Infrastructure.csproj" />
4040
<ProjectReference Include="..\..\Flow.Launcher.Plugin\Flow.Launcher.Plugin.csproj" />
41+
<ProjectReference Include="..\..\Flow.Launcher.Core\Flow.Launcher.Core.csproj" />
4142
</ItemGroup>
4243

4344
<ItemGroup>

Plugins/Flow.Launcher.Plugin.Sys/Languages/en.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<system:String x:Key="flowlauncher_plugin_sys_open_docs_tips_cmd">Flow Launcher Tips</system:String>
2828
<system:String x:Key="flowlauncher_plugin_sys_open_userdata_location_cmd">Flow Launcher UserData Folder</system:String>
2929
<system:String x:Key="flowlauncher_plugin_sys_toggle_game_mode_cmd">Toggle Game Mode</system:String>
30+
<system:String x:Key="flowlauncher_plugin_sys_theme_selector_cmd">Set the Flow Launcher Theme</system:String>
3031

3132
<!-- Command Descriptions -->
3233
<system:String x:Key="flowlauncher_plugin_sys_shutdown_computer">Shutdown Computer</system:String>
@@ -49,8 +50,9 @@
4950
<system:String x:Key="flowlauncher_plugin_sys_open_docs_tips">Visit Flow Launcher's documentation for more help and how to use tips</system:String>
5051
<system:String x:Key="flowlauncher_plugin_sys_open_userdata_location">Open the location where Flow Launcher's settings are stored</system:String>
5152
<system:String x:Key="flowlauncher_plugin_sys_toggle_game_mode">Toggle Game Mode</system:String>
53+
<system:String x:Key="flowlauncher_plugin_sys_theme_selector">Quickly change the Flow Launcher theme</system:String>
5254

53-
<!-- Dialogs -->
55+
<!-- Dialogs -->
5456
<system:String x:Key="flowlauncher_plugin_sys_dlgtitle_success">Success</system:String>
5557
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_all_settings_saved">All Flow Launcher settings saved</system:String>
5658
<system:String x:Key="flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded">Reloaded all applicable plugin data</system:String>

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818

1919
namespace Flow.Launcher.Plugin.Sys
2020
{
21-
public class Main : IPlugin, ISettingProvider, IPluginI18n
21+
public class Main : IPlugin, ISettingProvider, IPluginI18n, IDisposable
2222
{
2323
private PluginInitContext context;
24+
private ThemeSelector themeSelector;
2425
private Dictionary<string, string> KeywordTitleMappings = new Dictionary<string, string>();
2526

2627
#region DllImport
@@ -58,6 +59,11 @@ public Control CreateSettingPanel()
5859

5960
public List<Result> Query(Query query)
6061
{
62+
if(query.Search.StartsWith(ThemeSelector.Keyword))
63+
{
64+
return themeSelector.Query(query);
65+
}
66+
6167
var commands = Commands();
6268
var results = new List<Result>();
6369
foreach (var c in commands)
@@ -106,6 +112,7 @@ private string GetDynamicTitle(Query query, Result result)
106112
public void Init(PluginInitContext context)
107113
{
108114
this.context = context;
115+
themeSelector = new ThemeSelector(context);
109116
KeywordTitleMappings = new Dictionary<string, string>{
110117
{"Shutdown", "flowlauncher_plugin_sys_shutdown_computer_cmd"},
111118
{"Restart", "flowlauncher_plugin_sys_restart_computer_cmd"},
@@ -126,7 +133,8 @@ public void Init(PluginInitContext context)
126133
{"Open Log Location", "flowlauncher_plugin_sys_open_log_location_cmd"},
127134
{"Flow Launcher Tips", "flowlauncher_plugin_sys_open_docs_tips_cmd"},
128135
{"Flow Launcher UserData Folder", "flowlauncher_plugin_sys_open_userdata_location_cmd"},
129-
{"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"}
136+
{"Toggle Game Mode", "flowlauncher_plugin_sys_toggle_game_mode_cmd"},
137+
{"Set Flow Launcher Theme", "flowlauncher_plugin_sys_theme_selector_cmd"}
130138
};
131139
}
132140

@@ -426,6 +434,18 @@ private List<Result> Commands()
426434
context.API.ToggleGameMode();
427435
return true;
428436
}
437+
},
438+
new Result
439+
{
440+
Title = "Set Flow Launcher Theme",
441+
SubTitle = context.API.GetTranslation("flowlauncher_plugin_sys_theme_selector"),
442+
IcoPath = "Images\\theme_selector.png",
443+
Glyph = new GlyphInfo("/Resources/#Segoe Fluent Icons", "\ue790"),
444+
Action = c =>
445+
{
446+
context.API.ChangeQuery($"{ThemeSelector.Keyword} ");
447+
return false;
448+
}
429449
}
430450
});
431451

@@ -441,5 +461,10 @@ public string GetTranslatedPluginDescription()
441461
{
442462
return context.API.GetTranslation("flowlauncher_plugin_sys_plugin_description");
443463
}
464+
465+
public void Dispose()
466+
{
467+
themeSelector.Dispose();
468+
}
444469
}
445470
}

Plugins/Flow.Launcher.Plugin.FlowThemeSelector/Main.cs renamed to Plugins/Flow.Launcher.Plugin.Sys/ThemeSelector.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
using System.Linq;
55
using Flow.Launcher.Core.Resource;
66

7-
namespace Flow.Launcher.Plugin.FlowThemeSelector
7+
namespace Flow.Launcher.Plugin.Sys
88
{
9-
public class FlowThemeSelector : IPlugin, IReloadable, IDisposable
9+
public class ThemeSelector : IReloadable, IDisposable
1010
{
11-
private PluginInitContext context;
11+
public const string Keyword = "fltheme";
12+
13+
private readonly PluginInitContext context;
1214
private IEnumerable<string> themes;
1315

14-
public void Init(PluginInitContext context)
16+
public ThemeSelector(PluginInitContext context)
1517
{
1618
this.context = context;
1719
context.API.VisibilityChanged += OnVisibilityChanged;
@@ -24,14 +26,16 @@ public List<Result> Query(Query query)
2426
LoadThemes();
2527
}
2628

27-
if (string.IsNullOrWhiteSpace(query.Search))
29+
string search = query.Search[(query.Search.IndexOf(Keyword, StringComparison.Ordinal) + Keyword.Length + 1)..];
30+
31+
if (string.IsNullOrWhiteSpace(search))
2832
{
2933
return themes.Select(CreateThemeResult)
3034
.OrderBy(x => x.Title)
3135
.ToList();
3236
}
3337

34-
return themes.Select(theme => (theme, matchResult: context.API.FuzzySearch(query.Search, theme)))
38+
return themes.Select(theme => (theme, matchResult: context.API.FuzzySearch(search, theme)))
3539
.Where(x => x.matchResult.IsSearchPrecisionScoreMet())
3640
.Select(x => CreateThemeResult(x.theme, x.matchResult.Score, x.matchResult.MatchData))
3741
.OrderBy(x => x.Title)
@@ -46,11 +50,12 @@ private void OnVisibilityChanged(object sender, VisibilityChangedEventArgs args)
4650
}
4751
}
4852

49-
public void LoadThemes() => themes = ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension);
53+
private void LoadThemes()
54+
=> themes = ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension);
5055

51-
public static Result CreateThemeResult(string theme) => CreateThemeResult(theme, 0, null);
56+
private static Result CreateThemeResult(string theme) => CreateThemeResult(theme, 0, null);
5257

53-
public static Result CreateThemeResult(string theme, int score, IList<int> highlightData)
58+
private static Result CreateThemeResult(string theme, int score, IList<int> highlightData)
5459
{
5560
string title;
5661
if (theme == ThemeManager.Instance.Settings.Theme)
@@ -86,6 +91,5 @@ public void Dispose()
8691
context.API.VisibilityChanged -= OnVisibilityChanged;
8792
}
8893
}
89-
9094
}
9195
}

0 commit comments

Comments
 (0)