diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index f23b529cc..fcb261f24 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -46,6 +46,7 @@ namespace Flow.Launcher.Core.Plugin private static List _metadatas; private static readonly List _modifiedPlugins = new(); + private static readonly Dictionary> _pluginHotkeyInfo = new(); private static readonly Dictionary> _windowPluginHotkeys = new(); /// @@ -263,9 +264,9 @@ namespace Flow.Launcher.Core.Plugin await Task.WhenAll(InitTasks); - var pluginHotkeyInfo = GetPluginHotkeyInfo(); - Settings.UpdatePluginHotkeyInfo(pluginHotkeyInfo); - InitializeWindowPluginHotkeys(pluginHotkeyInfo); + InitializePluginHotkeyInfo(); + Settings.UpdatePluginHotkeyInfo(GetPluginHotkeyInfo()); + InitializeWindowPluginHotkeys(); foreach (var plugin in AllPlugins) { @@ -478,14 +479,7 @@ namespace Flow.Launcher.Core.Plugin public static Dictionary> GetPluginHotkeyInfo() { - var hotkeyPluginInfos = new Dictionary>(); - foreach (var plugin in _hotkeyPlugins) - { - var hotkeys = ((IPluginHotkey)plugin.Plugin).GetPuginHotkeys(); - hotkeyPluginInfos.Add(plugin, hotkeys); - } - - return hotkeyPluginInfos; + return _pluginHotkeyInfo; } public static Dictionary> GetWindowPluginHotkeys() @@ -493,9 +487,45 @@ namespace Flow.Launcher.Core.Plugin return _windowPluginHotkeys; } - private static void InitializeWindowPluginHotkeys(Dictionary> pluginHotkeyInfo) + public static void UpdatePluginHotkeyInfoTranslations() { - foreach (var info in pluginHotkeyInfo) + foreach (var plugin in _hotkeyPlugins) + { + var newHotkeys = ((IPluginHotkey)plugin.Plugin).GetPuginHotkeys(); + if (_pluginHotkeyInfo.TryGetValue(plugin, out var oldHotkeys)) + { + foreach (var newHotkey in newHotkeys) + { + if (oldHotkeys.FirstOrDefault(h => h.Id == newHotkey.Id) is BasePluginHotkey pluginHotkey) + { + pluginHotkey.Name = newHotkey.Name; + pluginHotkey.Description = newHotkey.Description; + } + else + { + oldHotkeys.Add(newHotkey); + } + } + } + else + { + _pluginHotkeyInfo.Add(plugin, newHotkeys); + } + } + } + + private static void InitializePluginHotkeyInfo() + { + foreach (var plugin in _hotkeyPlugins) + { + var hotkeys = ((IPluginHotkey)plugin.Plugin).GetPuginHotkeys(); + _pluginHotkeyInfo.Add(plugin, hotkeys); + } + } + + private static void InitializeWindowPluginHotkeys() + { + foreach (var info in GetPluginHotkeyInfo()) { var pluginPair = info.Key; var hotkeyInfo = info.Value; diff --git a/Flow.Launcher.Core/Resource/Internationalization.cs b/Flow.Launcher.Core/Resource/Internationalization.cs index 8879e5d63..0b173b69b 100644 --- a/Flow.Launcher.Core/Resource/Internationalization.cs +++ b/Flow.Launcher.Core/Resource/Internationalization.cs @@ -278,6 +278,7 @@ namespace Flow.Launcher.Core.Resource private void UpdatePluginMetadataTranslations() { + // Update plugin metadata name & description foreach (var p in PluginManager.GetTranslationPlugins()) { if (p.Plugin is not IPluginI18n pluginI18N) return; @@ -292,6 +293,9 @@ namespace Flow.Launcher.Core.Resource API.LogException(ClassName, $"Failed for <{p.Metadata.Name}>", e); } } + + // Update plugin hotkey name & description + PluginManager.UpdatePluginHotkeyInfoTranslations(); } private static string LanguageFile(string folder, string language)