1- using Avalonia ;
21using Avalonia . Controls . ApplicationLifetimes ;
32using Avalonia . Markup . Xaml ;
3+ using Garyon . Objects ;
44using Microsoft . CodeAnalysis ;
55using Serilog ;
66using Serilog . Events ;
7+ using Syndiesis . Updating ;
78using Syndiesis . Utilities ;
89using Syndiesis . Views ;
9- using System ;
1010using System . Reflection ;
1111
1212namespace Syndiesis ;
@@ -38,6 +38,11 @@ public static AppResourceManager CurrentResourceManager
3838
3939 public override void Initialize ( )
4040 {
41+ // Force initialize app settings on the UI thread to avoid troubles
42+ // with extra invocation handling when initializing instances from
43+ // de-/serializations or first-time accesses. Deadlocks are very
44+ // common to encounter when incorrectly using UI thread dispatches
45+ _ = AppSettings . Instance ;
4146 AvaloniaXamlLoader . Load ( this ) ;
4247 ResourceManager = new ( this ) ;
4348 AppInfo = CreateAppInfo ( ) ;
@@ -64,40 +69,46 @@ private static InformationalVersion InformationalVersionForAssembly(Assembly ass
6469 private static void SetupGeneral ( )
6570 {
6671 SetupSerilog ( ) ;
67- AppSettings . TryLoad ( ) ;
72+ Task . Run ( SetupGeneralAsync ) ;
73+ }
74+
75+ private static async Task SetupGeneralAsync ( )
76+ {
77+ await AppSettings . TryLoad ( ) ;
78+ await CheckUpdates ( ) ;
6879 }
6980
7081 public override void OnFrameworkInitializationCompleted ( )
7182 {
7283 if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
7384 {
74- SetupDesktop ( desktop ) ;
85+ SetupDesktopLifetime ( desktop ) ;
7586 }
7687
7788 if ( ApplicationLifetime is ISingleViewApplicationLifetime single )
7889 {
79- SetupSingleView ( single ) ;
90+ SetupSingleViewLifetime ( single ) ;
8091 }
8192
8293 if ( ApplicationLifetime is IControlledApplicationLifetime controlled )
8394 {
84- SetupControlled ( controlled ) ;
95+ SetupControlledLifetime ( controlled ) ;
8596 }
8697
8798 base . OnFrameworkInitializationCompleted ( ) ;
8899 }
89100
90- private void SetupDesktop ( IClassicDesktopStyleApplicationLifetime desktop )
101+ private void SetupDesktopLifetime ( IClassicDesktopStyleApplicationLifetime desktop )
91102 {
92103 desktop . MainWindow = new MainWindow ( ) ;
93104 }
94105
95- private void SetupSingleView ( ISingleViewApplicationLifetime single )
106+ private void SetupSingleViewLifetime ( ISingleViewApplicationLifetime single )
96107 {
97108 single . MainView = new MainView ( ) ;
98109 }
99110
100- private void SetupControlled ( IControlledApplicationLifetime controlled )
111+ private void SetupControlledLifetime ( IControlledApplicationLifetime controlled )
101112 {
102113 SetupSerilog ( controlled ) ;
103114 controlled . Exit += HandleControlledLifetimeExit ;
@@ -106,7 +117,7 @@ private void SetupControlled(IControlledApplicationLifetime controlled)
106117 private void HandleControlledLifetimeExit (
107118 object ? sender , ControlledApplicationLifetimeExitEventArgs e )
108119 {
109- AppSettings . TrySave ( ) ;
120+ Task . Run ( ( ) => AppSettings . TrySave ( ) ) ;
110121 }
111122
112123 private void SetupSerilog ( IControlledApplicationLifetime lifetime )
@@ -134,4 +145,12 @@ private static void LogApplicationExit(object? sender, EventArgs e)
134145 {
135146 LoggerExtensionsEx . LogMethodInvocation ( nameof ( LogApplicationExit ) ) ;
136147 }
148+
149+ private static async Task CheckUpdates ( )
150+ {
151+ if ( AppSettings . Instance . UpdateOptions . AutoCheckUpdates )
152+ {
153+ await Singleton < UpdateManager > . Instance . CheckForUpdates ( ) ;
154+ }
155+ }
137156}
0 commit comments