Skip to content

Commit 3e8f60f

Browse files
authored
Fix: Fixed issue where tabs weren't restored when resuming from the background (#14857)
1 parent 63364ea commit 3e8f60f

File tree

7 files changed

+25
-5
lines changed

7 files changed

+25
-5
lines changed

src/Files.App/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ private async void Window_Closed(object sender, WindowEventArgs args)
208208
return;
209209
}
210210

211+
// Save the current tab list in case it was overwriten by another instance
211212
AppLifecycleHelper.SaveSessionTabs();
212213

213214
// Continue running the app on the background

src/Files.App/Data/Contexts/Multitasking/MultitaskingContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public MultitaskingContext()
3939
private void AppInstances_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
4040
{
4141
UpdateTabCount();
42-
AppLifecycleHelper.SaveSessionTabs();
4342
}
4443
private void AppModel_PropertyChanged(object? sender, PropertyChangedEventArgs e)
4544
{

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ public static void HandleAppUnhandledException(Exception? ex, bool showToastNoti
282282
// Please check "Output Window" for exception details (View -> Output Window) (CTRL + ALT + O)
283283
Debugger.Break();
284284

285+
// Save the current tab list in case it was overwriten by another instance
285286
SaveSessionTabs();
286287
App.Logger.LogError(ex, ex?.Message ?? "An unhandled error occurred.");
287288

src/Files.App/Helpers/Navigation/NavigationHelpers.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public static async Task AddNewTabByPathAsync(Type type, string? path, int atInd
6161
MainPageViewModel.AppInstances.Insert(index, tabItem);
6262

6363
App.AppModel.TabStripSelectedIndex = index;
64+
65+
// Save the updated tab list
66+
AppLifecycleHelper.SaveSessionTabs();
6467
}
6568

6669
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
8689
var index = atIndex == -1 ? MainPageViewModel.AppInstances.Count : atIndex;
8790
MainPageViewModel.AppInstances.Insert(index, tabItem);
8891
App.AppModel.TabStripSelectedIndex = index;
92+
93+
// Save the updated tab list
94+
AppLifecycleHelper.SaveSessionTabs();
8995
}
9096

9197
private static async Task UpdateTabInfoAsync(TabBarItem tabItem, object navigationArg)

src/Files.App/Services/UpdateService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ public async Task CheckForUpdatesAsync()
109109

110110
private async Task DownloadAndInstallAsync()
111111
{
112+
// Save the updated tab list before installing the update
112113
AppLifecycleHelper.SaveSessionTabs();
114+
113115
App.AppModel.ForceProcessTermination = true;
116+
114117
var downloadOperation = _storeContext?.RequestDownloadAndInstallStorePackageUpdatesAsync(_updatePackages);
115118
var result = await downloadOperation.AsTask();
116119

src/Files.App/UserControls/TabBar/BaseTabBar.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ public void CloseTab(TabBarItem tabItem)
147147
tabItem.NavigationParameter,
148148
});
149149

150+
// Save the updated tab list
151+
AppLifecycleHelper.SaveSessionTabs();
152+
150153
if (Items.Count == 0)
151154
MainWindow.Instance.Close();
152155
}

src/Files.App/ViewModels/Settings/GeneralViewModel.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,17 @@ public GeneralViewModel()
114114

115115
private async void DoRestartAsync()
116116
{
117-
UserSettingsService.AppSettingsService.RestoreTabsOnStartup = true; // Tells the app to restore tabs when it's next launched
118-
AppLifecycleHelper.SaveSessionTabs(); // Saves the open tabs
119-
await Launcher.LaunchUriAsync(new Uri("files-uwp:")); // Launches a new instance of Files
120-
Process.GetCurrentProcess().Kill(); // Closes the current instance
117+
// Tells the app to restore tabs when it's next launched
118+
UserSettingsService.AppSettingsService.RestoreTabsOnStartup = true;
119+
120+
// Save the updated tab list before restarting
121+
AppLifecycleHelper.SaveSessionTabs();
122+
123+
// Launches a new instance of Files
124+
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));
125+
126+
// Closes the current instance
127+
Process.GetCurrentProcess().Kill();
121128
}
122129

123130
private void DoCancelRestart()

0 commit comments

Comments
 (0)