Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed issue where tabs weren't restored when resuming from the background #14857

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Services/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/UserControls/TabBar/BaseTabBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
15 changes: 11 additions & 4 deletions src/Files.App/ViewModels/Settings/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading