33
44using CommunityToolkit . WinUI . Helpers ;
55using CommunityToolkit . WinUI . Notifications ;
6+ using Files . App . Helpers ;
67using Files . App . Services . DateTimeFormatter ;
78using Files . App . Services . Settings ;
89using Files . App . Storage . FtpStorage ;
2122using Microsoft . Extensions . Logging ;
2223using Microsoft . UI . Xaml ;
2324using Microsoft . UI . Xaml . Controls ;
25+ using Microsoft . UI . Xaml . Media ;
26+ using Microsoft . UI . Xaml . Media . Animation ;
2427using Microsoft . Windows . AppLifecycle ;
2528using System . IO ;
2629using System . Text ;
@@ -40,7 +43,7 @@ public partial class App : Application
4043 private static bool ShowErrorNotification = false ;
4144 public static string OutputPath { get ; set ; }
4245 public static CommandBarFlyout ? LastOpenedFlyout { get ; set ; }
43- public static TaskCompletionSource ? SplashScreenLoadingTCS { get ; set ; }
46+ public static TaskCompletionSource ? SplashScreenLoadingTCS { get ; private set ; }
4447
4548 public static StorageHistoryWrapper HistoryWrapper { get ; } = new ( ) ;
4649 public static AppModel AppModel { get ; private set ; }
@@ -176,12 +179,7 @@ await Task.WhenAll(
176179 FileTagsHelper . UpdateTagsDb ( ) ;
177180 } ) ;
178181
179- // Check for required updates
180- var updateService = Ioc . Default . GetRequiredService < IUpdateService > ( ) ;
181- await updateService . CheckForUpdates ( ) ;
182- await updateService . DownloadMandatoryUpdates ( ) ;
183- await updateService . CheckAndUpdateFilesLauncherAsync ( ) ;
184- await updateService . CheckLatestReleaseNotesAsync ( ) ;
182+ await CheckForRequiredUpdates ( ) ;
185183
186184 static async Task OptionalTask ( Task task , bool condition )
187185 {
@@ -190,6 +188,15 @@ static async Task OptionalTask(Task task, bool condition)
190188 }
191189 }
192190
191+ private static async Task CheckForRequiredUpdates ( )
192+ {
193+ var updateService = Ioc . Default . GetRequiredService < IUpdateService > ( ) ;
194+ await updateService . CheckForUpdates ( ) ;
195+ await updateService . DownloadMandatoryUpdates ( ) ;
196+ await updateService . CheckAndUpdateFilesLauncherAsync ( ) ;
197+ await updateService . CheckLatestReleaseNotesAsync ( ) ;
198+ }
199+
193200 /// <summary>
194201 /// Invoked when the application is launched normally by the end user. Other entry points
195202 /// will be used such as when the application is launched to open a specific file.
@@ -300,6 +307,43 @@ private async void Window_Closed(object sender, WindowEventArgs args)
300307 return ;
301308 }
302309
310+ if ( Ioc . Default . GetRequiredService < IUserSettingsService > ( ) . GeneralSettingsService . LeaveAppRunning &&
311+ ! Process . GetProcessesByName ( "Files" ) . Any ( x => x . Id != Process . GetCurrentProcess ( ) . Id ) )
312+ {
313+ // Close open content dialogs
314+ UIHelpers . CloseAllDialogs ( ) ;
315+
316+ // Cache the window instead of closing it
317+ MainWindow . Instance . AppWindow . Hide ( ) ;
318+ args . Handled = true ;
319+
320+ // Save and close all tabs
321+ SaveSessionTabs ( ) ;
322+ MainPageViewModel . AppInstances . ForEach ( tabItem => tabItem . Unload ( ) ) ;
323+ MainPageViewModel . AppInstances . Clear ( ) ;
324+ await Task . Delay ( 100 ) ;
325+
326+ // Wait for all properties windows to close
327+ await FilePropertiesHelpers . WaitClosingAll ( ) ;
328+
329+ // Sleep current instance
330+ Program . Pool = new ( 0 , 1 , "Files-Instance" ) ;
331+ Thread . Yield ( ) ;
332+ if ( Program . Pool . WaitOne ( ) )
333+ {
334+ // Resume the instance
335+ Program . Pool . Dispose ( ) ;
336+ MainWindow . Instance . AppWindow . Show ( ) ;
337+ MainWindow . Instance . Activate ( ) ;
338+
339+ _ = CheckForRequiredUpdates ( ) ;
340+
341+ MainWindow . Instance . EnsureWindowIsInitialized ( ) . Navigate ( typeof ( MainPage ) , null , new SuppressNavigationTransitionInfo ( ) ) ;
342+ }
343+
344+ return ;
345+ }
346+
303347 // Method can take a long time, make sure the window is hidden
304348 await Task . Yield ( ) ;
305349
0 commit comments