@@ -22,13 +22,14 @@ public static Microsoft.Maui.Hosting.MauiApp CreateMauiApp()
2222 {
2323 Console . Write ( RuntimeInformation . RuntimeIdentifier ) ;
2424 return CreateMauiAppInternal ( ) ;
25- } catch ( Exception e )
25+ }
26+ catch ( Exception e )
2627 {
2728 Console . WriteLine ( e ) ;
2829 throw ;
2930 }
3031 }
31-
32+
3233 private static Microsoft . Maui . Hosting . MauiApp CreateMauiAppInternal ( )
3334 {
3435 var builder = Microsoft . Maui . Hosting . MauiApp . CreateBuilder ( ) ;
@@ -49,14 +50,27 @@ private static Microsoft.Maui.Hosting.MauiApp CreateMauiAppInternal()
4950 windowsLifecycleBuilder . OnWindowCreated ( window =>
5051 {
5152 var appWindow = WindowUtils . GetAppWindow ( window ) ;
53+
54+ // On first launch, hide the window if the user has chosen to start minimized
55+ if ( _config ? . App . MinimizeOnLaunch ?? false )
56+ {
57+ void HideOnFirstLaunch ( object ? sender , Microsoft . UI . Xaml . WindowActivatedEventArgs args )
58+ {
59+ appWindow . Hide ( ) ;
60+
61+ window . Activated -= HideOnFirstLaunch ;
62+ }
63+
64+ window . Activated += HideOnFirstLaunch ;
65+ }
5266
5367 _pipeServerService ? . OnMessageReceived . SubscribeAsync ( _ =>
5468 {
5569 appWindow . ShowOnTop ( ) ;
5670
5771 return Task . CompletedTask ;
5872 } ) . AsTask ( ) . Wait ( ) ;
59-
73+
6074 //When user execute the closing method, we can push a display alert. If user click Yes, close this application, if click the cancel, display alert will dismiss.
6175 appWindow . Closing += async ( s , e ) =>
6276 {
@@ -71,9 +85,9 @@ private static Microsoft.Maui.Hosting.MauiApp CreateMauiAppInternal()
7185 if ( Application . Current == null ) return ;
7286
7387 var page = Application . Current . Windows [ 0 ] . Page ;
74-
75- if ( page == null ) return ;
76-
88+
89+ if ( page == null ) return ;
90+
7791 var result = await page . DisplayAlert (
7892 "Close?" ,
7993 "Do you want to close OpenShock?" ,
@@ -96,7 +110,7 @@ private static Microsoft.Maui.Hosting.MauiApp CreateMauiAppInternal()
96110
97111 _config = app . Services . GetRequiredService < ConfigManager > ( ) . Config ;
98112 _pipeServerService = app . Services . GetRequiredService < PipeServerService > ( ) ;
99-
113+
100114 app . Services . StartOpenShockDesktopServices ( false ) ;
101115
102116 return app ;
0 commit comments