-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Persist window layout cont. save multiple windows #11083
Persist window layout cont. save multiple windows #11083
Conversation
769eb31
to
a59f2a9
Compare
This PR as a whole is difficult to look at now, so discussion can wait for the main one to be merged. Because @lhecker had some concerns
|
This commit adds initial support for saving window layout on application close. Done: - Add user setting for if tabs should be maintained. - Added events to track the number of open windows for the monarch, and then save if you are the last window closing. - Saves layout when the user explicitly hits the "Close Window" button. - If the user manually closed all of their tabs (through the tab x button or through closing all panes on the tab) then remove any saved state. - Saves in the ApplicationState file a list of actions the terminal can perform to restore its layout and the window size/position information. - This saves an action to focus the correct pane, but this won't actually work without #10978. Note that if you have a pane zoomed, it does still zoom the correct pane, but when you unzoom it will have a different pane selected. Todo: - multiple windows? Right now it can only handle loading/saving one window. - PR #11083 will save multiple windows. - This also sometimes runs into the existing bug where multiple tabs appear to be focused on opening. Next Steps: - The business logic of when the save is triggered can be adjusted as necessary. - Right now I am taking the pragmatic approach and just saving the state as an array of objects, but only ever populate it with 1, that way saving multiple windows in the future could be added without breaking schema compatibility. Selfishly I'm hoping that handling multiple windows could be spun off into another pr/feature for now. - One possible thing that can maybe be done is that the commandline can be augmented with a "--saved ##" attribute that would load from the nth saved state if it exists. e.g. if there are 3 saved windows, on first load it can spawn three wt --saved {0,1,2} that would reopen the windows? This way there also exists a way to load a copy of a previous window (if it is in the saved state). - Is the application state something that is planned to be public/user editable? In theory the user could since it is just json, but I don't know what it buys them over just modifying their settings and startupActions. Validation Steps Performed: - The happy path: open terminal -> set setting to true -> close terminal -> reopen and see tabs. Tested with powershell/cmd/wsl windows. - That closing all panes/tabs on their own will remove the saved session. - Open multiple windows, close windows and confirm that the last window closed saves its state. The generated file stores a sequence of actions that will be executed to restore the terminal to its saved form. References #8324 This is also one of the items on #5000 Closes #766
- Monarch will now gather and save all window layouts on a timer - When loading, the first window/monarch will create a new window for each saved layout
…iple windows contending with the same state file. - Re-read the state on saving, and only update the properties that we actually changed
…ow action instead of storing a separate `name` property because that proved more difficult to insert into the lifecycle correctly when the window/peasant was created than afterwards.
8ffd314
to
5aa455d
Compare
branch has been rebased and is now open for business |
Add the ability to quit all terminal instances. Doing this separately from the window layout saving ones to lessen the number of 1k+ line monsters I make y'all review. ## References #11083 ## PR Checklist * [x] Closes #11081 * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [x] Schema updated. ## Detailed Description of the Pull Request / Additional comments - Warn the user before they do so to give a chance to cancel - Percolate a QuitAll event up to the monarch who then directs each peasant to clsoe. - Leave a window-layout-saving-sized hole to add that feature on top ## Validation Steps Performed - quit with one window (from the monarch) - quit from the monarch with multiple windows - quit from a peasant - cancel the quit dialog ![image](https://user-images.githubusercontent.com/6185249/132105775-3310f614-ce55-4454-9718-ef5c0d39fbd2.png)
…ve-multiple-windows Conflicts: src/cascadia/Remoting/Peasant.cpp src/cascadia/Remoting/Peasant.h src/cascadia/Remoting/Peasant.idl src/cascadia/Remoting/WindowManager.h src/cascadia/Remoting/WindowManager.idl src/cascadia/TerminalApp/AppActionHandlers.cpp src/cascadia/TerminalApp/AppLogic.cpp src/cascadia/TerminalApp/AppLogic.h src/cascadia/TerminalApp/AppLogic.idl src/cascadia/TerminalApp/TerminalPage.h src/cascadia/UnitTests_Remoting/RemotingTests.cpp src/cascadia/WindowsTerminal/AppHost.cpp
Added saving on quit, so I believe this is now feature complete. |
So, I was trying to make a video to show off the feature with the new quit, but I managed to reproduce the exception on loading multiple windows that I found in #11143 that kills the monarch. I can't get this to reproduce every time, but it is somewhat frequent. Video of it happening because I was trying to create a new video that doesn't include me killing it in task manager. 2021-09-09.11-28-43.mp4 |
In further testing I've also run into the issue that @leonMSFT warned about where quitting doesn't always cause all windows to quit, despite expectation. Specifically sometimes I've seen that one window might not receive the quit somehow. Its always only one window in my experience, not multiple. This also happens with what is on main, so not including any changes here. Edit: When I've seen the crash on load, and also the failure to quit, I've noticed that the call stack is this. I'm not sure if that is a coincidence or not. Further inspection seems like the window that is left/crashed probably was/just became the monarch because it has a dozen threads in various monarch methods like _doHandleActivatePeasant. I put a memory dump at https://rosefield.org/files/QuitAllCrash.dmp and would appreciate some help debugging :)
Edit Edit: Possibly a com deadlock? Looks like there are a bunch of threads stuck on Edit Edit Edit: All of the monarch as written basically assumes to be single-threaded, but that is definitely not true. E.g. I managed to get this exception too on |
Hello @zadjii-msft! Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:
If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you". |
…Add helper for getting the saved layout.
Wait, any window at all is getting persisted with just 10972 on a force close of the terminal? Interesting. I would've expected nothing to get saved. At least that is what happened when I killed the process locally in my testing. |
…ve-multiple-windows Conflicts: src/cascadia/TerminalApp/TerminalPage.cpp
Oh, has the project taken an explicit dependency on powershell 7 now? I notice that I can't compile after the merge because I don't have |
Oh, that came out of the json::value refactor, didn't it. |
It's possible that it's got leftover state from some previous window closing and then the force-killed one isn't getting persisted. I'm not really sure, this is of course happening at like 1am 😛 |
Yep, that's right - we may want to update the docs for that... |
I'm sorry. That was me! I needed The reason I didn't just write a regex is because some of the patterns (like |
I remembered reading that comment in the other pr, but didn't realize it had been merged yet so was thrown off guard. I figured it out once I noticed the failing command was on running against |
…d variables to try to prevent data loss.
Probably took longer that you would have, and I might have blown up my state file a couple of times with the wrong file attributes, but I think it is working correctly now. |
@check-spelling-bot ReportUnrecognized words, please review:
Previously acknowledged words that are now absentcarlos dpg sid SPACEBAR Unregister xIcon yIcon zamoraTo accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands... in a clone of the [email protected]:Rosefield/terminal.git repository
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉 🗜️ If you see a bunch of garbageIf it relates to a ... well-formed patternSee if there's a pattern that would match it. If not, try writing one and adding it to a Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines. Note that patterns can't match multiline strings. binary-ish stringPlease add a file path to the File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
|
Just to confirm the only outstanding issue to be resolved is the file synchronization? I tried rereading all of the resolved/hidden comments but I want to make sure I'm not missing anything. |
@Rosefield We've talked within our team about this today and we'll probably move the |
NICENICENICE I'm gonna merge this so we can selfhost it for our internal bug bash tomorrow. I'm sure Dustin will have his share of thoughts when he gets back from vacation, but let's fix the nits in post. |
I look forward to no longer babysitting this pr, but instead compulsively checking the issues list to see if I broke anything :) |
…vated-state-2 Tossed out the AppState changes from #11083, since we're planning on just moving that to the Monarch anyways.
🎉 Handy links: |
Summary of the Pull Request
Continuation of #10972 to handle multiple windows, requires that to be merged first.
References
PR Checklist
Detailed Description of the Pull Request / Additional comments
Rough changelog:
Normally saving is triggered to occur every 30s, or sooner if a window is created/closed. The existing behavior of saving on last close is maintained to bypass that throttling. The automatic saving allows for crash recovery. Additionally all window layouts will be saved upon taking the
quit
action.For loading we will check if we are the first window, that there are any saved layouts, and if the setting is enabled, and then depending on if we were given command line args or startup actions.
This also saves the layout when the quit action is taken.
Misc changes
Validation Steps Performed