diff --git a/Management/FormManager.cs b/Management/FormManager.cs index 98ef0f69..3e927548 100644 --- a/Management/FormManager.cs +++ b/Management/FormManager.cs @@ -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 { diff --git a/Program.cs b/Program.cs index cb68c0e5..eb686edd 100644 --- a/Program.cs +++ b/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);