3
3
4
4
using CommunityToolkit . WinUI . Helpers ;
5
5
using CommunityToolkit . WinUI . Notifications ;
6
- using Files . App . Helpers ;
7
6
using Files . App . Services . DateTimeFormatter ;
8
7
using Files . App . Services . Settings ;
9
8
using Files . App . Storage . FtpStorage ;
10
9
using Files . App . Storage . NativeStorage ;
11
- using Files . App . UserControls . TabBar ;
12
10
using Files . App . ViewModels . Settings ;
13
11
using Files . Core . Services . SizeProvider ;
14
12
using Files . Core . Storage ;
22
20
using Microsoft . Extensions . Logging ;
23
21
using Microsoft . UI . Xaml ;
24
22
using Microsoft . UI . Xaml . Controls ;
25
- using Microsoft . UI . Xaml . Media ;
26
- using Microsoft . UI . Xaml . Media . Animation ;
27
23
using Microsoft . Windows . AppLifecycle ;
28
24
using System . IO ;
29
25
using System . Text ;
@@ -230,6 +226,10 @@ async Task ActivateAsync()
230
226
231
227
EnsureSettingsAndConfigurationAreBootstrapped ( ) ;
232
228
229
+ // Hook events for the window
230
+ MainWindow . Instance . Closed += Window_Closed ;
231
+ MainWindow . Instance . Activated += Window_Activated ;
232
+
233
233
// TODO: Remove App.Logger instance and replace with DI
234
234
Logger = Ioc . Default . GetRequiredService < ILogger < App > > ( ) ;
235
235
Logger . LogInformation ( $ "App launched. Launch args type: { appActivationArguments . Data . GetType ( ) . Name } ") ;
@@ -262,10 +262,6 @@ private void EnsureSuperEarlyWindow()
262
262
// Get the MainWindow instance
263
263
var window = MainWindow . Instance ;
264
264
265
- // Hook events for the window
266
- window . Activated += Window_Activated ;
267
- window . Closed += Window_Closed ;
268
-
269
265
// Attempt to activate it
270
266
window . Activate ( ) ;
271
267
}
@@ -297,6 +293,8 @@ public void OnActivated(AppActivationArguments activatedEventArgs)
297
293
private async void Window_Closed ( object sender , WindowEventArgs args )
298
294
{
299
295
// Save application state and stop any background activity
296
+ IUserSettingsService userSettingsService = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
297
+ StatusCenterViewModel satusCenterViewModel = Ioc . Default . GetRequiredService < StatusCenterViewModel > ( ) ;
300
298
301
299
// A Workaround for the crash (#10110)
302
300
if ( LastOpenedFlyout ? . IsOpen ?? false )
@@ -307,15 +305,15 @@ private async void Window_Closed(object sender, WindowEventArgs args)
307
305
return ;
308
306
}
309
307
310
- if ( Ioc . Default . GetRequiredService < IUserSettingsService > ( ) . GeneralSettingsService . LeaveAppRunning &&
308
+ if ( userSettingsService . GeneralSettingsService . LeaveAppRunning &&
311
309
! AppModel . ForceProcessTermination &&
312
310
! Process . GetProcessesByName ( "Files" ) . Any ( x => x . Id != Process . GetCurrentProcess ( ) . Id ) )
313
311
{
314
312
// Close open content dialogs
315
313
UIHelpers . CloseAllDialogs ( ) ;
316
-
314
+
317
315
// Close all notification banners except in progress
318
- Ioc . Default . GetRequiredService < StatusCenterViewModel > ( ) . RemoveAllCompletedItems ( ) ;
316
+ satusCenterViewModel . RemoveAllCompletedItems ( ) ;
319
317
320
318
// Cache the window instead of closing it
321
319
MainWindow . Instance . AppWindow . Hide ( ) ;
0 commit comments