Skip to content

Commit 34f5192

Browse files
committed
1. Move PluginsManager constuction to Init().
2. Return HotKeys list when query is like "pm *"
1 parent 431584e commit 34f5192

File tree

4 files changed

+209
-139
lines changed

4 files changed

+209
-139
lines changed

Flow.Launcher.Infrastructure/Http/Http.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static async Task<string> Get([NotNull] string url, string encoding = "UT
5959
Log.Debug($"|Http.Get|Url <{url}>");
6060
var request = WebRequest.CreateHttp(url);
6161
request.Method = "GET";
62-
request.Timeout = 1000;
62+
request.Timeout = 6000;
6363
request.Proxy = WebProxy();
6464
request.UserAgent = UserAgent;
6565
var response = await request.GetResponseAsync() as HttpWebResponse;

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@
33
using Flow.Launcher.Plugin.PluginsManager.ViewModels;
44
using Flow.Launcher.Plugin.PluginsManager.Views;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using System.Windows.Controls;
8+
using Flow.Launcher.Infrastructure;
79

810
namespace Flow.Launcher.Plugin.PluginsManager
911
{
1012
public class Main : ISettingProvider, IPlugin, ISavable, IContextMenu, IPluginI18n
1113
{
12-
internal PluginInitContext Context { get; set; }
14+
internal static PluginInitContext Context { get; set; }
1315

1416
internal Settings Settings;
1517

1618
private SettingsViewModel viewModel;
1719

1820
private IContextMenu contextMenu;
1921

22+
internal PluginsManager pluginManager;
23+
2024
public Control CreateSettingPanel()
2125
{
2226
return new PluginsManagerSettings(viewModel);
@@ -28,6 +32,7 @@ public void Init(PluginInitContext context)
2832
viewModel = new SettingsViewModel(context);
2933
Settings = viewModel.Settings;
3034
contextMenu = new ContextMenu(Context, Settings);
35+
pluginManager = new PluginsManager(Context, Settings);
3136
}
3237

3338
public List<Result> LoadContextMenus(Result selectedResult)
@@ -38,18 +43,21 @@ public List<Result> LoadContextMenus(Result selectedResult)
3843
public List<Result> Query(Query query)
3944
{
4045
var search = query.Search.ToLower();
46+
47+
if (string.IsNullOrWhiteSpace(search))
48+
return Settings.HotKeys;
4149

42-
var pluginManager = new PluginsManager(Context, Settings);
43-
44-
if (!string.IsNullOrEmpty(search)
45-
&& ($"{Settings.HotkeyUninstall} ".StartsWith(search) || search.StartsWith($"{Settings.HotkeyUninstall} ")))
46-
return pluginManager.RequestUninstall(search);
47-
48-
if (!string.IsNullOrEmpty(search)
49-
&& ($"{Settings.HotkeyUpdate} ".StartsWith(search) || search.StartsWith($"{Settings.HotkeyUpdate} ")))
50-
return pluginManager.RequestUpdate(search);
51-
52-
return pluginManager.RequestInstallOrUpdate(search);
50+
return search switch
51+
{
52+
var s when s.StartsWith(Settings.HotKeyInstall) => pluginManager.RequestInstallOrUpdate(s),
53+
var s when s.StartsWith(Settings.HotkeyUninstall) => pluginManager.RequestUninstall(s),
54+
var s when s.StartsWith(Settings.HotkeyUpdate) => pluginManager.RequestUpdate(s),
55+
_ => Settings.HotKeys.Where(hotkey =>
56+
{
57+
hotkey.Score = StringMatcher.FuzzySearch(search, hotkey.Title).Score;
58+
return hotkey.Score > 0;
59+
}).ToList()
60+
};
5361
}
5462

5563
public void Save()
@@ -67,4 +75,4 @@ public string GetTranslatedPluginDescription()
6775
return Context.API.GetTranslation("plugin_pluginsmanager_plugin_description");
6876
}
6977
}
70-
}
78+
}

0 commit comments

Comments
 (0)