1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-23 03:15:48 +02:00

Fix exceptions during app launch not showing error message dialogs

This commit is contained in:
chylex 2022-01-16 18:28:48 +01:00
parent e2ac38ed0b
commit d38e525fed
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
2 changed files with 30 additions and 14 deletions

View File

@ -9,11 +9,23 @@ static class FormManager {
private static FormCollection OpenForms => System.Windows.Forms.Application.OpenForms;
public static void RunOnUIThread(Action action) {
TryFind<FormBrowser>()?.InvokeSafe(action);
var form = TryFind<FormBrowser>();
if (form == null) {
action();
}
else {
form.InvokeSafe(action);
}
}
public static void RunOnUIThreadAsync(Action action) {
TryFind<FormBrowser>()?.InvokeAsyncSafe(action);
var form = TryFind<FormBrowser>();
if (form == null) {
action();
}
else {
form.InvokeAsyncSafe(action);
}
}
public static T TryFind<T>() where T : Form {

View File

@ -8,6 +8,7 @@
using TweetDuck.Browser.Adapters;
using TweetDuck.Browser.Handling;
using TweetDuck.Configuration;
using TweetDuck.Dialogs;
using TweetDuck.Management;
using TweetDuck.Updates;
using TweetDuck.Utils;
@ -64,16 +65,20 @@ private static void Main() {
})
);
Lib.AppLauncher launch = Lib.Initialize(new AppBuilder {
Setup = new Setup(),
ErrorHandler = reporter,
SystemHandler = new SystemHandler(),
MessageDialogs = new MessageDialogs(),
FileDialogs = new FileDialogs(),
});
try {
Lib.AppLauncher launch = Lib.Initialize(new AppBuilder {
Setup = new Setup(),
ErrorHandler = reporter,
SystemHandler = new SystemHandler(),
MessageDialogs = new MessageDialogs(),
FileDialogs = new FileDialogs(),
});
errorReporter = reporter;
launch();
errorReporter = reporter;
launch();
} catch (AppException e) {
FormMessage.Error(e.Title, e.Message, FormMessage.OK);
}
}
private sealed class Setup : IAppSetup {
@ -153,9 +158,8 @@ public void Launch(ResourceCache resourceCache, PluginManager pluginManager) {
private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) {
if (e.ExceptionObject is Exception ex) {
AppException appEx = ex.GetBaseException() as AppException;
string title = appEx?.Title ?? "TweetDuck Has Failed :(";
string message = appEx?.Message ?? "An unhandled exception has occurred: " + ex.Message;
const string title = "TweetDuck Has Failed :(";
string message = "An unhandled exception has occurred: " + ex.Message;
if (errorReporter == null) {
Debug.WriteLine(ex);