From 35cb2e4b708d660e740d5b025f047620fef49495 Mon Sep 17 00:00:00 2001 From: ArchLeaders Date: Sat, 2 Sep 2023 19:32:01 -0700 Subject: [PATCH] Catch menu action invoking --- src/NxEditor/Generators/MenuFactory.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/NxEditor/Generators/MenuFactory.cs b/src/NxEditor/Generators/MenuFactory.cs index c91812d..56dc7f4 100644 --- a/src/NxEditor/Generators/MenuFactory.cs +++ b/src/NxEditor/Generators/MenuFactory.cs @@ -1,9 +1,11 @@ using Avalonia.Controls; using Avalonia.Input; using CommunityToolkit.Mvvm.Input; +using NxEditor.PluginBase; using NxEditor.PluginBase.Attributes; using System.Collections; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; @@ -109,8 +111,14 @@ private void AppendItem(Type type, object source, MethodInfo info, MenuAttribute } item.Command = new AsyncRelayCommand(async () => { - if (info.Invoke(source, null) is Task task) { - await task; + try { + if (info.Invoke(source, null) is Task task) { + await task; + } + } + catch (Exception ex) { + StatusModal.Set($"Failed to execute action: {attribute.Name}", "fa-regular fa-circle-xmark", isWorkingStatus: false, temporaryStatusTime: 3); + Trace.WriteLine($"{ex} - {ex.Message}"); } });