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

92 lines
3.1 KiB
C#
Raw Normal View History

using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Plugin.Explorer.Helper;
2020-05-19 12:38:42 +00:00
using Flow.Launcher.Plugin.Explorer.Search;
using Flow.Launcher.Plugin.Explorer.Search.Everything;
2021-01-26 20:42:43 +00:00
using Flow.Launcher.Plugin.Explorer.Search.QuickAccessLinks;
using Flow.Launcher.Plugin.Explorer.ViewModels;
using Flow.Launcher.Plugin.Explorer.Views;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
2021-01-02 14:01:15 +00:00
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace Flow.Launcher.Plugin.Explorer
{
public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n
{
internal static PluginInitContext Context { get; set; }
internal Settings Settings;
private SettingsViewModel viewModel;
private IContextMenu contextMenu;
2020-05-25 08:58:04 +00:00
2021-01-02 14:01:15 +00:00
private SearchManager searchManager;
public Control CreateSettingPanel()
{
return new ExplorerSettings(viewModel);
}
public Task InitAsync(PluginInitContext context)
{
Context = context;
2022-08-17 01:32:49 +00:00
Settings = context.API.LoadSettingJsonStorage<Settings>();
viewModel = new SettingsViewModel(context, Settings);
2022-08-17 01:32:49 +00:00
// as at v1.7.0 this is to maintain backwards compatibility, need to be removed afterwards.
if (Settings.QuickFolderAccessLinks.Any())
2021-01-26 19:17:24 +00:00
{
Settings.QuickAccessLinks = Settings.QuickFolderAccessLinks;
Settings.QuickFolderAccessLinks = new();
2021-01-26 19:17:24 +00:00
}
2021-01-26 10:14:39 +00:00
contextMenu = new ContextMenu(Context, Settings, viewModel);
2021-01-02 14:01:15 +00:00
searchManager = new SearchManager(Settings, Context);
2021-07-02 03:38:07 +00:00
ResultManager.Init(Context, Settings);
2022-08-17 01:32:49 +00:00
if (Settings.EverythingEnabled)
{
_ = EverythingDownloadHelper.PromptDownloadIfNotInstallAsync(Settings.EverythingInstalledPath, context.API)
.ContinueWith(s =>
{
if (s.IsCompletedSuccessfully)
Settings.EverythingInstalledPath = s.Result;
}, TaskScheduler.Default);
}
SortOptionTranslationHelper.API = context.API;
2022-08-17 01:32:49 +00:00
EverythingApiDllImport.Load(Path.Combine(Context.CurrentPluginMetadata.PluginDirectory, "EverythingSDK",
Environment.Is64BitProcess ? "Everything64.dll" : "Everything86.dll"));
return Task.CompletedTask;
}
public List<Result> LoadContextMenus(Result selectedResult)
{
return contextMenu.LoadContextMenus(selectedResult);
}
2021-01-02 14:01:15 +00:00
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
{
2021-01-02 14:01:15 +00:00
return await searchManager.SearchAsync(query, token);
}
2020-06-08 10:31:48 +00:00
public string GetTranslatedPluginTitle()
{
return Context.API.GetTranslation("plugin_explorer_plugin_name");
}
public string GetTranslatedPluginDescription()
{
return Context.API.GetTranslation("plugin_explorer_plugin_description");
}
}
2022-08-17 01:32:49 +00:00
}