pub struct WindowStateService { /* private fields */ }Expand description
Persistent, in-memory-backed store for per-window geometry.
Entries are PerWindowState, keyed by a stable string label. state_for
reads straight from memory with no I/O.
§Why this is debounced, unlike SettingsFile
SettingsFile’s mutate is a synchronous locked read-modify-write, which
is right for a document written rarely (a settings change; one record per
backup). Window geometry is the opposite: teksilo-app’s window_persist
observes the size / position / placement signals and calls record
on every change — i.e. once per frame while the user drags a window. A
synchronous flock + read + parse + serialize + fsync per frame would make
dragging visibly janky.
So this service owns its own DebouncedWriter and schedules a
WindowOp patch per record, exactly like crate::PersistedListModel:
in-memory state updates instantly (so state_for is always current), and
the burst collapses into one locked read-merge-write at the debounce
deadline. Frequent writes ⇒ debounced patch; rare writes ⇒ synchronous
locked RMW. Both are cross-process correct; they differ only in when the
disk write happens.
Implementations§
Source§impl WindowStateService
impl WindowStateService
Sourcepub fn open(paths: &AppPaths) -> Result<Self, SettingsFileError>
pub fn open(paths: &AppPaths) -> Result<Self, SettingsFileError>
Open the window-state file at the standard location inside paths.
Sourcepub fn open_with_delay(
paths: &AppPaths,
delay: Duration,
) -> Result<Self, SettingsFileError>
pub fn open_with_delay( paths: &AppPaths, delay: Duration, ) -> Result<Self, SettingsFileError>
Open at the standard location with an explicit debounce window.
Sourcepub fn open_at(
path: PathBuf,
delay: Duration,
) -> Result<Self, SettingsFileError>
pub fn open_at( path: PathBuf, delay: Duration, ) -> Result<Self, SettingsFileError>
Open the window-state file at an explicit path.
delay is the debounce window: geometry changes arriving inside it
coalesce into a single disk write. Duration::ZERO writes on the
worker’s next tick (used by tests).
Sourcepub fn state_for(&self, label: &str) -> Option<PerWindowState>
pub fn state_for(&self, label: &str) -> Option<PerWindowState>
Saved state for the window with label, or None if there’s no entry.
Sourcepub fn record(&self, state: PerWindowState) -> Result<(), SettingsFileError>
pub fn record(&self, state: PerWindowState) -> Result<(), SettingsFileError>
Record the current geometry for label, replacing any prior entry.
Updates memory immediately and schedules a debounced, locked read-merge-write — so a drag costs one write, not one per frame.
Sourcepub fn labels(&self) -> Vec<String>
pub fn labels(&self) -> Vec<String>
All recorded labels. Useful for “restore last session” features.
Sourcepub fn flush_now(&self) -> Result<(), SettingsFileError>
pub fn flush_now(&self) -> Result<(), SettingsFileError>
Flush any pending geometry to disk immediately, bypassing the debounce.
Flushes the op queue, never a re-derived snapshot of the in-memory document — dumping the snapshot is exactly how a cleanly-exiting process would erase a peer’s window entry.
Trait Implementations§
Source§impl Clone for WindowStateService
impl Clone for WindowStateService
Source§fn clone(&self) -> WindowStateService
fn clone(&self) -> WindowStateService
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WindowStateService
impl Debug for WindowStateService
Source§impl Reloadable for WindowStateService
impl Reloadable for WindowStateService
Source§fn reload_from_disk(&self) -> Result<bool, SettingsFileError>
fn reload_from_disk(&self) -> Result<bool, SettingsFileError>
Pick up a peer process’s window entry.
Merging is trivially safe here: entries are keyed by label, and
distinct labels (distinct windows) never conflict — so whatever a peer
wrote simply appears. The (mtime, len) stamp check short-circuits the
echo of our own write, and the content comparison guarantees we never
touch anything when nothing actually changed.