Files
Files copied to clipboard
Feature: Added support for restoring tabs after restarting Windows
Resolved / Related Issues
- [x] Were these changes approved in an issue or discussion with the project maintainers? In order to prevent extra work, feature requests and changes to the codebase must be approved before the pull request will be reviewed. This prevents extra work for the contributors and maintainers. Closes #12624
Validation How did you test these changes?
- [x] Did you build the app and test your changes?
- [ ] Did you check for accessibility? You can use Accessibility Insights for this.
- [ ] Did you remove any strings from the en-us resource file?
- [ ] Did you search the solution to see if the string is still being used?
- [ ] Did you implement any design changes to an existing feature?
- [ ] Was this change approved?
- [x] Are there any other steps that were used to validate these changes?
- Open multiple Files instances, and open several tabs for each instance.(Need to check "Continue where you left off")
- Modify tabs at will, including opening tabs, closing tabs, changing tab paths, etc.
- Check if "LastAppsTabsWithIDList" in user_settings.json is consistent with the open tab page.
- Restart the computer directly.
- After restarting, open Files and see if the tab status before shutdown is automatically restored.
Screenshots (optional) Add screenshots here.
I force-pushed my branch, causing the previous PR #12990 to be automatically closed. Because my program build reported an error in the latest commit.
Error CS0246 The type or namespace name 'SevenZipOpenFailedException' could not be found (are you missing a using directive or an assembly reference?) Error CS1061 'ExtractionFailedException' does not contain a definition for 'Result', and no accessible extension method 'Result' that accepts a first argument of type 'ExtractionFailedException' could be found (are you missing a using directive or an assembly reference?) \src\Files.App\Utils\Storage\StorageBaseItems\IPasswordProtectedItem. cs But SevenZipSharp is installed in my NuGet package
I've now put most of my changes into Helpers/AppLifecycle.cs.
You can fix that issue by deleting USER_PROFILE/.nuget/packages
The latest commit has been merged, and it works well.
@IzayoiSake sorry for the delay, I took a look and I think we can simplify this quite a bit by using WM_ENDSESSION
to detect when the device is shutting down/logging off.
Sorry for the late response. Indeed, using the WM_ENDSESSION message is much better. However, I am currently stuck in an issue. The code is as follows:
public static void SaveTabs()
{
var userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
var lastAppsTabsWithIdArgList = new List<TabItemWithIDArguments>();
if (userSettingsService.GeneralSettingsService.LastAppsTabsWithIDList is not null)
{
lastAppsTabsWithIdArgList = userSettingsService.GeneralSettingsService.LastAppsTabsWithIDList
.Select(x => TabItemWithIDArguments.Deserialize(x))
.ToList();
}
var tabsWithIdArgList = GetTabsWithIDArgList();
tabsWithIdArgList = tabsWithIdArgList.Concat(lastAppsTabsWithIdArgList).ToList();
userSettingsService.GeneralSettingsService.LastAppsTabsWithIDList = tabsWithIdArgList.Select(x => x.Serialize()).ToList();
}
This function is executed when receiving the WM_ENDSESSION message. However, I found that userSettingsService.GeneralSettingsService.LastAppsTabsWithIDList is not updated in real-time. For example, when "Instance 1" executes the above function first, if "Instance 2" executes it afterward, it won't be able to obtain the data stored by "Instance 1."
Is Instance
talking about multiple windows?
Yes. When multiple windows are running, their userSettingsService.GeneralSettingsService.LastAppsTabsWithIDList
are isolated from each other. Therefore, when receiving WM_ENDSESSION
message, only the Tabs of the last closed window are saved.
This is true even when closing the app normally. We might be able to add support for saving tabs from multiple windows once we switch to single instance.
@IzayoiSake Do you have any update on this?
This function is executed when receiving the WM_ENDSESSION message. However, I found that userSettingsService.GeneralSettingsService.LastAppsTabsWithIDList is not updated in real-time. For example, when "Instance 1" executes the above function first, if "Instance 2" executes it afterward, it won't be able to obtain the data stored by "Instance 1."
Some settings are only saved when the app is closed (for performance reasons). We can adjust it so that the tab list is saved right away, but we'll need to account for multiple windows.
We recently made a fix for this.