From e3cd040324287c6dc02812c9b6594c9baa0c95a9 Mon Sep 17 00:00:00 2001 From: 1111mp Date: Thu, 5 Dec 2024 18:05:37 +0800 Subject: [PATCH] fix: correct usage of `tauri-plugin-window-state` (https://github.com/1111mp/nvm-desktop/issues/147) Signed-off-by: 1111mp --- src-tauri/src/cmds.rs | 2 ++ src-tauri/src/main.rs | 7 ++----- src-tauri/src/utils/resolve.rs | 8 +++----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 34c4533..138442b 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -1,5 +1,6 @@ use anyhow::Result; use std::{path::PathBuf, process::Command}; +use tauri_plugin_window_state::{AppHandleExt, StateFlags}; use crate::{ config::{Config, Group, ISettings, NVersion, Project}, @@ -188,6 +189,7 @@ pub fn open_dir(dir: String) -> CmdResult<()> { /// restart app #[tauri::command] pub fn restart(app_handle: tauri::AppHandle) { + let _ = app_handle.save_window_state(StateFlags::default()); app_handle.restart() } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 5bae5a8..9c94847 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -60,7 +60,7 @@ fn main() -> tauri::Result<()> { cmds::group_list, cmds::update_groups, cmds::update_group_version, - // configration + // configuration cmds::configration_export, cmds::configration_import, // app @@ -97,10 +97,7 @@ fn main() -> tauri::Result<()> { let app = builder.build(tauri::generate_context!())?; - app.run(|app_handle, err| match err { - tauri::RunEvent::ExitRequested { .. } => { - let _ = app_handle.save_window_state(StateFlags::default()); - } + app.run(|_, err| match err { tauri::RunEvent::WindowEvent { label, event, .. } => { if label == "main" { match event { diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index b9b9c54..3a93514 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -46,6 +46,7 @@ pub fn create_window() -> Result<()> { .visible(false) .fullscreen(false) .inner_size(1024.0, 728.0) + .min_inner_size(1024.0, 728.0) .resizable(false) .center(); @@ -67,11 +68,8 @@ pub fn create_window() -> Result<()> { #[cfg(target_os = "linux")] let window = builder.decorations(false).transparent(true).build()?; - if tauri::is_dev() { - window.open_devtools(); - } - - let _ = window.restore_state(StateFlags::all()); + #[cfg(debug_assertions)] + window.open_devtools(); Ok(()) }