The window-state module persists the current window's geometry to
JSON and restores it at startup: position (x/y), size
(width/height), and the maximized/fullscreen/always-on-top flags. It
is a translation of Tauri's tauri-plugin-window-state, backed by the
plugin:window-state|* commands. Three commands: get (read the
persisted state, null when none), save (snapshot the current geometry
and return it), restore (re-apply the persisted state, no-op when
none).
window-state is a standalone plugin with a two-level permission ladder:
| Permission set | Grants |
|---|---|
window-state:default |
allow-get + allow-restore (read + startup restore) |
window-state:write |
default + allow-save (write snapshots) |
From examples/hello/capabilities/main.json:
"window-state:write".
Construction options: windowStatePlugin({ file?, restoreOnStartup? })
— file is the absolute path of the state JSON (default
$TMP/ztron-window-state.json); restoreOnStartup defaults to true
(the plugin auto-restores one tick after setup); the hello spike turns
it off to verify restore manually. From
examples/hello/src/main.ts:
The restore order matters (DESIGN §30): the webview library re-centers
the window on every set_size, so the host applies the size first
and the position afterwards, then re-applies
maximized/fullscreen/alwaysOnTop as needed.
A save → move → restore round trip. From
examples/hello/frontend/src/main.ts (the anchor
WINDOW_STATE_PLUGIN_OK is its real run output):
The WindowState shape: { x, y, width, height, maximized, fullscreen, alwaysOnTop }; getWindowState() / restoreWindowState() return
null when there is no state file. All three functions accept
{ file } to override the default path.
plugin:window-state|* totals 3 commands, mapped one-to-one to
the API:
| Command | API |
|---|---|
get |
getWindowState(options?) |
save |
saveWindowState(options?) |
restore |
restoreWindowState(options?) |
Full list in the Commands Reference and the API symbol reference.
Applicable version: ztron 0.3.1