PluginsManager: refactor sub-commands

Rename them to something more accurate, switch them to be const
This commit is contained in:
Ioannis G 2022-01-12 23:48:16 +02:00
parent d6bca894ff
commit a0bb995643
No known key found for this signature in database
GPG key ID: EAC0E4E5E36AC49E
3 changed files with 17 additions and 20 deletions

View file

@ -50,15 +50,12 @@ namespace Flow.Launcher.Plugin.PluginsManager
if (string.IsNullOrWhiteSpace(query.Search))
return pluginManager.GetDefaultHotKeys();
return query.FirstSearch switch
return query.FirstSearch.ToLower() switch
{
//search could be url, no need ToLower() when passed in
var s when s.Equals(Settings.HotKeyInstall, StringComparison.OrdinalIgnoreCase)
=> await pluginManager.RequestInstallOrUpdate(query.SecondToEndSearch, token),
var s when s.Equals(Settings.HotkeyUninstall, StringComparison.OrdinalIgnoreCase)
=> pluginManager.RequestUninstall(query.SecondToEndSearch),
var s when s.Equals(Settings.HotkeyUpdate, StringComparison.OrdinalIgnoreCase)
=> await pluginManager.RequestUpdate(query.SecondToEndSearch, token),
Settings.InstallCommand => await pluginManager.RequestInstallOrUpdate(query.SecondToEndSearch, token),
Settings.UninstallCommand => pluginManager.RequestUninstall(query.SecondToEndSearch),
Settings.UpdateCommand => await pluginManager.RequestUpdate(query.SecondToEndSearch, token),
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
{
hotkey.Score = StringMatcher.FuzzySearch(query.Search, hotkey.Title).Score;

View file

@ -75,34 +75,34 @@ namespace Flow.Launcher.Plugin.PluginsManager
{
new Result()
{
Title = Settings.HotKeyInstall,
Title = Settings.InstallCommand,
IcoPath = icoPath,
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotKeyInstall} ",
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.InstallCommand} ",
Action = _ =>
{
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotKeyInstall} ");
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.InstallCommand} ");
return false;
}
},
new Result()
{
Title = Settings.HotkeyUninstall,
Title = Settings.UninstallCommand,
IcoPath = icoPath,
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotkeyUninstall} ",
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.UninstallCommand} ",
Action = _ =>
{
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotkeyUninstall} ");
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.UninstallCommand} ");
return false;
}
},
new Result()
{
Title = Settings.HotkeyUpdate,
Title = Settings.UpdateCommand,
IcoPath = icoPath,
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotkeyUpdate} ",
AutoCompleteText = $"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.UpdateCommand} ",
Action = _ =>
{
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.HotkeyUpdate} ");
Context.API.ChangeQuery($"{Context.CurrentPluginMetadata.ActionKeyword} {Settings.UpdateCommand} ");
return false;
}
}
@ -122,7 +122,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
Context
.API
.ChangeQuery(
$"{Context.CurrentPluginMetadata.ActionKeywords.FirstOrDefault()} {Settings.HotkeyUpdate} {plugin.Name}");
$"{Context.CurrentPluginMetadata.ActionKeywords.FirstOrDefault()} {Settings.UpdateCommand} {plugin.Name}");
var mainWindow = Application.Current.MainWindow;
mainWindow.Show();

View file

@ -6,11 +6,11 @@ namespace Flow.Launcher.Plugin.PluginsManager
{
internal class Settings
{
internal string HotKeyInstall { get; set; } = "install";
internal const string InstallCommand = "install";
internal string HotkeyUninstall { get; set; } = "uninstall";
internal const string UninstallCommand = "uninstall";
internal string HotkeyUpdate { get; set; } = "update";
internal const string UpdateCommand = "update";
public bool WarnFromUnknownSource { get; set; } = true;
}