Files icon indicating copy to clipboard operation
Files copied to clipboard

Feature: Added support for restoring tabs after restarting Windows

Open IzayoiSake opened this issue 11 months ago • 10 comments

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?
    1. Open multiple Files instances, and open several tabs for each instance.(Need to check "Continue where you left off")
    2. Modify tabs at will, including opening tabs, closing tabs, changing tab paths, etc.
    3. Check if "LastAppsTabsWithIDList" in user_settings.json is consistent with the open tab page.
    4. Restart the computer directly.
    5. After restarting, open Files and see if the tab status before shutdown is automatically restored.

Screenshots (optional) Add screenshots here.

IzayoiSake avatar Aug 05 '23 02:08 IzayoiSake

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 image

I've now put most of my changes into Helpers/AppLifecycle.cs.

IzayoiSake avatar Aug 05 '23 03:08 IzayoiSake

You can fix that issue by deleting USER_PROFILE/.nuget/packages

0x5bfa avatar Aug 05 '23 06:08 0x5bfa

The latest commit has been merged, and it works well.

IzayoiSake avatar Aug 05 '23 10:08 IzayoiSake

@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.

yaira2 avatar Nov 16 '23 16:11 yaira2

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."

IzayoiSake avatar Dec 03 '23 09:12 IzayoiSake

Is Instance talking about multiple windows?

yaira2 avatar Dec 03 '23 15:12 yaira2

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.

IzayoiSake avatar Dec 03 '23 15:12 IzayoiSake

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.

yaira2 avatar Dec 03 '23 15:12 yaira2

@IzayoiSake Do you have any update on this?

0x5bfa avatar Feb 15 '24 17:02 0x5bfa

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.

yaira2 avatar Feb 15 '24 17:02 yaira2

We recently made a fix for this.

0x5bfa avatar Feb 21 '24 15:02 0x5bfa