Preserve window size through restarts

This commit is contained in:
Matte Noble
2025-05-29 10:13:53 -07:00
parent ccef224ea5
commit 957a3e3c7f
9 changed files with 132 additions and 7 deletions

View File

@@ -58,6 +58,7 @@
"@tauri-apps/plugin-os": "~2",
"@tauri-apps/plugin-sql": "~2",
"@tauri-apps/plugin-updater": "~2",
"@tauri-apps/plugin-window-state": "~2",
"change-case": "^5.4.4",
"highlight.js": "^11.11.1",
"marked": "^15.0.7",

10
pnpm-lock.yaml generated
View File

@@ -32,6 +32,9 @@ importers:
'@tauri-apps/plugin-updater':
specifier: ~2
version: 2.7.1
'@tauri-apps/plugin-window-state':
specifier: ~2
version: 2.2.2
change-case:
specifier: ^5.4.4
version: 5.4.4
@@ -791,6 +794,9 @@ packages:
'@tauri-apps/plugin-updater@2.7.1':
resolution: {integrity: sha512-1OPqEY/z7NDVSeTEMIhD2ss/vXWdpfZ5Th2Mk0KtPR/RA6FKuOTDGZQhxoyYBk0pcZJ+nNZUbl/IujDCLBApjA==}
'@tauri-apps/plugin-window-state@2.2.2':
resolution: {integrity: sha512-7pFwmMtGhhhE/WgmM7PUrj0BSSWVAQMfDdYbRalphIqqF1tWBvxtlxclx8bTutpXHLJTQoCpIeWtBEIXsoAlGw==}
'@types/cookie@0.6.0':
resolution: {integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==}
@@ -3036,6 +3042,10 @@ snapshots:
dependencies:
'@tauri-apps/api': 2.3.0
'@tauri-apps/plugin-window-state@2.2.2':
dependencies:
'@tauri-apps/api': 2.3.0
'@types/cookie@0.6.0': {}
'@types/estree@1.0.6': {}

16
src-tauri/Cargo.lock generated
View File

@@ -30,6 +30,7 @@ dependencies = [
"tauri-plugin-single-instance",
"tauri-plugin-sql",
"tauri-plugin-updater",
"tauri-plugin-window-state",
"tokio",
"webview2-com 0.37.0",
"webview2-com-sys 0.37.0",
@@ -5264,6 +5265,21 @@ dependencies = [
"zip",
]
[[package]]
name = "tauri-plugin-window-state"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a27a3fe49de72adbe0d84aee33c89a0b059722cd0b42aaeab29eaaee7f7535cd"
dependencies = [
"bitflags 2.9.0",
"log",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.12",
]
[[package]]
name = "tauri-runtime"
version = "2.4.0"

View File

@@ -48,6 +48,7 @@ webview2-com-sys = "0.37.0"
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-updater = "2"
tauri-plugin-window-state = "2"
[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.

File diff suppressed because one or more lines are too long

View File

@@ -6037,6 +6037,48 @@
"type": "string",
"const": "updater:deny-install",
"markdownDescription": "Denies the install command without any pre-configured scope."
},
{
"description": "This permission set configures what kind of\noperations are available from the window state plugin.\n\n#### Granted Permissions\n\nAll operations are enabled by default.\n\n\n#### This default permission set includes:\n\n- `allow-filename`\n- `allow-restore-state`\n- `allow-save-window-state`",
"type": "string",
"const": "window-state:default",
"markdownDescription": "This permission set configures what kind of\noperations are available from the window state plugin.\n\n#### Granted Permissions\n\nAll operations are enabled by default.\n\n\n#### This default permission set includes:\n\n- `allow-filename`\n- `allow-restore-state`\n- `allow-save-window-state`"
},
{
"description": "Enables the filename command without any pre-configured scope.",
"type": "string",
"const": "window-state:allow-filename",
"markdownDescription": "Enables the filename command without any pre-configured scope."
},
{
"description": "Enables the restore_state command without any pre-configured scope.",
"type": "string",
"const": "window-state:allow-restore-state",
"markdownDescription": "Enables the restore_state command without any pre-configured scope."
},
{
"description": "Enables the save_window_state command without any pre-configured scope.",
"type": "string",
"const": "window-state:allow-save-window-state",
"markdownDescription": "Enables the save_window_state command without any pre-configured scope."
},
{
"description": "Denies the filename command without any pre-configured scope.",
"type": "string",
"const": "window-state:deny-filename",
"markdownDescription": "Denies the filename command without any pre-configured scope."
},
{
"description": "Denies the restore_state command without any pre-configured scope.",
"type": "string",
"const": "window-state:deny-restore-state",
"markdownDescription": "Denies the restore_state command without any pre-configured scope."
},
{
"description": "Denies the save_window_state command without any pre-configured scope.",
"type": "string",
"const": "window-state:deny-save-window-state",
"markdownDescription": "Denies the save_window_state command without any pre-configured scope."
}
]
},

