mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
UI - Improved exception dialog shown at early startup failure
Plugins - Provide a better error message on built in plugin installation failure Conditions - Added better null/not null checks for strings
This commit is contained in:
parent
c66c21152f
commit
992657b0c5
@ -0,0 +1,13 @@
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class StringNotNullConditionOperator : ConditionOperator<string>
|
||||
{
|
||||
public override string Description => "Is not null";
|
||||
public override string Icon => "CheckboxMarkedCircleOutline";
|
||||
|
||||
public override bool Evaluate(string a)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class StringNullConditionOperator : ConditionOperator<string>
|
||||
{
|
||||
public override string Description => "Is null";
|
||||
public override string Icon => "Null";
|
||||
|
||||
public override bool Evaluate(string a)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,11 +98,19 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
PluginInfo pluginInfo;
|
||||
try
|
||||
{
|
||||
// Compare versions, copy if the same when debugging
|
||||
PluginInfo pluginInfo = CoreJson.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile))!;
|
||||
pluginInfo = CoreJson.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile))!;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ArtemisPluginException($"Failed read plugin metadata needed to install built-in plugin: {e.Message}", e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (builtInPluginInfo.Version > pluginInfo.Version)
|
||||
{
|
||||
_logger.Debug("Copying updated built-in plugin from {pluginInfo} to {builtInPluginInfo}", pluginInfo, builtInPluginInfo);
|
||||
@ -111,7 +119,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ArtemisPluginException("Failed read plugin metadata needed to install built-in plugin", e);
|
||||
throw new ArtemisPluginException($"Failed to install built-in plugin: {e.Message}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,6 +61,8 @@ namespace Artemis.Core.Services
|
||||
RegisterConditionOperator(Constants.CorePlugin, new StringStartsWithConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePlugin, new StringEndsWithConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePlugin, new StringMatchesRegexConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePlugin, new StringNullConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePlugin, new StringNotNullConditionOperator());
|
||||
|
||||
// Null checks, at the bottom
|
||||
// TODO: Implement a priority mechanism
|
||||
|
||||
@ -4,13 +4,16 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Screens;
|
||||
using Artemis.UI.Utilities;
|
||||
using Ninject;
|
||||
using Ookii.Dialogs.Wpf;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI
|
||||
@ -127,5 +130,48 @@ namespace Artemis.UI
|
||||
|
||||
Execute.OnUIThread(() => Application.Current.Shutdown());
|
||||
}
|
||||
|
||||
public void DisplayException(Exception e)
|
||||
{
|
||||
using TaskDialog dialog = new();
|
||||
AssemblyInformationalVersionAttribute versionAttribute = typeof(ApplicationStateManager).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
dialog.WindowTitle = $"Artemis {versionAttribute?.InformationalVersion} build {Constants.BuildInfo.BuildNumberDisplay}";
|
||||
dialog.MainInstruction = "Unfortunately Artemis ran into an unhandled exception and cannot continue.";
|
||||
dialog.Content = e.Message;
|
||||
dialog.ExpandedInformation = e.StackTrace.Trim();
|
||||
|
||||
dialog.CollapsedControlText = "Show stack trace";
|
||||
dialog.ExpandedControlText = "Hide stack trace";
|
||||
|
||||
dialog.Footer = "If this keeps happening check out the <a href=\"https://wiki.artemis-rgb.com\">wiki</a> or hit us up on <a href=\"https://discord.gg/S3MVaC9\">Discord</a>.";
|
||||
dialog.FooterIcon = TaskDialogIcon.Error;
|
||||
dialog.EnableHyperlinks = true;
|
||||
dialog.HyperlinkClicked += OpenHyperlink;
|
||||
|
||||
TaskDialogButton copyButton = new("Copy stack trace");
|
||||
TaskDialogButton closeButton = new("Close") {Default = true};
|
||||
dialog.Buttons.Add(copyButton);
|
||||
dialog.Buttons.Add(closeButton);
|
||||
dialog.ButtonClicked += (_, args) =>
|
||||
{
|
||||
if (args.Item == copyButton)
|
||||
{
|
||||
Clipboard.SetText(e.ToString());
|
||||
args.Cancel = true;
|
||||
}
|
||||
};
|
||||
|
||||
dialog.ShowDialog(Application.Current.MainWindow);
|
||||
}
|
||||
|
||||
private void OpenHyperlink(object sender, HyperlinkClickedEventArgs e)
|
||||
{
|
||||
ProcessStartInfo processInfo = new()
|
||||
{
|
||||
FileName = e.Href,
|
||||
UseShellExecute = true
|
||||
};
|
||||
Process.Start(processInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,7 +48,14 @@ namespace Artemis.UI
|
||||
return;
|
||||
}
|
||||
|
||||
try { DPIAwareness.Initalize(); } catch (Exception ex) { logger.Error($"Failed to set DPI-Awareness: {ex.Message}"); }
|
||||
try
|
||||
{
|
||||
DPIAwareness.Initalize();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error($"Failed to set DPI-Awareness: {ex.Message}");
|
||||
}
|
||||
|
||||
IViewManager viewManager = Kernel.Get<IViewManager>();
|
||||
StartupArguments = Args.ToList();
|
||||
@ -71,7 +78,7 @@ namespace Artemis.UI
|
||||
Execute.OnUIThreadSync(() =>
|
||||
{
|
||||
UIElement view = viewManager.CreateAndBindViewForModelIfNecessary(RootViewModel);
|
||||
((TrayViewModel)RootViewModel).SetTaskbarIcon(view);
|
||||
((TrayViewModel) RootViewModel).SetTaskbarIcon(view);
|
||||
});
|
||||
|
||||
// Initialize the core async so the UI can show the progress
|
||||
@ -136,15 +143,9 @@ namespace Artemis.UI
|
||||
private void HandleFatalException(Exception e, ILogger logger)
|
||||
{
|
||||
logger.Fatal(e, "Fatal exception during initialization, shutting down.");
|
||||
|
||||
// Can't use a pretty exception dialog here since the UI might not even be visible
|
||||
Execute.OnUIThread(() =>
|
||||
{
|
||||
Kernel.Get<IWindowManager>().ShowMessageBox(e.Message + "\n\n Please refer the log file for more details.",
|
||||
"Fatal exception during initialization",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error
|
||||
);
|
||||
_applicationStateManager.DisplayException(e);
|
||||
Environment.Exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user