fix(desktop): restoreAll reopens every old session as its own window - #5181
Open
imsamad wants to merge 1 commit into
Open
fix(desktop): restoreAll reopens every old session as its own window#5181imsamad wants to merge 1 commit into
imsamad wants to merge 1 commit into
Conversation
Buffer stores only get deleted once all their tabs report isSaved. So if you edit a file across a bunch of sessions without ever hitting save, you end up with one leftover store per session, and restoreAll opens a window for each one. I had 34 stores covering 7 files, one of them duplicated 12 times. Only launching from a desktop launcher hits this, since passing a path on the command line skips the restore branch entirely. Now only one store per set of open documents gets restored, the most recent one, and the older duplicates are deleted so the folder stops growing. Untitled tabs keep their own identity, there's no file to fall back on if we merge those. Also moved the cleanup out of the mt::close-window IPC handler and into forceClose. Everything goes through forceClose eventually, so windows torn down by forceCloseById or by quitting the app were never cleaning up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Launching MarkText from a desktop launcher could open a pile of windows — one per leftover
buffer store — instead of restoring the previous session.
A buffer store is only collected once every tab in it reports
isSaved. So editing afile across several sessions without ever hitting save leaves one store behind per session,
and
restoreAllopens a window for each. In my case: 34 stores covering 7 distinct files,one file duplicated 12 times, so 34 windows on launch. The directory grows without bound
because nothing ever removes the stale duplicates.
Only the launcher pathway hits this — passing a file path on the command line skips the
restore branch entirely.
Two changes:
Restore one window per distinct set of open documents, newest wins.
New
EditorBufferStore.getRestorableBufferStores()keys each store by the set ofpathnames its tabs hold (sorted, so tab order doesn't matter), keeps the store with the
newest mtime for each key, and deletes the superseded ones so the folder stops growing.
App.createWindownow calls it instead of iteratinggetAll().Stores containing an untitled tab keep their own identity (
untitled:<id>) and are nevercollapsed — an unsaved draft exists nowhere else on disk, so merging two of them would
lose content.
A store that fails to parse or stat is skipped, not deleted: it's excluded from the
restore rather than aborting it, and left on disk rather than thrown away.
Moved buffer cleanup from the
mt::close-windowhandler intoforceClose().Every window teardown path funnels through
forceClose, but the cleanup only ran on therenderer's
mt::close-windowround trip. Windows destroyed any other way —forceCloseById, application quit, or a renderer that never answersmt::ask-for-close—never cleaned up their store, which is a large part of how the duplicates accumulated in
the first place. The call sits before
remove()so the editor-window list still countsthe closing window.
Type of change
Test plan
New tests added —
packages/desktop/test/unit/specs/buffer-store-restore-dedupe.spec.ts,5 cases over
getRestorableBufferStores():Manually tested on: Linux — reproduced the 34-window launch, then confirmed a single
restored window per document set after the fix, with the stale stores gone from the
buffer-store directory.
Notes for reviewers [optional]
recency signal available for picking a winner among duplicates. It's good enough here:
the loser is a strictly older snapshot of the same document set.
getRestorableBufferStores(). That's aside effect in something that reads like a getter, and I'd rather hear if you want it
split into a separate sweep — I kept them together so the "which store won" decision and
the "delete the losers" action can't drift apart.
draft still restores as its own window. That's the conservative choice; the alternative
risks silently dropping unsaved content.
restoreBufferIdcast inwindowManager.tsis pre-existing — the property is stashedon the
BrowserWindowand isn't in Electron's types. I moved the call, not the cast.