Skip to content

Commit 2a52c28

Browse files
committed
Store plugin hotkey info
1 parent 089c0fd commit 2a52c28

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static class PluginManager
4646
private static List<PluginMetadata> _metadatas;
4747
private static readonly List<string> _modifiedPlugins = new();
4848

49+
private static readonly Dictionary<PluginPair, List<BasePluginHotkey>> _pluginHotkeyInfo = new();
4950
private static readonly Dictionary<HotkeyModel, List<(PluginMetadata, SearchWindowPluginHotkey)>> _windowPluginHotkeys = new();
5051

5152
/// <summary>
@@ -263,9 +264,9 @@ public static async Task InitializePluginsAsync()
263264

264265
await Task.WhenAll(InitTasks);
265266

266-
var pluginHotkeyInfo = GetPluginHotkeyInfo();
267-
Settings.UpdatePluginHotkeyInfo(pluginHotkeyInfo);
268-
InitializeWindowPluginHotkeys(pluginHotkeyInfo);
267+
InitializePluginHotkeyInfo();
268+
Settings.UpdatePluginHotkeyInfo(GetPluginHotkeyInfo());
269+
InitializeWindowPluginHotkeys();
269270

270271
foreach (var plugin in AllPlugins)
271272
{
@@ -478,24 +479,53 @@ public static IList<PluginPair> GetTranslationPlugins()
478479

479480
public static Dictionary<PluginPair, List<BasePluginHotkey>> GetPluginHotkeyInfo()
480481
{
481-
var hotkeyPluginInfos = new Dictionary<PluginPair, List<BasePluginHotkey>>();
482+
return _pluginHotkeyInfo;
483+
}
484+
485+
public static Dictionary<HotkeyModel, List<(PluginMetadata Metadata, SearchWindowPluginHotkey SearchWindowPluginHotkey)>> GetWindowPluginHotkeys()
486+
{
487+
return _windowPluginHotkeys;
488+
}
489+
490+
public static void UpdatePluginHotkeyInfoTranslations()
491+
{
482492
foreach (var plugin in _hotkeyPlugins)
483493
{
484-
var hotkeys = ((IPluginHotkey)plugin.Plugin).GetPuginHotkeys();
485-
hotkeyPluginInfos.Add(plugin, hotkeys);
494+
var newHotkeys = ((IPluginHotkey)plugin.Plugin).GetPuginHotkeys();
495+
if (_pluginHotkeyInfo.TryGetValue(plugin, out var oldHotkeys))
496+
{
497+
foreach (var newHotkey in newHotkeys)
498+
{
499+
if (oldHotkeys.FirstOrDefault(h => h.Id == newHotkey.Id) is BasePluginHotkey pluginHotkey)
500+
{
501+
pluginHotkey.Name = newHotkey.Name;
502+
pluginHotkey.Description = newHotkey.Description;
503+
}
504+
else
505+
{
506+
oldHotkeys.Add(newHotkey);
507+
}
508+
}
509+
}
510+
else
511+
{
512+
_pluginHotkeyInfo.Add(plugin, newHotkeys);
513+
}
486514
}
487-
488-
return hotkeyPluginInfos;
489515
}
490516

491-
public static Dictionary<HotkeyModel, List<(PluginMetadata Metadata, SearchWindowPluginHotkey SearchWindowPluginHotkey)>> GetWindowPluginHotkeys()
517+
private static void InitializePluginHotkeyInfo()
492518
{
493-
return _windowPluginHotkeys;
519+
foreach (var plugin in _hotkeyPlugins)
520+
{
521+
var hotkeys = ((IPluginHotkey)plugin.Plugin).GetPuginHotkeys();
522+
_pluginHotkeyInfo.Add(plugin, hotkeys);
523+
}
494524
}
495525

496-
private static void InitializeWindowPluginHotkeys(Dictionary<PluginPair, List<BasePluginHotkey>> pluginHotkeyInfo)
526+
private static void InitializeWindowPluginHotkeys()
497527
{
498-
foreach (var info in pluginHotkeyInfo)
528+
foreach (var info in GetPluginHotkeyInfo())
499529
{
500530
var pluginPair = info.Key;
501531
var hotkeyInfo = info.Value;

Flow.Launcher.Core/Resource/Internationalization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ public static string GetTranslation(string key)
278278

279279
private void UpdatePluginMetadataTranslations()
280280
{
281+
// Update plugin metadata name & description
281282
foreach (var p in PluginManager.GetTranslationPlugins())
282283
{
283284
if (p.Plugin is not IPluginI18n pluginI18N) return;
@@ -292,6 +293,9 @@ private void UpdatePluginMetadataTranslations()
292293
API.LogException(ClassName, $"Failed for <{p.Metadata.Name}>", e);
293294
}
294295
}
296+
297+
// Update plugin hotkey name & description
298+
PluginManager.UpdatePluginHotkeyInfoTranslations();
295299
}
296300

297301
private static string LanguageFile(string folder, string language)

0 commit comments

Comments
 (0)