|
| 1 | +//! In-session position+size cache for child windows (Settings, Debug). |
| 2 | +//! |
| 3 | +//! The window-state plugin persists only the main window across launches |
| 4 | +//! (`with_filter(|label| label == "main")` in `lib.rs`). Child windows |
| 5 | +//! intentionally start fresh each app launch — they're modal-feeling and |
| 6 | +//! should reappear centered on the main window, not in a stale spot from |
| 7 | +//! days ago. |
| 8 | +//! |
| 9 | +//! Within a single session, though, reopening Settings after closing it |
| 10 | +//! should land back where the user last had it. That's what this cache is |
| 11 | +//! for. It lives in `app.manage(...)` so it's wiped automatically when the |
| 12 | +//! process exits; no disk involvement. |
| 13 | +
|
| 14 | +use std::collections::HashMap; |
| 15 | +use std::sync::Mutex; |
| 16 | + |
| 17 | +/// Logical-pixel rectangle. `f64` mirrors what Tauri's `LogicalPosition` / |
| 18 | +/// `LogicalSize` use on the wire. |
| 19 | +#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)] |
| 20 | +pub struct ChildWindowRect { |
| 21 | + pub x: f64, |
| 22 | + pub y: f64, |
| 23 | + pub width: f64, |
| 24 | + pub height: f64, |
| 25 | +} |
| 26 | + |
| 27 | +/// Mutex-guarded map keyed by window label. |
| 28 | +#[derive(Default)] |
| 29 | +pub struct ChildWindowRectStore(Mutex<HashMap<String, ChildWindowRect>>); |
| 30 | + |
| 31 | +impl ChildWindowRectStore { |
| 32 | + pub fn new() -> Self { |
| 33 | + Self::default() |
| 34 | + } |
| 35 | + |
| 36 | + pub fn get(&self, label: &str) -> Option<ChildWindowRect> { |
| 37 | + self.0.lock().ok()?.get(label).copied() |
| 38 | + } |
| 39 | + |
| 40 | + pub fn set(&self, label: String, rect: ChildWindowRect) { |
| 41 | + if let Ok(mut map) = self.0.lock() { |
| 42 | + map.insert(label, rect); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments