Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(desktop): restore window size and position across launches (#7979)

Eric Hayesa5f9cad96935
diff --git a/apps/web/tauri/Cargo.lock b/apps/web/tauri/Cargo.lock
index 6253155488..7327c7e089 100644
--- a/apps/web/tauri/Cargo.lock
+++ b/apps/web/tauri/Cargo.lock
@@ -293,6 +293,7 @@ dependencies = [
"tauri-plugin-updater",
"tauri-plugin-virtual-keyboard",
"tauri-plugin-websocket",
+ "tauri-plugin-window-state",
"thiserror 2.0.18",
"tokio",
"tokio-util",
@@ -7122,6 +7123,21 @@ dependencies = [
"tokio-tungstenite",
]
+[[package]]
+name = "tauri-plugin-window-state"
+version = "2.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73736611e14142408d15353e21e3cca2f12a3cfb523ad0ce85999b6d2ef1a704"
+dependencies = [
+ "bitflags 2.11.1",
+ "log",
+ "serde",
+ "serde_json",
+ "tauri",
+ "tauri-plugin",
+ "thiserror 2.0.18",
+]
+
[[package]]
name = "tauri-runtime"
version = "2.11.3"
diff --git a/apps/web/tauri/src-tauri/Cargo.toml b/apps/web/tauri/src-tauri/Cargo.toml
index 4bc51537c6..4a78a37f24 100644
--- a/apps/web/tauri/src-tauri/Cargo.toml
+++ b/apps/web/tauri/src-tauri/Cargo.toml
@@ -74,6 +74,8 @@ tauri-plugin-os = "2"
clap = { version = "4", features = ["derive"] }
tauri-plugin-single-instance = { version = "2", features = ["deep-link"] }
tauri-plugin-updater = "=2.10.1"
+# 2.5 requires tauri 2.12; the pinned fork is 2.11.
+tauri-plugin-window-state = "=2.4.1"
[target.'cfg(target_os = "macos")'.dependencies]
block2 = "0.6"
diff --git a/apps/web/tauri/src-tauri/README.md b/apps/web/tauri/src-tauri/README.md
index b62118d230..0d4326554f 100644
--- a/apps/web/tauri/src-tauri/README.md
+++ b/apps/web/tauri/src-tauri/README.md
@@ -200,6 +200,15 @@ or enqueueing mutations. An older binary uses the existing uncached fallback and
shows an update-required notice; its existing mutation queue stays intact until
the user installs the native update.
+## Desktop window state
+
+The desktop window reopens at its last size, position, maximized, and
+fullscreen state (`src/window_state.rs`, backed by `tauri-plugin-window-state`).
+The `tauri.conf.json` window size only applies to the first launch. A saved
+position that no longer lands on a connected monitor is ignored and the OS
+places the window. State is written to `.window-state.json` in the app config
+directory on quit; delete that file to reset. Mobile is unaffected.
+
## Desktop native updates
Release builds for macOS Apple Silicon and Linux AppImage check for native updates
diff --git a/apps/web/tauri/src-tauri/src/lib.rs b/apps/web/tauri/src-tauri/src/lib.rs
index dffdffda41..1490d9d3cb 100644
--- a/apps/web/tauri/src-tauri/src/lib.rs
+++ b/apps/web/tauri/src-tauri/src/lib.rs
@@ -41,6 +41,8 @@ mod logging;
mod macos_notification_permission;
mod share_target;
mod staged_upload;
+#[cfg(desktop)]
+mod window_state;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum AppEnvironment {
@@ -159,9 +161,11 @@ pub fn run() {
{
// single instance plugin should always be the first registered
tracing::debug!("register single instance plugin");
- builder = builder.plugin(tauri_plugin_single_instance::init(|_app, argv, _cwd| {
- tracing::debug!("single instance callback with argv: {argv:?}");
- }))
+ builder = builder
+ .plugin(tauri_plugin_single_instance::init(|_app, argv, _cwd| {
+ tracing::debug!("single instance callback with argv: {argv:?}");
+ }))
+ .plugin(window_state::plugin());
}
#[cfg(target_os = "ios")]
@@ -399,6 +403,7 @@ pub fn run() {
}
#[cfg(desktop)]
RunEvent::ExitRequested { api, .. } => {
+ window_state::save(app_handle);
desktop_update::on_exit_requested(app_handle, api)
}
RunEvent::Exit => {
diff --git a/apps/web/tauri/src-tauri/src/window_state.rs b/apps/web/tauri/src-tauri/src/window_state.rs
new file mode 100644
index 0000000000..3f9241de65
--- /dev/null
+++ b/apps/web/tauri/src-tauri/src/window_state.rs
@@ -0,0 +1,32 @@
+//! Reopens the desktop window where the user left it.
+//!
+//! Without this, every launch creates the window at the `tauri.conf.json`
+//! default size wherever the OS places it. The plugin restores the saved
+//! geometry when the window is created and keeps it updated from move/resize
+//! events; the saved position is only reused when it still lands on a
+//! connected monitor.
+
+use tauri::plugin::TauriPlugin;
+use tauri::{AppHandle, Runtime};
+use tauri_plugin_window_state::{AppHandleExt, Builder, StateFlags};
+
+/// Decorations are fixed by `tauri.conf.json` and visibility is never toggled,
+/// so only geometry is persisted. Restoring `VISIBLE` would also re-show and
+/// refocus the window on every launch.
+const FLAGS: StateFlags = StateFlags::SIZE
+ .union(StateFlags::POSITION)
+ .union(StateFlags::MAXIMIZED)
+ .union(StateFlags::FULLSCREEN);
+
+pub fn plugin<R: Runtime>() -> TauriPlugin<R> {
+ Builder::new().with_state_flags(FLAGS).build()
+}
+
+/// The plugin only writes to disk on `RunEvent::Exit`. The native updater's
+/// restart path exits the process before that event, so persist as soon as
+/// quitting is requested; a later `Exit` write is harmless.
+pub fn save<R: Runtime>(app: &AppHandle<R>) {
+ if let Err(error) = app.save_window_state(FLAGS) {
+ tracing::warn!(error = ?error, "failed to save window state");
+ }
+}