Skip to main content

WindowStateService

Struct WindowStateService 

Source
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

Source

pub fn open(paths: &AppPaths) -> Result<Self, SettingsFileError>

Open the window-state file at the standard location inside paths.

Source

pub fn open_with_delay( paths: &AppPaths, delay: Duration, ) -> Result<Self, SettingsFileError>

Open at the standard location with an explicit debounce window.

Source

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).

Source

pub fn state_for(&self, label: &str) -> Option<PerWindowState>

Saved state for the window with label, or None if there’s no entry.

Source

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.

Source

pub fn forget(&self, label: &str) -> Result<(), SettingsFileError>

Forget the entry for label.

Source

pub fn labels(&self) -> Vec<String>

All recorded labels. Useful for “restore last session” features.

Source

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.

Source

pub fn path(&self) -> &Path

Absolute path of the underlying TOML file managed by this service.

Trait Implementations§

Source§

impl Clone for WindowStateService

Source§

fn clone(&self) -> WindowStateService

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WindowStateService

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Reloadable for WindowStateService

Source§

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.

Source§

fn path(&self) -> &Path

The file this instance reads from and writes to. A watcher uses this to know which path to associate with which Reloadable handle.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.