mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-01 08:34:11 +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;
|
private static FormCollection OpenForms => System.Windows.Forms.Application.OpenForms;
|
||||||
|
|
||||||
public static void RunOnUIThread(Action action) {
|
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) {
|
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 {
|
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.Adapters;
|
||||||
using TweetDuck.Browser.Handling;
|
using TweetDuck.Browser.Handling;
|
||||||
using TweetDuck.Configuration;
|
using TweetDuck.Configuration;
|
||||||
|
using TweetDuck.Dialogs;
|
||||||
using TweetDuck.Management;
|
using TweetDuck.Management;
|
||||||
using TweetDuck.Updates;
|
using TweetDuck.Updates;
|
||||||
using TweetDuck.Utils;
|
using TweetDuck.Utils;
|
||||||
@ -64,16 +65,20 @@ private static void Main() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
Lib.AppLauncher launch = Lib.Initialize(new AppBuilder {
|
try {
|
||||||
Setup = new Setup(),
|
Lib.AppLauncher launch = Lib.Initialize(new AppBuilder {
|
||||||
ErrorHandler = reporter,
|
Setup = new Setup(),
|
||||||
SystemHandler = new SystemHandler(),
|
ErrorHandler = reporter,
|
||||||
MessageDialogs = new MessageDialogs(),
|
SystemHandler = new SystemHandler(),
|
||||||
FileDialogs = new FileDialogs(),
|
MessageDialogs = new MessageDialogs(),
|
||||||
});
|
FileDialogs = new FileDialogs(),
|
||||||
|
});
|
||||||
|
|
||||||
errorReporter = reporter;
|
errorReporter = reporter;
|
||||||
launch();
|
launch();
|
||||||
|
} catch (AppException e) {
|
||||||
|
FormMessage.Error(e.Title, e.Message, FormMessage.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class Setup : IAppSetup {
|
private sealed class Setup : IAppSetup {
|
||||||
@ -153,9 +158,8 @@ public void Launch(ResourceCache resourceCache, PluginManager pluginManager) {
|
|||||||
|
|
||||||
private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) {
|
private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) {
|
||||||
if (e.ExceptionObject is Exception ex) {
|
if (e.ExceptionObject is Exception ex) {
|
||||||
AppException appEx = ex.GetBaseException() as AppException;
|
const string title = "TweetDuck Has Failed :(";
|
||||||
string title = appEx?.Title ?? "TweetDuck Has Failed :(";
|
string message = "An unhandled exception has occurred: " + ex.Message;
|
||||||
string message = appEx?.Message ?? "An unhandled exception has occurred: " + ex.Message;
|
|
||||||
|
|
||||||
if (errorReporter == null) {
|
if (errorReporter == null) {
|
||||||
Debug.WriteLine(ex);
|
Debug.WriteLine(ex);
|
||||||
|
Loading…
Reference in New Issue
Block a user