Skip to content

Commit

Permalink
Catch menu action invoking
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Sep 3, 2023
1 parent 7618026 commit 35cb2e4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/NxEditor/Generators/MenuFactory.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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}");
}
});

Expand Down

0 comments on commit 35cb2e4

Please sign in to comment.