Skip to content

Commit a0bb995

Browse files
committed
PluginsManager: refactor sub-commands
Rename them to something more accurate, switch them to be const
1 parent d6bca89 commit a0bb995

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,12 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
5050
if (string.IsNullOrWhiteSpace(query.Search))
5151
return pluginManager.GetDefaultHotKeys();
5252

53-
return query.FirstSearch switch
53+
return query.FirstSearch.ToLower() switch
5454
{
5555
//search could be url, no need ToLower() when passed in
56-
var s when s.Equals(Settings.HotKeyInstall, StringComparison.OrdinalIgnoreCase)
57-
=> await pluginManager.RequestInstallOrUpdate(query.SecondToEndSearch, token),
58-
var s when s.Equals(Settings.HotkeyUninstall, StringComparison.OrdinalIgnoreCase)
59-
=> pluginManager.RequestUninstall(query.SecondToEndSearch),
60-
var s when s.Equals(Settings.HotkeyUpdate, StringComparison.OrdinalIgnoreCase)
61-
=> await pluginManager.RequestUpdate(query.SecondToEndSearch, token),
56+
Settings.InstallCommand => await pluginManager.RequestInstallOrUpdate(query.SecondToEndSearch, token),
57+
Settings.UninstallCommand => pluginManager.RequestUninstall(query.SecondToEndSearch),
58+
Settings.UpdateCommand => await pluginManager.RequestUpdate(query.SecondToEndSearch, token),
6259
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
6360
{
6461
hotkey.Score = StringMatcher.FuzzySearch(query.Search, hotkey.Title).Score;

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,34 @@ internal List<Result> GetDefaultHotKeys()
7575
{
7676
new Result()
7777
{
78-
Title = Settings.HotKeyInstall,
78+
Title = Settings.InstallCommand,
7979
IcoPath = icoPath,
80-
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotKeyInstall} ",
80+
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.InstallCommand} ",
8181
Action = _ =>
8282
{
83-
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotKeyInstall} ");
83+
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.InstallCommand} ");
8484
return false;
8585
}
8686
},
8787
new Result()
8888
{
89-
Title = Settings.HotkeyUninstall,
89+
Title = Settings.UninstallCommand,
9090
IcoPath = icoPath,
91-
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotkeyUninstall} ",
91+
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.UninstallCommand} ",
9292
Action = _ =>
9393
{
94-
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotkeyUninstall} ");
94+
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.UninstallCommand} ");
9595
return false;
9696
}
9797
},
9898
new Result()
9999
{
100-
Title = Settings.HotkeyUpdate,
100+
Title = Settings.UpdateCommand,
101101
IcoPath = icoPath,
102-
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotkeyUpdate} ",
102+
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.UpdateCommand} ",
103103
Action = _ =>
104104
{
105-
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotkeyUpdate} ");
105+
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.UpdateCommand} ");
106106
return false;
107107
}
108108
}
@@ -122,7 +122,7 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
122122
Context
123123
.API
124124
.ChangeQuery(
125-
$"{Context.CurrentPluginMetadata.ActionKeywords.FirstOrDefault()} {Settings.HotkeyUpdate} {plugin.Name}");
125+
$"{Context.CurrentPluginMetadata.ActionKeywords.FirstOrDefault()} {Settings.UpdateCommand} {plugin.Name}");
126126

127127
var mainWindow = Application.Current.MainWindow;
128128
mainWindow.Show();

Plugins/Flow.Launcher.Plugin.PluginsManager/Settings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ namespace Flow.Launcher.Plugin.PluginsManager
66
{
77
internal class Settings
88
{
9-
internal string HotKeyInstall { get; set; } = "install";
9+
internal const string InstallCommand = "install";
1010

11-
internal string HotkeyUninstall { get; set; } = "uninstall";
11+
internal const string UninstallCommand = "uninstall";
1212

13-
internal string HotkeyUpdate { get; set; } = "update";
13+
internal const string UpdateCommand = "update";
1414

1515
public bool WarnFromUnknownSource { get; set; } = true;
1616
}

0 commit comments

Comments
 (0)