From 522ff153bedfd4c26ffddf7f42264dd118ffcbe1 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 16 Oct 2025 22:36:51 +0800 Subject: [PATCH] Refactor hotkey initialization logic Simplify hotkey initialization by using the null-coalescing assignment operator (`??=`) to ensure `metadata.PluginHotkeys` is initialized to an empty collection if null. Add a call to `Clear()` to reset the collection before reuse. Replace `List()` with shorthand `[]` syntax for creating empty collections, improving code readability and consistency. --- Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs index f4d55060f..736654d06 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs @@ -100,12 +100,14 @@ namespace Flow.Launcher.Infrastructure.UserSettings var pluginPair = info.Key; var hotkeyInfo = info.Value; var metadata = pluginPair.Metadata; + metadata.PluginHotkeys ??= []; + metadata.PluginHotkeys.Clear(); if (Plugins.TryGetValue(pluginPair.Metadata.ID, out var plugin)) { if (plugin.pluginHotkeys == null || plugin.pluginHotkeys.Count == 0) { // If plugin hotkeys does not exist, create a new one and initialize with default values - plugin.pluginHotkeys = new List(); + plugin.pluginHotkeys = []; foreach (var hotkey in hotkeyInfo) { plugin.pluginHotkeys.Add(new PluginHotkey