Skip to content

Commit

Permalink
Improve resilience and error display
Browse files Browse the repository at this point in the history
Attempt to handle strange Windows issues with OpenFileDialog during Welcome screen.
Added app-wide exception catcher to hopefully provide more information when unexpected things happen.
Reduced default size of main window to fit on smaller desktops and force correct ratio on first run.
Dev only: Added dev-only buttons to trigger dummy exceptions and to wipe current app settings.
  • Loading branch information
coldino committed Feb 8, 2018
1 parent bd6f3d1 commit db6ecf8
Show file tree
Hide file tree
Showing 7 changed files with 860 additions and 779 deletions.
49 changes: 48 additions & 1 deletion LarkatorGUI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Windows;
using System;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace LarkatorGUI
{
Expand All @@ -10,11 +13,55 @@ public partial class App : Application
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

#if !DEBUG
RegisterExceptionHandlers();
#endif
}

private void RegisterExceptionHandlers()
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
}

private void Application_Exit(object sender, ExitEventArgs e)
{
LarkatorGUI.Properties.Settings.Default.Save();
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
HandleUnhandledException(e.ExceptionObject as Exception);
}

private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
HandleUnhandledException(e.Exception);
}

private void HandleUnhandledException(Exception ex)
{
if (ex == null)
{
MessageBox.Show("Null Exception!");
return;
}

var sb = new StringBuilder();
sb.AppendLine("Sorry, something bad happened and the application must exit.");
sb.AppendLine();
sb.AppendLine("If you wish to report this issue please press Ctrl-C now to copy the details and");
sb.AppendLine("paste it into a new issue along with a description of what was happening");
sb.AppendLine("at: https://github.com/coldino/Larkator/issues");
sb.AppendLine("Thanks!");
sb.AppendLine();
sb.AppendLine("Exception:");
sb.AppendLine(ex.ToString());

MessageBox.Show(sb.ToString(), "Whoops...", MessageBoxButton.OK, MessageBoxImage.Error);

Environment.Exit(1);
}
}
}
10 changes: 6 additions & 4 deletions LarkatorGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
d:DataContext="{d:DesignInstance Type={x:Type local:DummyMainWindow}, IsDesignTimeCreatable=True}"
SourceInitialized="Window_SourceInitialized" Loaded="Window_Loaded"
Title="{Binding WindowTitle}" Background="{DynamicResource WindowBackgroundBrush}"
MaxHeight="1016" MinHeight="240"
MaxHeight="1016" MinHeight="500"
Left="{Binding Source={StaticResource Settings}, Path=Default.MainWindowLeft, Mode=TwoWay}"
Top="{Binding Source={StaticResource Settings}, Path=Default.MainWindowTop, Mode=TwoWay}"
Width="{Binding Source={StaticResource Settings}, Path=Default.MainWindowWidth, Mode=TwoWay}"
Expand Down Expand Up @@ -357,9 +357,11 @@
</DataGrid>

<StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<StackPanel x:Name="devButtons" Visibility="Collapsed" Orientation="Horizontal">
<fa:ImageAwesome Icon="Bug" Height="30" Width="30" Margin="8" Foreground="#88FFFF00" ToolTip="Use dummy data" MouseDown="DummyData_Click"/>
<fa:ImageAwesome Icon="crop" Height="30" Width="30" Margin="8" Foreground="#88FFFF00" ToolTip="Calibration" MouseDown="Calibration_Click"/>
<StackPanel x:Name="devButtons" Visibility="Collapsed" Orientation="Horizontal" Margin="0,0,32,0">
<fa:ImageAwesome Icon="Bug" Height="30" Width="30" Margin="8" Foreground="#88FFFF00" ToolTip="Add dummy map points" MouseDown="Dev_DummyData_Click"/>
<fa:ImageAwesome Icon="Crop" Height="30" Width="30" Margin="8" Foreground="#88FFFF00" ToolTip="Calibration" MouseDown="Dev_Calibration_Click"/>
<fa:ImageAwesome Icon="Bomb" Height="30" Width="30" Margin="8" Foreground="#88FFFF00" ToolTip="Generate exception and exit" MouseDown="Dev_GenerateException_Click"/>
<fa:ImageAwesome Icon="Remove" Height="30" Width="30" Margin="8" Foreground="#88FFFF00" ToolTip="Remove user settings &amp; exit" MouseDown="Dev_RemoveSettings_Click"/>
</StackPanel>
<fa:ImageAwesome Icon="cogs" Width="30" Height="30" Margin="8" Foreground="#44ffffff" ToolTip="Settings" MouseDown="Settings_Click"/>
</StackPanel>
Expand Down
Loading

0 comments on commit db6ecf8

Please sign in to comment.