View File

@@ -6037,6 +6037,48 @@
"type": "string",
"const": "updater:deny-install",
"markdownDescription": "Denies the install command without any pre-configured scope."
},
{
"description": "This permission set configures what kind of\noperations are available from the window state plugin.\n\n#### Granted Permissions\n\nAll operations are enabled by default.\n\n\n#### This default permission set includes:\n\n- `allow-filename`\n- `allow-restore-state`\n- `allow-save-window-state`",
"type": "string",
"const": "window-state:default",
"markdownDescription": "This permission set configures what kind of\noperations are available from the window state plugin.\n\n#### Granted Permissions\n\nAll operations are enabled by default.\n\n\n#### This default permission set includes:\n\n- `allow-filename`\n- `allow-restore-state`\n- `allow-save-window-state`"
},
{
"description": "Enables the filename command without any pre-configured scope.",
"type": "string",
"const": "window-state:allow-filename",
"markdownDescription": "Enables the filename command without any pre-configured scope."
},
{
"description": "Enables the restore_state command without any pre-configured scope.",
"type": "string",
"const": "window-state:allow-restore-state",
"markdownDescription": "Enables the restore_state command without any pre-configured scope."
},
{
"description": "Enables the save_window_state command without any pre-configured scope.",
"type": "string",
"const": "window-state:allow-save-window-state",
"markdownDescription": "Enables the save_window_state command without any pre-configured scope."
},
{
"description": "Denies the filename command without any pre-configured scope.",
"type": "string",
"const": "window-state:deny-filename",
"markdownDescription": "Denies the filename command without any pre-configured scope."
},
{
"description": "Denies the restore_state command without any pre-configured scope.",
"type": "string",
"const": "window-state:deny-restore-state",
"markdownDescription": "Denies the restore_state command without any pre-configured scope."
},
{
"description": "Denies the save_window_state command without any pre-configured scope.",
"type": "string",
"const": "window-state:deny-save-window-state",
"markdownDescription": "Denies the save_window_state command without any pre-configured scope."
}
]
},

View File

@@ -16,6 +16,7 @@ use std::sync::OnceLock;
use process::Process;
use tauri::{AppHandle, Manager, RunEvent};
use tauri_plugin_deep_link::DeepLinkExt;
use tauri_plugin_window_state::{AppHandleExt, StateFlags, WindowExt};
use crate::migrations::migrations;
use crate::state::State;
@@ -28,6 +29,7 @@ static APP_HANDLE: OnceLock<AppHandle> = OnceLock::new();
fn main() {
let app = tauri::Builder::default()
.plugin(tauri_plugin_window_state::Builder::new().build())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_opener::init())
@@ -65,6 +67,8 @@ fn main() {
#[cfg(target_os = "macos")]
configure_macos_window(&window);
let _ = window.restore_state(StateFlags::all());
app.deep_link().on_open_url(|event| {
deeplink::handle(event.urls());
});
@@ -90,11 +94,19 @@ fn main() {
.build(tauri::generate_context!())
.expect("error running Tome");
app.run(|_, event| {
if let RunEvent::Exit = event {
// Ensure we kill every child (and child of child, of child, etc.)
// MCP server process
Process::current().kill().unwrap();
app.run(|app, event| {
match event {
RunEvent::ExitRequested { .. } => {
let _ = app.save_window_state(StateFlags::all());
}
RunEvent::Exit => {
// Ensure we kill every child (and child of child, of child, etc.)
// MCP server process
Process::current().kill().unwrap();
}
_ => {}
}
});
}

View File

@@ -105,7 +105,8 @@
"fs:allow-resource-read",
"sql:default",
"sql:allow-execute",
"updater:default"
"updater:default",
"window-state:default"
]
},
{