Skip to main content

Module user_workspace

Module user_workspace 

Source
Expand description

The open workspace: a named set of windows, saved as it changes (docs/specs/SPEC_WORKSPACES_2026_10_23.md §2, §4, §8). Not the srv Workspace object, which is one window’s contents.

  • Which one is open: Client.meta["workspace:current"] (its id) and Client.meta["workspace:name"] (its name, for the status bar panel). A start with no workspace makes Default Workspace; a new version’s first start copies the previous version’s instead (prepare_at_startup).
  • Saving: every write to a window, a window’s contents, a tab, a layout or a block counts as a change (LayoutWrites, bumped by the store). The saver (spawn_saver) writes the whole session (session_windows::snapshot_session) as the workspace’s record 1 s after the last change, and at least every 15 s while changes keep coming. A quit, an OS shutdown and the last window’s close write it at once (write_record_now), and so does a window losing focus (workspace.Flush). A write that would store what is already there is skipped; one with no window open is never made. Each window in the record has a state: open, or closed for the windows the user closed (session_closed), which a cold start keeps closed.
  • Loading: a cold start restores the newer of the session record and the workspace’s record, then falls back to the last record that loaded cleanly (previous) and the copy made before an upgrade (pre_upgrade) (restore_at_launch). Only a clean load replaces previous.

The session record (session:last_topology) is still written as before: the version after this one reads it if it has no workspace yet.

Structs§

Pending 🔒
A change not yet saved: when the first came, and the last, and whether any changed the arrangement (not only blocks’ settings).
Restored 🔒
What a launch restored: the window being created’s workspace and events (as restore_last_session returns them), the record and where it came from.

Enums§

LoadedFrom 🔒
Which copy a launch loaded.
Saved 🔒
What a save did.

Constants§

CEILING_MS 🔒
…and no later than this after the first one not yet saved.
CURRENT_META_KEY 🔒
The open workspace’s id.
DEBOUNCE_MS 🔒
A change is saved this long after the last one…
DEFAULT_NAME 🔒
The workspace everyone starts in.
NAME_MAX_CHARS 🔒
The longest name kept, in characters (a window’s name has the same cap).
NAME_META_KEY 🔒
The open workspace’s name.
RESTORED_FROM_META_KEY 🔒
Set when a launch had to load an older copy of the workspace: previous or pre_upgrade. The window says so once and clears it.
SETTINGS_ONLY_MS 🔒
A change to blocks’ settings alone (an agent pane writes them as it works) waits this long instead; a close, a quit or focus loss saves it at once.
TICK 🔒
How often the saver looks for changes.

Statics§

WRITE_LOCK 🔒
One save at a time: the saver, a flush and a boundary write never interleave their read-compare-write.

Functions§

adopt_current 🔒
After ensure_initial_data: open decided (from prepare_at_startup), or keep the one the client names, or the most recently opened. Writes its id and name onto the client, and when it was opened onto its row.
after_clean_load 🔒
A restore finished cleanly (window_create’s final read-back): keep what loaded as the workspace’s previous, and when it was an older copy, leave the window a note to say so.
clean_name 🔒
name trimmed and capped, or None when nothing is left.
client 🔒
copy_from_previous_version 🔒
A new version’s first start (spec §4.2 “Upgrades”): copy every workspace the channel’s most recently written other version has, once, reading its database only. Ids and names are kept; each record is also kept as the row’s pre_upgrade. Returns the one to open: the one that version had open. None when there is nothing to copy.
create_client_only 🔒
The client row alone, as ensure_initial_data makes it (insert, then the temp id), with no window: ensure_initial_data then sees a store that is set up and seeds nothing.
current_id 🔒
The open workspace’s id, if one is set.
handle_flush 🔒
workspace.Flush: save the open workspace now if anything changed since its last save. The window calls it when it loses focus. Returns { saved }.
handle_rename 🔒
workspace.RenameUserWorkspace(workspaceId, name): rename a workspace ("" is the open one). The row and, for the open one, the client’s workspace:name change in one transaction; the client goes back as an object update so every window’s status bar panel shows the new name.
launch_candidates 🔒
The records a cold start tries, in order: the newer of the session record and the workspace’s record (the session record on a tie: a quit writes both), then the other, then previous, then pre_upgrade. A copy that doesn’t parse is left out.
new_row 🔒
parse_copy 🔒
prepare_at_startup 🔒
Before the store’s first window is made (wcore::ensure_initial_data): make sure there is a workspace. With none, copy the previous version’s (copy_from_previous_version), else make Default Workspace. Returns the workspace this start opens when it decided one, for adopt_current.
quit_holds_saves 🔒
Whether a quit is under way: its record is the session record and was saved within the last two minutes (session_windows::is_recent_quit_record).
read_other_workspaces 🔒
The workspaces in the database at path, read-only, with the id its client names as open. Ok(None) for a database without workspaces (an older version’s has no table).
record_has_tabs 🔒
Whether any window in record has a tab to restore.
restore_at_launch 🔒
A cold start’s restore: each of launch_candidates in turn until one brings a window back. Ok(None) when none had anything; the default seed follows.
same_windows 🔒
Whether two records hold the same windows: equal but for saved_at_ms.
save_now 🔒
Save the open workspace from the live windows now.
saved_at 🔒
spawn_saver 🔒
Save the open workspace as it changes, for as long as srv runs. The state it starts with is saved too (§8: the windows open at the first start with this become Default Workspace at once).
write_record 🔒
Store record (the open windows) as the open workspace’s windows, with its closed windows (session_closed::with_closed), unless that is what is stored already. Takes no lock; callers hold WRITE_LOCK.
write_record_now 🔒
Write record (a session record a boundary just built: a quit’s, an OS shutdown’s, the last close’s) as the open workspace’s windows.