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:
parent
e2ac38ed0b
commit
d38e525fed
@ -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 {
|
||||
|
28
Program.cs
28
Program.cs
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user