2025-04-04 07:37:03 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-12-27 13:13:25 +00:00
|
|
|
|
using System.Linq;
|
2020-12-06 10:10:22 +00:00
|
|
|
|
using System.Windows.Controls;
|
2020-12-28 15:06:47 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2021-01-02 14:21:45 +00:00
|
|
|
|
using System.Threading;
|
2025-04-04 07:37:03 +00:00
|
|
|
|
using Flow.Launcher.Plugin.PluginsManager.ViewModels;
|
|
|
|
|
|
using Flow.Launcher.Plugin.PluginsManager.Views;
|
2020-12-06 08:58:27 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Flow.Launcher.Plugin.PluginsManager
|
|
|
|
|
|
{
|
2022-01-12 17:25:42 +00:00
|
|
|
|
public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n
|
2020-12-06 08:58:27 +00:00
|
|
|
|
{
|
2025-04-04 07:37:03 +00:00
|
|
|
|
internal static PluginInitContext Context { get; set; }
|
2020-12-06 10:10:22 +00:00
|
|
|
|
|
|
|
|
|
|
internal Settings Settings;
|
|
|
|
|
|
|
|
|
|
|
|
private SettingsViewModel viewModel;
|
|
|
|
|
|
|
|
|
|
|
|
private IContextMenu contextMenu;
|
|
|
|
|
|
|
2020-12-27 13:13:25 +00:00
|
|
|
|
internal PluginsManager pluginManager;
|
|
|
|
|
|
|
2020-12-06 10:10:22 +00:00
|
|
|
|
public Control CreateSettingPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new PluginsManagerSettings(viewModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-12 17:22:55 +00:00
|
|
|
|
public async Task InitAsync(PluginInitContext context)
|
2020-12-06 10:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
|
Context = context;
|
2021-05-13 11:29:21 +00:00
|
|
|
|
Settings = context.API.LoadSettingJsonStorage<Settings>();
|
2021-05-11 12:18:57 +00:00
|
|
|
|
viewModel = new SettingsViewModel(context, Settings);
|
2020-12-29 07:13:52 +00:00
|
|
|
|
contextMenu = new ContextMenu(Context);
|
2020-12-27 13:13:25 +00:00
|
|
|
|
pluginManager = new PluginsManager(Context, Settings);
|
2021-01-20 10:00:16 +00:00
|
|
|
|
|
2025-04-04 08:05:33 +00:00
|
|
|
|
await Context.API.UpdatePluginManifestAsync();
|
2020-12-06 10:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Result> LoadContextMenus(Result selectedResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
return contextMenu.LoadContextMenus(selectedResult);
|
|
|
|
|
|
}
|
2021-12-19 17:35:34 +00:00
|
|
|
|
|
2021-01-02 14:21:45 +00:00
|
|
|
|
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
|
2020-12-06 10:10:22 +00:00
|
|
|
|
{
|
2022-01-11 06:55:59 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(query.Search))
|
2020-12-29 04:23:15 +00:00
|
|
|
|
return pluginManager.GetDefaultHotKeys();
|
2020-12-06 20:40:42 +00:00
|
|
|
|
|
2022-01-12 21:48:16 +00:00
|
|
|
|
return query.FirstSearch.ToLower() switch
|
2020-12-27 13:13:25 +00:00
|
|
|
|
{
|
2021-11-21 05:09:49 +00:00
|
|
|
|
//search could be url, no need ToLower() when passed in
|
2025-01-04 13:55:44 +00:00
|
|
|
|
Settings.InstallCommand => await pluginManager.RequestInstallOrUpdateAsync(query.SecondToEndSearch, token, query.IsReQuery),
|
2022-01-12 21:48:16 +00:00
|
|
|
|
Settings.UninstallCommand => pluginManager.RequestUninstall(query.SecondToEndSearch),
|
2023-07-05 14:01:12 +00:00
|
|
|
|
Settings.UpdateCommand => await pluginManager.RequestUpdateAsync(query.SecondToEndSearch, token, query.IsReQuery),
|
2020-12-29 04:23:15 +00:00
|
|
|
|
_ => pluginManager.GetDefaultHotKeys().Where(hotkey =>
|
2020-12-27 13:13:25 +00:00
|
|
|
|
{
|
2025-04-04 07:37:03 +00:00
|
|
|
|
hotkey.Score = Context.API.FuzzySearch(query.Search, hotkey.Title).Score;
|
2020-12-27 13:13:25 +00:00
|
|
|
|
return hotkey.Score > 0;
|
|
|
|
|
|
}).ToList()
|
|
|
|
|
|
};
|
2020-12-06 10:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetTranslatedPluginTitle()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.API.GetTranslation("plugin_pluginsmanager_plugin_name");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetTranslatedPluginDescription()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Context.API.GetTranslation("plugin_pluginsmanager_plugin_description");
|
|
|
|
|
|
}
|
2020-12-06 08:58:27 +00:00
|
|
|
|
}
|
2022-11-02 09:45:38 +00:00
|
|
|
|
}
|