Skip to content

Restore workspace and open tabs between sessions - #258

Merged
ZFordDev merged 4 commits into
mainfrom
244-restore-workspace-and-open-tabs-between-sessions
Sep 1, 2026
Merged

Restore workspace and open tabs between sessions#258
ZFordDev merged 4 commits into
mainfrom
244-restore-workspace-and-open-tabs-between-sessions

Conversation

@ZFordDev

@ZFordDev ZFordDev commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

Adds opt-in session restoration (issue #244). When enabled, SnapDock reopens the last workspace and the saved-file tabs (in order, with the previously active tab) on startup.

This replaces the earlier autosave idea (which stored a single editor buffer) by persisting navigation metadata only and always reloading file content from disk.

Changes

1. Session metadata module (src/modules/file/session.js)

  • Persists only { workspacePath, openFiles, activeFile } to a workspace-scoped localStorage key (snapdock_session_<workspace>), mirroring the recent-files pattern.
  • Off by default (snapdock_session_enabled); opt-in.
  • Never stores file contents, untitled tabs, dirty text, undo/scroll, or snapshots.
  • Toggle on/off (isSessionRestoreEnabled / setSessionRestoreEnabled), metadata load/save/clear with defensive parsing.

2. Tab-state persistence (src/modules/file/tabs.js)

  • Persists the session whenever a saved-file tab is created, closed, moved (drag reorder), or set active — but only when the feature is enabled, and only records tabs that have a filePath.
  • A persistSession() helper captures current tab order and active file path.

3. Tools menu toggle

  • New Tools → Restore Session button (#restoreSessionBtn), modeled on the Spellcheck toggle (off by default).
  • Enabling records the current navigation state immediately; disabling clears the stored session metadata (per acceptance criteria).

4. Startup restore

  • initSessionRestore() listens for the workspace-loaded event and, when enabled, reopens each saved-file path in order via handleFileOpen() (which reloads from disk and skips missing/inaccessible files), then switches to the previously active tab.
  • Registered before initApp() so it catches the startup workspace event.
  • Enforces workspace isolation (only restores files under the triggered workspace).

5. Close Project clears session

  • The existing workspace:clear-for-close handler now also calls clearSession().

6. Tests

  • tests/session-restore.test.mjs: 9 unit tests covering restoration round-trip, active-tab fallback, workspace isolation, disabling/clearing, corrupt-metadata safety, and verifying that persisted values contain only metadata (no file body text). Wired into the npm test script.

7. Documentation

  • Updated the bundled user guide and the online DocsHub snapdock docs (preferences, desktop guide, developer reference, technical overview, history, troubleshooting).

Out of scope (by design)

  • No unsaved/dirty content, untitled tabs, undo/redo history, cursor/scroll positions, automatic file writes, or crash snapshots.

Verification

  • New unit tests pass (9/9) via node --test tests/session-restore.test.mjs. Confirmed working interactively.
  • Note: the full npm test chain and the esbuild renderer bundle require node_modules (markdown-it/esbuild), which is not installed in the dev workspace used here. All changed source files pass node -c syntax checks; these build/run in CI.

Files changed

  • src/modules/file/session.js (new)
  • src/modules/file/tabs.js
  • src/modules/ui/dropdownMenus.js
  • src/scripts.js
  • index.html
  • package.json
  • assets/resources/docs/user_guide.md
  • tests/session-restore.test.mjs (new)

Closes #244

…s toggle (#244)

Add an opt-in session restoration foundation:
- New src/modules/file/session.js owns navigation-only session metadata
  ({workspacePath, openFiles, activeFile}) scoped per workspace, mirroring
  the recent-files pattern. Content is never stored; files reload from disk.
- tabs.js persists the session on every saved-file-tab mutation (create,
  close, move, switch-active) when the feature is enabled.
- Tools menu gains a Restore Session toggle (off by default). Enabling
  records the current navigation state; disabling clears stored metadata.
Add initSessionRestore() which listens for the workspace-loaded event and,
when session restoration is enabled, reopens the saved-file tabs in their
previous order via handleFileOpen() (loading content from disk, skipping
missing/inaccessible files) and then restores the previously active tab.

The restore listener is registered before initApp() so it catches the startup
workspace-loaded event. Files are filtered to the triggering workspace to
enforce workspace isolation.

Close Project now clears the stored session metadata alongside the workspace
clear and relaunch (scripts.js onClearForCloseRequest).
#244)

Cover the session metadata module (session.js) with an in-memory
localStorage mock:

- disabled by default and persist-across-restart preference,
- save/load round-trip restores ordered open files and the active file
  while excluding untitled tabs,
- active-file fallback to the last open file,
- workspace isolation (sessions keyed per folder; foreign workspace = null),
- disabling + clearing removes stored metadata (also the Close Project path),
- corrupt metadata returns null safely,
- persisted values are navigation metadata only and never contain file body
  text.

Runs standalone via node --test. Full suite requires npm install (node_modules)
for the markdown-it-based md:test step, which is unavailable in this workspace.
Add a Session restoration section covering the Tools -> Restore Session toggle,
saved-file-only restoration, reload-from-disk behavior, skipping of missing
files, and clearing on disable / Close Project.
@ZFordDev ZFordDev linked an issue Sep 1, 2026 that may be closed by this pull request
11 tasks
@ZFordDev
ZFordDev merged commit c32c9e4 into main Sep 1, 2026
4 checks passed
@ZFordDev
ZFordDev deleted the 244-restore-workspace-and-open-tabs-between-sessions branch September 1, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restore workspace and open tabs between sessions

1 participant