mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
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<PluginHotkey>()` with shorthand `[]` syntax for creating empty collections, improving code readability and consistency.
This commit is contained in:
parent
f8e588b4e1
commit
522ff153be
1 changed files with 3 additions and 1 deletions
|
|
@ -100,12 +100,14 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
||||||
var pluginPair = info.Key;
|
var pluginPair = info.Key;
|
||||||
var hotkeyInfo = info.Value;
|
var hotkeyInfo = info.Value;
|
||||||
var metadata = pluginPair.Metadata;
|
var metadata = pluginPair.Metadata;
|
||||||
|
metadata.PluginHotkeys ??= [];
|
||||||
|
metadata.PluginHotkeys.Clear();
|
||||||
if (Plugins.TryGetValue(pluginPair.Metadata.ID, out var plugin))
|
if (Plugins.TryGetValue(pluginPair.Metadata.ID, out var plugin))
|
||||||
{
|
{
|
||||||
if (plugin.pluginHotkeys == null || plugin.pluginHotkeys.Count == 0)
|
if (plugin.pluginHotkeys == null || plugin.pluginHotkeys.Count == 0)
|
||||||
{
|
{
|
||||||
// If plugin hotkeys does not exist, create a new one and initialize with default values
|
// If plugin hotkeys does not exist, create a new one and initialize with default values
|
||||||
plugin.pluginHotkeys = new List<PluginHotkey>();
|
plugin.pluginHotkeys = [];
|
||||||
foreach (var hotkey in hotkeyInfo)
|
foreach (var hotkey in hotkeyInfo)
|
||||||
{
|
{
|
||||||
plugin.pluginHotkeys.Add(new PluginHotkey
|
plugin.pluginHotkeys.Add(new PluginHotkey
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue