add main thread exception handling
This commit is contained in:
parent
f6ad9c7f8a
commit
26f4e5aab8
@ -1,4 +1,5 @@
|
||||
using Avalonia;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using ReactiveUI;
|
||||
@ -36,6 +37,12 @@ public partial class App : Application
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
if (desktop.Args != null && desktop.Args.Any(x => x.ToLower() == "debug"))
|
||||
{
|
||||
System.Diagnostics.Trace.Listeners.Add(new SerilogTraceListener.SerilogTraceListener());
|
||||
Log.Debug("TraceListener is registered");
|
||||
}
|
||||
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = new MainWindowViewModel(),
|
||||
|
@ -99,8 +99,13 @@ public class InstallerUpdateInfo : ReactiveObject
|
||||
return file.FullName;
|
||||
}
|
||||
|
||||
private void EndCheck(string infoText, bool updateAvailable)
|
||||
private void EndCheck(string infoText, bool updateAvailable, bool log = true)
|
||||
{
|
||||
if (log)
|
||||
{
|
||||
Log.Information(infoText);
|
||||
}
|
||||
|
||||
UpdateInfoText = infoText;
|
||||
|
||||
if (!updateAvailable)
|
||||
@ -138,7 +143,7 @@ public class InstallerUpdateInfo : ReactiveObject
|
||||
|
||||
if (releases == null || releases.Count == 0)
|
||||
{
|
||||
EndCheck("No updates available", false);
|
||||
EndCheck("No releases available", false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -146,7 +151,7 @@ public class InstallerUpdateInfo : ReactiveObject
|
||||
|
||||
if (latest == null)
|
||||
{
|
||||
EndCheck("No updates available", false);
|
||||
EndCheck("could not get latest release", false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -168,7 +173,7 @@ public class InstallerUpdateInfo : ReactiveObject
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
EndCheck(ex.Message, false);
|
||||
EndCheck(ex.Message, false, false);
|
||||
Log.Error(ex, "Failed to check for updates");
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ using SPTInstaller.Interfaces;
|
||||
using SPTInstaller.Models;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Serilog;
|
||||
|
||||
namespace SPTInstaller;
|
||||
|
||||
@ -19,8 +20,18 @@ internal class Program
|
||||
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
|
||||
// yet and stuff might break.
|
||||
[STAThread]
|
||||
public static void Main(string[] args) => BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Installer closed unexpectedly");
|
||||
}
|
||||
}
|
||||
|
||||
// Avalonia configuration, don't remove; also used by visual designer.
|
||||
public static AppBuilder BuildAvaloniaApp()
|
||||
|
@ -41,6 +41,7 @@
|
||||
<PackageReference Include="MegaApiClient" Version="1.10.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="SerilogTraceListener" Version="3.2.0" />
|
||||
<PackageReference Include="SharpCompress" Version="0.34.0" />
|
||||
<PackageReference Include="System.Reactive" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user