@@ -65,17 +65,21 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
65
65
66
66
async Task ActivateAsync ( )
67
67
{
68
- // Initialize and activate MainWindow
69
- MainWindow . Instance . Activate ( ) ;
68
+ // Get AppActivationArguments
69
+ var appActivationArguments = Microsoft . Windows . AppLifecycle . AppInstance . GetCurrent ( ) . GetActivatedEventArgs ( ) ;
70
+ var isStartupTask = appActivationArguments . Data is Windows . ApplicationModel . Activation . IStartupTaskActivatedEventArgs ;
70
71
71
- // Wait for the Window to initialize
72
- await Task . Delay ( 10 ) ;
72
+ if ( ! isStartupTask )
73
+ {
74
+ // Initialize and activate MainWindow
75
+ MainWindow . Instance . Activate ( ) ;
73
76
74
- SplashScreenLoadingTCS = new TaskCompletionSource ( ) ;
75
- MainWindow . Instance . ShowSplashScreen ( ) ;
77
+ // Wait for the Window to initialize
78
+ await Task . Delay ( 10 ) ;
76
79
77
- // Get AppActivationArguments
78
- var appActivationArguments = Microsoft . Windows . AppLifecycle . AppInstance . GetCurrent ( ) . GetActivatedEventArgs ( ) ;
80
+ SplashScreenLoadingTCS = new TaskCompletionSource ( ) ;
81
+ MainWindow . Instance . ShowSplashScreen ( ) ;
82
+ }
79
83
80
84
// Start tracking app usage
81
85
if ( appActivationArguments . Data is Windows . ApplicationModel . Activation . IActivatedEventArgs activationEventArgs )
@@ -90,6 +94,21 @@ async Task ActivateAsync()
90
94
AppLifecycleHelper . ConfigureAppCenter ( ) ;
91
95
#endif
92
96
97
+ var userSettingsService = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
98
+ var isLeaveAppRunning = userSettingsService . GeneralSettingsService . LeaveAppRunning ;
99
+
100
+ if ( isStartupTask && ! isLeaveAppRunning )
101
+ {
102
+ // Initialize and activate MainWindow
103
+ MainWindow . Instance . Activate ( ) ;
104
+
105
+ // Wait for the Window to initialize
106
+ await Task . Delay ( 10 ) ;
107
+
108
+ SplashScreenLoadingTCS = new TaskCompletionSource ( ) ;
109
+ MainWindow . Instance . ShowSplashScreen ( ) ;
110
+ }
111
+
93
112
// TODO: Replace with DI
94
113
QuickAccessManager = Ioc . Default . GetRequiredService < QuickAccessManager > ( ) ;
95
114
HistoryWrapper = Ioc . Default . GetRequiredService < StorageHistoryWrapper > ( ) ;
@@ -105,15 +124,28 @@ async Task ActivateAsync()
105
124
106
125
Logger . LogInformation ( $ "App launched. Launch args type: { appActivationArguments . Data . GetType ( ) . Name } ") ;
107
126
108
- // Wait for the UI to update
109
- await SplashScreenLoadingTCS ! . Task . WithTimeoutAsync ( TimeSpan . FromMilliseconds ( 500 ) ) ;
110
- SplashScreenLoadingTCS = null ;
127
+ if ( ! ( isStartupTask && isLeaveAppRunning ) )
128
+ {
129
+ // Wait for the UI to update
130
+ await SplashScreenLoadingTCS ! . Task . WithTimeoutAsync ( TimeSpan . FromMilliseconds ( 500 ) ) ;
131
+ SplashScreenLoadingTCS = null ;
111
132
112
- // Create a system tray icon
113
- SystemTrayIcon = new SystemTrayIcon ( ) . Show ( ) ;
133
+ // Create a system tray icon
134
+ SystemTrayIcon = new SystemTrayIcon ( ) . Show ( ) ;
114
135
115
- _ = AppLifecycleHelper . InitializeAppComponentsAsync ( ) ;
116
- _ = MainWindow . Instance . InitializeApplicationAsync ( appActivationArguments . Data ) ;
136
+ _ = MainWindow . Instance . InitializeApplicationAsync ( appActivationArguments . Data ) ;
137
+ }
138
+
139
+ await AppLifecycleHelper . InitializeAppComponentsAsync ( ) ;
140
+
141
+ if ( isStartupTask && isLeaveAppRunning )
142
+ {
143
+ // Create a system tray icon when initialization is done
144
+ SystemTrayIcon = new SystemTrayIcon ( ) . Show ( ) ;
145
+ App . Current . Exit ( ) ;
146
+ }
147
+ else
148
+ await AppLifecycleHelper . CheckAppUpdate ( ) ;
117
149
}
118
150
}
119
151
@@ -122,11 +154,12 @@ async Task ActivateAsync()
122
154
/// </summary>
123
155
public async Task OnActivatedAsync ( AppActivationArguments activatedEventArgs )
124
156
{
125
- Logger . LogInformation ( $ "The app is being activated. Activation type: { activatedEventArgs . Data . GetType ( ) . Name } ") ;
157
+ var activatedEventArgsData = activatedEventArgs . Data ;
158
+ Logger . LogInformation ( $ "The app is being activated. Activation type: { activatedEventArgsData . GetType ( ) . Name } ") ;
126
159
127
160
// InitializeApplication accesses UI, needs to be called on UI thread
128
161
await MainWindow . Instance . DispatcherQueue . EnqueueOrInvokeAsync ( ( )
129
- => MainWindow . Instance . InitializeApplicationAsync ( activatedEventArgs . Data ) ) ;
162
+ => MainWindow . Instance . InitializeApplicationAsync ( activatedEventArgsData ) ) ;
130
163
}
131
164
132
165
/// <summary>
0 commit comments