Check result null & Improve docuements

This commit is contained in:
Jack251970 2025-06-26 10:37:18 +08:00
parent c7de03bbec
commit b52c7e756c
2 changed files with 21 additions and 8 deletions

View file

@ -91,7 +91,7 @@ public class SearchWindowPluginHotkey : BasePluginHotkey
}
/// <summary>
/// An action that will be executed when the hotkey is triggered.
/// An action that will be executed when the hotkey is triggered and a result is selected.
/// </summary>
public Func<Result, bool> Action { get; set; } = null;
}

View file

@ -256,15 +256,28 @@ internal static class HotKeyMapper
existingCommand.Execute(null);
}
foreach (var hotkeyModel in hotkeyModels)
var selectedResult = _mainViewModel.Results.SelectedItem?.Result;
// Check result nullability
if (selectedResult != null)
{
var metadata = hotkeyModel.Metadata;
if (metadata.Disabled)
continue;
var pluginId = selectedResult.PluginID;
foreach (var hotkeyModel in hotkeyModels)
{
var metadata = hotkeyModel.Metadata;
var pluginHotkey = hotkeyModel.PluginHotkey;
var pluginHotkey = hotkeyModel.PluginHotkey;
if (pluginHotkey.Action?.Invoke(_mainViewModel.Results.SelectedItem?.Result) ?? false)
App.API.HideMainWindow();
// Check plugin ID match
if (metadata.ID != pluginId)
continue;
// Check plugin enabled state
if (metadata.Disabled)
continue;
// Invoke action
if (pluginHotkey.Action?.Invoke(selectedResult) ?? false)
App.API.HideMainWindow();
}
}
});
}