33
44using CommunityToolkit . WinUI . Helpers ;
55using CommunityToolkit . WinUI . Notifications ;
6- using Files . App . Helpers ;
76using Files . App . Services . DateTimeFormatter ;
87using Files . App . Services . Settings ;
98using Files . App . Storage . FtpStorage ;
109using Files . App . Storage . NativeStorage ;
11- using Files . App . UserControls . TabBar ;
1210using Files . App . ViewModels . Settings ;
1311using Files . Core . Services . SizeProvider ;
1412using Files . Core . Storage ;
2220using Microsoft . Extensions . Logging ;
2321using Microsoft . UI . Xaml ;
2422using Microsoft . UI . Xaml . Controls ;
25- using Microsoft . UI . Xaml . Media ;
26- using Microsoft . UI . Xaml . Media . Animation ;
2723using Microsoft . Windows . AppLifecycle ;
2824using System . IO ;
2925using System . Text ;
@@ -230,6 +226,10 @@ async Task ActivateAsync()
230226
231227 EnsureSettingsAndConfigurationAreBootstrapped ( ) ;
232228
229+ // Hook events for the window
230+ MainWindow . Instance . Closed += Window_Closed ;
231+ MainWindow . Instance . Activated += Window_Activated ;
232+
233233 // TODO: Remove App.Logger instance and replace with DI
234234 Logger = Ioc . Default . GetRequiredService < ILogger < App > > ( ) ;
235235 Logger . LogInformation ( $ "App launched. Launch args type: { appActivationArguments . Data . GetType ( ) . Name } ") ;
@@ -262,10 +262,6 @@ private void EnsureSuperEarlyWindow()
262262 // Get the MainWindow instance
263263 var window = MainWindow . Instance ;
264264
265- // Hook events for the window
266- window . Activated += Window_Activated ;
267- window . Closed += Window_Closed ;
268-
269265 // Attempt to activate it
270266 window . Activate ( ) ;
271267 }
@@ -297,6 +293,8 @@ public void OnActivated(AppActivationArguments activatedEventArgs)
297293 private async void Window_Closed ( object sender , WindowEventArgs args )
298294 {
299295 // Save application state and stop any background activity
296+ IUserSettingsService userSettingsService = Ioc . Default . GetRequiredService < IUserSettingsService > ( ) ;
297+ StatusCenterViewModel satusCenterViewModel = Ioc . Default . GetRequiredService < StatusCenterViewModel > ( ) ;
300298
301299 // A Workaround for the crash (#10110)
302300 if ( LastOpenedFlyout ? . IsOpen ?? false )
@@ -307,15 +305,15 @@ private async void Window_Closed(object sender, WindowEventArgs args)
307305 return ;
308306 }
309307
310- if ( Ioc . Default . GetRequiredService < IUserSettingsService > ( ) . GeneralSettingsService . LeaveAppRunning &&
308+ if ( userSettingsService . GeneralSettingsService . LeaveAppRunning &&
311309 ! AppModel . ForceProcessTermination &&
312310 ! Process . GetProcessesByName ( "Files" ) . Any ( x => x . Id != Process . GetCurrentProcess ( ) . Id ) )
313311 {
314312 // Close open content dialogs
315313 UIHelpers . CloseAllDialogs ( ) ;
316-
314+
317315 // Close all notification banners except in progress
318- Ioc . Default . GetRequiredService < StatusCenterViewModel > ( ) . RemoveAllCompletedItems ( ) ;
316+ satusCenterViewModel . RemoveAllCompletedItems ( ) ;
319317
320318 // Cache the window instead of closing it
321319 MainWindow . Instance . AppWindow . Hide ( ) ;
0 commit comments