2025-07-21 02:29:14 +00:00
|
|
|
|
using Flow.Launcher.Plugin.Explorer.Helper;
|
2020-05-19 12:38:42 +00:00
|
|
|
|
using Flow.Launcher.Plugin.Explorer.Search;
|
2022-03-25 21:19:00 +00:00
|
|
|
|
using Flow.Launcher.Plugin.Explorer.Search.Everything;
|
2020-05-11 13:15:15 +00:00
|
|
|
|
using Flow.Launcher.Plugin.Explorer.ViewModels;
|
|
|
|
|
|
using Flow.Launcher.Plugin.Explorer.Views;
|
2022-03-25 21:19:00 +00:00
|
|
|
|
using System;
|
2020-05-11 13:15:15 +00:00
|
|
|
|
using System.Collections.Generic;
|
2022-03-25 21:19:00 +00:00
|
|
|
|
using System.IO;
|
2021-01-02 14:01:15 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2020-05-11 13:15:15 +00:00
|
|
|
|
using System.Windows.Controls;
|
2022-09-22 00:18:20 +00:00
|
|
|
|
using Flow.Launcher.Plugin.Explorer.Exceptions;
|
2025-07-20 11:11:09 +00:00
|
|
|
|
using System.Linq;
|
2025-07-21 02:29:14 +00:00
|
|
|
|
using System.Globalization;
|
2020-05-11 13:15:15 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Flow.Launcher.Plugin.Explorer
|
|
|
|
|
|
{
|
2025-07-20 11:11:09 +00:00
|
|
|
|
public class Main : ISettingProvider, IAsyncPlugin, IContextMenu, IPluginI18n, IAsyncDialogJump
|
2020-05-11 13:15:15 +00:00
|
|
|
|
{
|
2022-07-04 00:50:02 +00:00
|
|
|
|
internal static PluginInitContext Context { get; set; }
|
2020-05-11 13:15:15 +00:00
|
|
|
|
|
2025-06-28 03:00:56 +00:00
|
|
|
|
internal static Settings Settings { get; set; }
|
2020-05-11 13:15:15 +00:00
|
|
|
|
|
2020-06-08 04:20:22 +00:00
|
|
|
|
private SettingsViewModel viewModel;
|
2020-05-11 13:15:15 +00:00
|
|
|
|
|
2025-07-22 16:03:48 +00:00
|
|
|
|
private ContextMenu contextMenu;
|
2020-05-25 08:58:04 +00:00
|
|
|
|
|
2021-01-02 14:01:15 +00:00
|
|
|
|
private SearchManager searchManager;
|
|
|
|
|
|
|
2025-07-20 11:11:09 +00:00
|
|
|
|
private static readonly List<DialogJumpResult> _emptyDialogJumpResultList = new();
|
|
|
|
|
|
|
2020-05-11 13:15:15 +00:00
|
|
|
|
public Control CreateSettingPanel()
|
|
|
|
|
|
{
|
2020-06-08 04:20:22 +00:00
|
|
|
|
return new ExplorerSettings(viewModel);
|
2020-05-11 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-22 09:23:25 +00:00
|
|
|
|
public Task InitAsync(PluginInitContext context)
|
2020-05-11 13:15:15 +00:00
|
|
|
|
{
|
|
|
|
|
|
Context = context;
|
2022-08-17 01:32:49 +00:00
|
|
|
|
|
2021-05-13 11:29:21 +00:00
|
|
|
|
Settings = context.API.LoadSettingJsonStorage<Settings>();
|
2025-06-07 05:54:15 +00:00
|
|
|
|
FillQuickAccessLinkNames();
|
|
|
|
|
|
|
2021-05-11 12:18:57 +00:00
|
|
|
|
viewModel = new SettingsViewModel(context, Settings);
|
2025-07-17 16:15:46 +00:00
|
|
|
|
contextMenu = new ContextMenu(Context, Settings);
|
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
|
|
|
|
|
2022-03-25 21:19:00 +00:00
|
|
|
|
EverythingApiDllImport.Load(Path.Combine(Context.CurrentPluginMetadata.PluginDirectory, "EverythingSDK",
|
2022-11-04 05:58:07 +00:00
|
|
|
|
Environment.Is64BitProcess ? "x64" : "x86"));
|
2021-05-22 09:23:25 +00:00
|
|
|
|
return Task.CompletedTask;
|
2020-05-11 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Result> LoadContextMenus(Result selectedResult)
|
|
|
|
|
|
{
|
2020-06-08 04:20:22 +00:00
|
|
|
|
return contextMenu.LoadContextMenus(selectedResult);
|
2020-05-11 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-02 14:01:15 +00:00
|
|
|
|
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
|
2020-05-11 13:15:15 +00:00
|
|
|
|
{
|
2022-09-22 00:18:20 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return await searchManager.SearchAsync(query, token);
|
|
|
|
|
|
}
|
2022-11-25 19:25:12 +00:00
|
|
|
|
catch (Exception e) when (e is SearchException or EngineNotAvailableException)
|
2022-09-22 00:18:20 +00:00
|
|
|
|
{
|
|
|
|
|
|
return new List<Result>
|
|
|
|
|
|
{
|
|
|
|
|
|
new()
|
|
|
|
|
|
{
|
|
|
|
|
|
Title = e.Message,
|
2022-11-25 19:25:12 +00:00
|
|
|
|
SubTitle = e is EngineNotAvailableException { Resolution: { } resolution }
|
|
|
|
|
|
? resolution
|
2022-09-22 00:18:20 +00:00
|
|
|
|
: "Enter to copy the message to clipboard",
|
|
|
|
|
|
Score = 501,
|
2022-11-25 19:25:12 +00:00
|
|
|
|
IcoPath = e is EngineNotAvailableException { ErrorIcon: { } iconPath }
|
|
|
|
|
|
? iconPath
|
|
|
|
|
|
: Constants.GeneralSearchErrorImagePath,
|
|
|
|
|
|
AsyncAction = e is EngineNotAvailableException {Action: { } action}
|
|
|
|
|
|
? action
|
|
|
|
|
|
: _ =>
|
|
|
|
|
|
{
|
2023-06-09 09:59:49 +00:00
|
|
|
|
Context.API.CopyToClipboard(e.ToString());
|
2022-11-25 19:25:12 +00:00
|
|
|
|
return new ValueTask<bool>(true);
|
|
|
|
|
|
}
|
2022-09-22 00:18:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2020-05-11 13:15:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-08 10:31:48 +00:00
|
|
|
|
public string GetTranslatedPluginTitle()
|
|
|
|
|
|
{
|
2025-09-21 03:50:51 +00:00
|
|
|
|
return Localize.plugin_explorer_plugin_name();
|
2020-06-08 10:31:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetTranslatedPluginDescription()
|
|
|
|
|
|
{
|
2025-09-21 03:50:51 +00:00
|
|
|
|
return Localize.plugin_explorer_plugin_description();
|
2020-06-08 10:31:48 +00:00
|
|
|
|
}
|
2025-05-25 17:45:44 +00:00
|
|
|
|
|
2025-07-21 02:29:14 +00:00
|
|
|
|
public void OnCultureInfoChanged(CultureInfo newCulture)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Update labels for setting view model
|
|
|
|
|
|
EverythingSortOptionLocalized.UpdateLabels(viewModel.AllEverythingSortOptions);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-08 01:45:54 +00:00
|
|
|
|
private static void FillQuickAccessLinkNames()
|
2025-05-25 17:45:44 +00:00
|
|
|
|
{
|
2025-06-07 05:54:15 +00:00
|
|
|
|
// Legacy version does not have names for quick access links, so we fill them with the path name.
|
2025-05-25 17:45:44 +00:00
|
|
|
|
foreach (var link in Settings.QuickAccessLinks)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(link.Name))
|
|
|
|
|
|
{
|
|
|
|
|
|
link.Name = link.Path.GetPathName();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-20 11:11:09 +00:00
|
|
|
|
|
|
|
|
|
|
public async Task<List<DialogJumpResult>> QueryDialogJumpAsync(Query query, CancellationToken token)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var results = await searchManager.SearchAsync(query, token);
|
|
|
|
|
|
return results.Select(r => DialogJumpResult.From(r, r.CopyText)).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e) when (e is SearchException or EngineNotAvailableException)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _emptyDialogJumpResultList;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-05-11 13:15:15 +00:00
|
|
|
|
}
|
2022-09-22 00:18:20 +00:00
|
|
|
|
}
|