diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 72d167733717..4cc6852dec46 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -208,6 +208,7 @@ private async void Window_Closed(object sender, WindowEventArgs args) return; } + // Save the current tab list in case it was overwriten by another instance AppLifecycleHelper.SaveSessionTabs(); // Continue running the app on the background diff --git a/src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs b/src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs index a52788abc020..c470e4b9d76f 100644 --- a/src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs +++ b/src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs @@ -39,7 +39,6 @@ public MultitaskingContext() private void AppInstances_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { UpdateTabCount(); - AppLifecycleHelper.SaveSessionTabs(); } private void AppModel_PropertyChanged(object? sender, PropertyChangedEventArgs e) { diff --git a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs index 5f3c11307bb7..dd28c04e0e3c 100644 --- a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs +++ b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs @@ -282,6 +282,7 @@ public static void HandleAppUnhandledException(Exception? ex, bool showToastNoti // Please check "Output Window" for exception details (View -> Output Window) (CTRL + ALT + O) Debugger.Break(); + // Save the current tab list in case it was overwriten by another instance SaveSessionTabs(); App.Logger.LogError(ex, ex?.Message ?? "An unhandled error occurred."); diff --git a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs index 4be5c67f0a3a..3a0744631321 100644 --- a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs +++ b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs @@ -61,6 +61,9 @@ public static async Task AddNewTabByPathAsync(Type type, string? path, int atInd MainPageViewModel.AppInstances.Insert(index, tabItem); App.AppModel.TabStripSelectedIndex = index; + + // Save the updated tab list + AppLifecycleHelper.SaveSessionTabs(); } public static async Task AddNewTabByParamAsync(Type type, object tabViewItemArgs, int atIndex = -1) @@ -86,6 +89,9 @@ public static async Task AddNewTabByParamAsync(Type type, object tabViewItemArgs var index = atIndex == -1 ? MainPageViewModel.AppInstances.Count : atIndex; MainPageViewModel.AppInstances.Insert(index, tabItem); App.AppModel.TabStripSelectedIndex = index; + + // Save the updated tab list + AppLifecycleHelper.SaveSessionTabs(); } private static async Task UpdateTabInfoAsync(TabBarItem tabItem, object navigationArg) diff --git a/src/Files.App/Services/UpdateService.cs b/src/Files.App/Services/UpdateService.cs index 9b1fa8868419..d8265c7eee1d 100644 --- a/src/Files.App/Services/UpdateService.cs +++ b/src/Files.App/Services/UpdateService.cs @@ -109,8 +109,11 @@ public async Task CheckForUpdatesAsync() private async Task DownloadAndInstallAsync() { + // Save the updated tab list before installing the update AppLifecycleHelper.SaveSessionTabs(); + App.AppModel.ForceProcessTermination = true; + var downloadOperation = _storeContext?.RequestDownloadAndInstallStorePackageUpdatesAsync(_updatePackages); var result = await downloadOperation.AsTask(); diff --git a/src/Files.App/UserControls/TabBar/BaseTabBar.cs b/src/Files.App/UserControls/TabBar/BaseTabBar.cs index 812ae830d438..ad334c852a9c 100644 --- a/src/Files.App/UserControls/TabBar/BaseTabBar.cs +++ b/src/Files.App/UserControls/TabBar/BaseTabBar.cs @@ -147,6 +147,9 @@ public void CloseTab(TabBarItem tabItem) tabItem.NavigationParameter, }); + // Save the updated tab list + AppLifecycleHelper.SaveSessionTabs(); + if (Items.Count == 0) MainWindow.Instance.Close(); } diff --git a/src/Files.App/ViewModels/Settings/GeneralViewModel.cs b/src/Files.App/ViewModels/Settings/GeneralViewModel.cs index 159123e84a29..74709a660be8 100644 --- a/src/Files.App/ViewModels/Settings/GeneralViewModel.cs +++ b/src/Files.App/ViewModels/Settings/GeneralViewModel.cs @@ -114,10 +114,17 @@ public GeneralViewModel() private async void DoRestartAsync() { - UserSettingsService.AppSettingsService.RestoreTabsOnStartup = true; // Tells the app to restore tabs when it's next launched - AppLifecycleHelper.SaveSessionTabs(); // Saves the open tabs - await Launcher.LaunchUriAsync(new Uri("files-uwp:")); // Launches a new instance of Files - Process.GetCurrentProcess().Kill(); // Closes the current instance + // Tells the app to restore tabs when it's next launched + UserSettingsService.AppSettingsService.RestoreTabsOnStartup = true; + + // Save the updated tab list before restarting + AppLifecycleHelper.SaveSessionTabs(); + + // Launches a new instance of Files + await Launcher.LaunchUriAsync(new Uri("files-uwp:")); + + // Closes the current instance + Process.GetCurrentProcess().Kill(); } private void DoCancelRestart()