From 1896b679892968f089d91025354b5484587404d6 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 15 Feb 2022 22:15:04 +1100 Subject: [PATCH] add hotkey and interface listeners logic --- Flow.Launcher.Core/Plugin/PluginManager.cs | 10 +++++++--- Flow.Launcher.Plugin/PluginMetadata.cs | 4 +++- Plugins/Flow.Launcher.Plugin.Explorer/plugin.json | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 7c0727b66..094570f08 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -26,7 +26,6 @@ namespace Flow.Launcher.Core.Plugin public static IPublicAPI API { private set; get; } - // todo happlebao, this should not be public, the indicator function should be embeded public static PluginsSettings Settings; private static List _metadatas; @@ -181,9 +180,14 @@ namespace Flow.Launcher.Core.Plugin public static async Task PublishPathSelectedFromResult(string selectedPath, string hotkey) { - await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch + await Task.WhenAll(AllPlugins.Select(pluginPair => pluginPair.Plugin switch { - IPathSelected p => p.PathSelected(selectedPath, hotkey), + IPathSelected p + when pluginPair + .Metadata + .Listeners + .Any(x => x.ContainsKey(hotkey) && x.ContainsValue("IPathSelected")) + => p.PathSelected(selectedPath, hotkey), _ => Task.CompletedTask, })); } diff --git a/Flow.Launcher.Plugin/PluginMetadata.cs b/Flow.Launcher.Plugin/PluginMetadata.cs index e8f5cf744..57bda809e 100644 --- a/Flow.Launcher.Plugin/PluginMetadata.cs +++ b/Flow.Launcher.Plugin/PluginMetadata.cs @@ -35,8 +35,10 @@ namespace Flow.Launcher.Plugin public List ActionKeywords { get; set; } + public List> Listeners { get; set;} + public string IcoPath { get; set;} - + public override string ToString() { return Name; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json index 10be3381d..76b124df3 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Explorer/plugin.json @@ -7,6 +7,7 @@ "*", "*" ], + "Listeners": [{"f1": "IPathSelected"}], "Name": "Explorer", "Description": "Search and manage files and folders. Explorer utilises Windows Index Search", "Author": "Jeremy Wu",