diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 8a05e7a4f8..e6c3518fd9 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -141,11 +141,11 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" dependencies = [ - "async-lock 3.1.2", + "async-lock 3.2.0", "async-task", "concurrent-queue", "fastrand 2.0.1", - "futures-lite 2.0.1", + "futures-lite 2.1.0", "slab", ] @@ -187,14 +187,14 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6d3b15875ba253d1110c740755e246537483f152fa334f91abd7fe84c88b3ff" dependencies = [ - "async-lock 3.1.2", + "async-lock 3.2.0", "cfg-if", "concurrent-queue", "futures-io", - "futures-lite 2.0.1", + "futures-lite 2.1.0", "parking", "polling 3.3.1", - "rustix 0.38.25", + "rustix 0.38.26", "slab", "tracing", "windows-sys 0.52.0", @@ -211,9 +211,9 @@ dependencies = [ [[package]] name = "async-lock" -version = "3.1.2" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea8b3453dd7cc96711834b75400d671b73e3656975fa68d9f277163b7f7e316" +checksum = "7125e42787d53db9dd54261812ef17e937c95a51e4d291373b670342fa44310c" dependencies = [ "event-listener 4.0.0", "event-listener-strategy", @@ -244,7 +244,7 @@ dependencies = [ "cfg-if", "event-listener 3.1.0", "futures-lite 1.13.0", - "rustix 0.38.25", + "rustix 0.38.26", "windows-sys 0.48.0", ] @@ -271,7 +271,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 0.38.25", + "rustix 0.38.26", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -411,11 +411,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" dependencies = [ "async-channel 2.1.1", - "async-lock 3.1.2", + "async-lock 3.2.0", "async-task", "fastrand 2.0.1", "futures-io", - "futures-lite 2.0.1", + "futures-lite 2.1.0", "piper", "tracing", ] @@ -691,9 +691,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" +checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" dependencies = [ "crossbeam-utils", ] @@ -706,9 +706,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -716,9 +716,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "core-graphics" @@ -748,9 +748,9 @@ dependencies = [ [[package]] name = "core-graphics-types" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" +checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -868,12 +868,12 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.26" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" +checksum = "37e366bff8cd32dd8754b0991fb66b279dc48f598c3a18914852a6673deef583" dependencies = [ "quote", - "syn 1.0.109", + "syn 2.0.39", ] [[package]] @@ -978,9 +978,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" +checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" dependencies = [ "powerfmt", "serde", @@ -1280,14 +1280,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.22" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", - "windows-sys 0.48.0", + "redox_syscall", + "windows-sys 0.52.0", ] [[package]] @@ -1432,14 +1432,13 @@ dependencies = [ [[package]] name = "futures-lite" -version = "2.0.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3831c2651acb5177cbd83943f3d9c8912c5ad03c76afcc0e9511ba568ec5ebb" +checksum = "aeee267a1883f7ebef3700f262d2d54de95dfaf38189015a74fdc4e0c7ad8143" dependencies = [ "fastrand 2.0.1", "futures-core", "futures-io", - "memchr", "parking", "pin-project-lite", ] @@ -2136,9 +2135,9 @@ dependencies = [ [[package]] name = "infer" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a898e4b7951673fce96614ce5751d13c40fc5674bc2d759288e46c3ab62598b3" +checksum = "f551f8c3a39f68f986517db0d1759de85881894fdc7db798bd2a9df9cb04b7fc" dependencies = [ "cfb", ] @@ -2376,7 +2375,7 @@ checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" dependencies = [ "bitflags 2.4.1", "libc", - "redox_syscall 0.4.1", + "redox_syscall", ] [[package]] @@ -2402,9 +2401,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "lock_api" @@ -2640,9 +2639,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "wasi 0.11.0+wasi-snapshot-preview1", @@ -2977,9 +2976,9 @@ dependencies = [ [[package]] name = "openssl" -version = "0.10.60" +version = "0.10.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79a4c6c3a2b158f7f8f2a2fc5a969fa3a068df6fc9dbb4a43845436e3af7c800" +checksum = "6b8419dc8cc6d866deb801274bba2e6f8f6108c1bb7fcc10ee5ab864931dbb45" dependencies = [ "bitflags 2.4.1", "cfg-if", @@ -3018,9 +3017,9 @@ dependencies = [ [[package]] name = "openssl-sys" -version = "0.9.96" +version = "0.9.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3812c071ba60da8b5677cc12bcb1d42989a65553772897a7e0355545a819838f" +checksum = "c3eaad34cdd97d81de97964fc7f29e2d104f483840d906ef56daa1912338460b" dependencies = [ "cc", "libc", @@ -3119,7 +3118,7 @@ checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.4.1", + "redox_syscall", "smallvec", "windows-targets 0.48.5", ] @@ -3180,9 +3179,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" dependencies = [ - "phf_macros 0.10.0", "phf_shared 0.10.0", - "proc-macro-hack", ] [[package]] @@ -3191,6 +3188,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ + "phf_macros 0.11.2", "phf_shared 0.11.2", ] @@ -3270,16 +3268,15 @@ dependencies = [ [[package]] name = "phf_macros" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fdf3184dd560f160dd73922bea2d5cd6e8f064bf4b13110abd81b03697b4e0" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" dependencies = [ - "phf_generator 0.10.0", - "phf_shared 0.10.0", - "proc-macro-hack", + "phf_generator 0.11.2", + "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.39", ] [[package]] @@ -3410,7 +3407,7 @@ dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", - "rustix 0.38.25", + "rustix 0.38.26", "tracing", "windows-sys 0.52.0", ] @@ -3628,15 +3625,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -3794,9 +3782,9 @@ dependencies = [ [[package]] name = "ring" -version = "0.17.6" +version = "0.17.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "684d5e6e18f669ccebf64a92236bb7db9a34f07be010e3627368182027180866" +checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" dependencies = [ "cc", "getrandom 0.2.11", @@ -3889,15 +3877,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.25" +version = "0.38.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" +checksum = "9470c4bf8246c8daf25f9598dca807fb6510347b1e1cfa55749113850c79d88a" dependencies = [ "bitflags 2.4.1", "errno", "libc", - "linux-raw-sys 0.4.11", - "windows-sys 0.48.0", + "linux-raw-sys 0.4.12", + "windows-sys 0.52.0", ] [[package]] @@ -4641,9 +4629,9 @@ checksum = "14c39fd04924ca3a864207c66fc2cd7d22d7c016007f9ce846cbb9326331930a" [[package]] name = "tauri" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bfe673cf125ef364d6f56b15e8ce7537d9ca7e4dae1cf6fbbdeed2e024db3d9" +checksum = "32d563b672acde8d0cc4c1b1f5b855976923f67e8d6fe1eba51df0211e197be2" dependencies = [ "anyhow", "base64 0.21.5", @@ -4745,9 +4733,9 @@ dependencies = [ [[package]] name = "tauri-macros" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613740228de92d9196b795ac455091d3a5fbdac2654abb8bb07d010b62ab43af" +checksum = "acea6445eececebd72ed7720cfcca46eee3b5bad8eb408be8f7ef2e3f7411500" dependencies = [ "heck 0.4.1", "proc-macro2", @@ -4780,9 +4768,9 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8141d72b6b65f2008911e9ef5b98a68d1e3413b7a1464e8f85eb3673bb19a895" +checksum = "803a01101bc611ba03e13329951a1bde44287a54234189b9024b78619c1bc206" dependencies = [ "cocoa 0.24.1", "gtk", @@ -4800,9 +4788,9 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34d55e185904a84a419308d523c2c6891d5e2dbcee740c4997eb42e75a7b0f46" +checksum = "a52165bb340e6f6a75f1f5eeeab1bb49f861c12abe3a176067d53642b5454986" dependencies = [ "brotli", "ctor", @@ -4810,12 +4798,12 @@ dependencies = [ "glob", "heck 0.4.1", "html5ever 0.26.0", - "infer 0.12.0", + "infer 0.13.0", "json-patch", "kuchikiki", "log 0.4.20", "memchr", - "phf 0.10.1", + "phf 0.11.2", "proc-macro2", "quote", "semver 1.0.20", @@ -4825,7 +4813,7 @@ dependencies = [ "thiserror", "url", "walkdir", - "windows 0.39.0", + "windows-version", ] [[package]] @@ -4856,8 +4844,8 @@ checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", "fastrand 2.0.1", - "redox_syscall 0.4.1", - "rustix 0.38.25", + "redox_syscall", + "rustix 0.38.26", "windows-sys 0.48.0", ] @@ -5330,9 +5318,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" [[package]] name = "unicode-ident" @@ -5731,7 +5719,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.25", + "rustix 0.38.26", ] [[package]] @@ -5958,6 +5946,15 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f838de2fe15fe6bac988e74b798f26499a8b21a9d97edec321e79b28d1d7f597" +[[package]] +name = "windows-version" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75aa004c988e080ad34aff5739c39d0312f4684699d6d71fc8a198d057b8b9b4" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -6146,9 +6143,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.19" +version = "0.5.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +checksum = "b7e87b8dfbe3baffbe687eef2e164e32286eff31a5ee16463ce03d991643ec94" dependencies = [ "memchr", ] @@ -6337,18 +6334,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.26" +version = "0.7.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0" +checksum = "5d075cf85bbb114e933343e087b92f2146bac0d55b534cbb8188becf0039948e" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.26" +version = "0.7.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" +checksum = "86cd5ca076997b97ef09d3ad65efe811fa68c9e874cb636ccb211223a813b0c2" dependencies = [ "proc-macro2", "quote", diff --git a/backend/tauri/Cargo.toml b/backend/tauri/Cargo.toml index f1d6102276..c383f0f44b 100644 --- a/backend/tauri/Cargo.toml +++ b/backend/tauri/Cargo.toml @@ -32,15 +32,15 @@ serde_yaml = "0.9" auto-launch = "0.5" once_cell = "1.14.0" port_scanner = "0.1.5" -delay_timer = "0.11.1" +delay_timer = "0.11.4" parking_lot = "0.12.0" tokio = { version = "1", features = ["full"] } serde = { version = "1.0", features = ["derive"] } reqwest = { version = "0.11", features = ["json", "rustls-tls"] } -tauri = { version = "1.2.4", features = ["global-shortcut-all", "notification-all", "process-all", "shell-all", "system-tray", "updater", "window-all"] } +tauri = { version = "1.5.3", features = ["global-shortcut-all", "notification-all", "process-all", "shell-all", "system-tray", "updater", "window-all"] } window-vibrancy = { version = "0.3.0" } -window-shadows = { version = "0.2.0" } -wry = { version = "0.24.3" } +window-shadows = { version = "0.2.2" } +wry = { version = "0.24.6" } [target.'cfg(windows)'.dependencies] @@ -53,7 +53,7 @@ windows-sys = { version = "0.48", features = [ ] } [target.'cfg(windows)'.dependencies.tauri] -version = "1.2.4" +version = "1.5.3" features = [ "global-shortcut-all", "icon-png", @@ -65,7 +65,7 @@ features = [ ] [target.'cfg(linux)'.dependencies.tauri] -version = "1.2.4" +version = "1.5.3" features = [ "global-shortcut-all", "process-all", diff --git a/backend/tauri/src/cmds.rs b/backend/tauri/src/cmds.rs index bd549ad1ee..1e4937b2fa 100644 --- a/backend/tauri/src/cmds.rs +++ b/backend/tauri/src/cmds.rs @@ -2,7 +2,7 @@ use crate::{ config::*, core::*, feat, - utils::{dirs, help}, + utils::{dirs, help, resolve::save_window_state}, }; use crate::{ret_err, wrap_err}; use anyhow::{Context, Result}; @@ -234,6 +234,12 @@ pub fn open_web_url(url: String) -> CmdResult<()> { wrap_err!(open::that(url)) } +#[tauri::command] +pub fn save_window_size_state() -> CmdResult<()> { + let handle = handle::Handle::global().app_handle.lock().clone().unwrap(); + wrap_err!(save_window_state(&handle, true)) +} + #[cfg(windows)] pub mod uwp { use super::*; diff --git a/backend/tauri/src/config/verge.rs b/backend/tauri/src/config/verge.rs index d4d7d3ce9d..1be38b0469 100644 --- a/backend/tauri/src/config/verge.rs +++ b/backend/tauri/src/config/verge.rs @@ -87,9 +87,13 @@ pub struct IVerge { pub proxy_layout_column: Option, /// window size and position + #[deprecated(note = "use `window_size_state` instead")] #[serde(skip_serializing_if = "Option::is_none")] pub window_size_position: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub window_size_state: Option, + /// 是否启用随机端口 pub enable_random_port: Option, @@ -97,6 +101,16 @@ pub struct IVerge { pub verge_mixed_port: Option, } +#[derive(Default, Debug, Clone, Deserialize, Serialize)] +pub struct WindowState { + pub width: f64, + pub height: f64, + pub x: f64, + pub y: f64, + pub maximized: bool, + pub fullscreen: bool, +} + #[derive(Default, Debug, Clone, Deserialize, Serialize)] pub struct IVergeTheme { pub primary_color: Option, @@ -202,6 +216,7 @@ impl IVerge { patch!(enable_clash_fields); patch!(window_size_position); + patch!(window_size_state); } /// 在初始化前尝试拿到单例端口的值 diff --git a/backend/tauri/src/main.rs b/backend/tauri/src/main.rs index 3a84b3d253..76a0a8cfbf 100644 --- a/backend/tauri/src/main.rs +++ b/backend/tauri/src/main.rs @@ -64,6 +64,7 @@ fn main() -> std::io::Result<()> { cmds::delete_profile, cmds::read_profile_file, cmds::save_profile_file, + cmds::save_window_size_state, // service mode cmds::service::check_service, cmds::service::install_service, @@ -111,7 +112,7 @@ fn main() -> std::io::Result<()> { match event { tauri::WindowEvent::CloseRequested { api, .. } => { api.prevent_close(); - let _ = resolve::save_window_size_position(&app_handle, true); + let _ = resolve::save_window_state(app_handle, true); app_handle.get_window("main").map(|win| { let _ = win.hide(); @@ -126,10 +127,12 @@ fn main() -> std::io::Result<()> { if label == "main" { match event { tauri::WindowEvent::CloseRequested { .. } => { - let _ = resolve::save_window_size_position(&app_handle, true); + // log::info!(target: "app", "window close requested"); + let _ = resolve::save_window_state(app_handle, true); } tauri::WindowEvent::Moved(_) | tauri::WindowEvent::Resized(_) => { - let _ = resolve::save_window_size_position(&app_handle, false); + // log::info!(target: "app", "window moved or resized"); + let _ = resolve::save_window_state(app_handle, false); } _ => {} } diff --git a/backend/tauri/src/utils/resolve.rs b/backend/tauri/src/utils/resolve.rs index 3d001483b8..281ab4f075 100644 --- a/backend/tauri/src/utils/resolve.rs +++ b/backend/tauri/src/utils/resolve.rs @@ -1,7 +1,8 @@ -use crate::config::IVerge; +use crate::config::{IVerge, WindowState}; use crate::{config::Config, core::*, utils::init, utils::server}; use crate::{log_err, trace_err}; use anyhow::Result; +use serde::de; use serde_yaml::Mapping; use std::net::TcpListener; use tauri::{App, AppHandle, Manager}; @@ -109,14 +110,12 @@ pub fn create_window(app_handle: &AppHandle) { .title("Clash Nyanpasu") .fullscreen(false) .min_inner_size(600.0, 520.0); - - match Config::verge().latest().window_size_position.clone() { - Some(size_pos) if size_pos.len() == 4 => { - let size = (size_pos[0], size_pos[1]); - let pos = (size_pos[2], size_pos[3]); - let w = size.0.clamp(600.0, f64::INFINITY); - let h = size.1.clamp(520.0, f64::INFINITY); - builder = builder.inner_size(w, h).position(pos.0, pos.1); + let win_state = &Config::verge().latest().window_size_state.clone(); + match win_state { + Some(state) => { + builder = builder + .inner_size(state.width, state.height) + .position(state.x, state.y) } _ => { #[cfg(target_os = "windows")] @@ -149,6 +148,14 @@ pub fn create_window(app_handle: &AppHandle) { .build() { Ok(win) => { + if let Some(state) = win_state { + if state.maximized { + trace_err!(win.maximize(), "set win maximize"); + } + if state.fullscreen { + trace_err!(win.set_fullscreen(true), "set win fullscreen"); + } + } log::trace!("try to calculate the monitor size"); let center = (|| -> Result { let mut center = false; @@ -175,7 +182,7 @@ pub fn create_window(app_handle: &AppHandle) { // 加点延迟避免界面闪一下 tauri::async_runtime::spawn(async move { - sleep(Duration::from_millis(888)).await; + // sleep(Duration::from_millis(888)).await; if let Some(window) = app_handle.get_window("main") { trace_err!(set_shadow(&window, true), "set win shadow"); @@ -203,6 +210,7 @@ pub fn create_window(app_handle: &AppHandle) { } /// save window size and position +#[deprecated] pub fn save_window_size_position(app_handle: &AppHandle, save_to_file: bool) -> Result<()> { let win = app_handle .get_window("main") @@ -224,3 +232,45 @@ pub fn save_window_size_position(app_handle: &AppHandle, save_to_file: bool) -> Ok(()) } + +pub fn save_window_state(app_handle: &AppHandle, save_to_file: bool) -> Result<()> { + let win = app_handle + .get_window("main") + .ok_or(anyhow::anyhow!("failed to get window"))?; + let current_monitor = win.current_monitor()?; + let verge = Config::verge(); + let mut verge = verge.latest(); + match current_monitor { + Some(monitor) => { + let previous_state = verge.window_size_state.clone().unwrap_or_default(); + let mut state = WindowState { + maximized: win.is_maximized()?, + fullscreen: win.is_fullscreen()?, + ..previous_state + }; + let is_minimized = win.is_minimized()?; + + let scale_factor = monitor.scale_factor(); + let size = win.inner_size()?.to_logical(scale_factor); + if size.width > 0. && size.height > 0. && !state.maximized && !is_minimized { + state.width = size.width; + state.height = size.height; + } + let position = win.outer_position()?.to_logical(scale_factor); + if !state.maximized && !is_minimized { + state.x = position.x; + state.y = position.y; + } + verge.window_size_state = Some(state); + } + None => { + verge.window_size_state = None; + } + } + + if save_to_file { + verge.save_file()?; + } + + Ok(()) +} diff --git a/package.json b/package.json index 4213ba2af5..d6a5cc30ef 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@mui/lab": "5.0.0-alpha.149", "@mui/material": "^5.14.14", "@mui/x-data-grid": "^6.16.3", - "@tauri-apps/api": "^1.3.0", + "@tauri-apps/api": "^1.5.1", "ahooks": "^3.7.2", "axios": "^1.1.3", "dayjs": "1.11.5", @@ -70,7 +70,7 @@ "@actions/github": "^5.0.3", "@commitlint/cli": "18.4.3", "@commitlint/config-conventional": "18.4.3", - "@tauri-apps/cli": "^1.3.1", + "@tauri-apps/cli": "^1.5.7", "@types/fs-extra": "^9.0.13", "@types/js-cookie": "^3.0.2", "@types/lodash": "^4.14.180", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index da7fe91b03..7593dd16d4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,8 +36,8 @@ dependencies: specifier: ^6.16.3 version: 6.16.3(@mui/material@5.14.14)(@mui/system@5.14.14)(@types/react@18.2.37)(react-dom@18.2.0)(react@18.2.0) '@tauri-apps/api': - specifier: ^1.3.0 - version: 1.3.0 + specifier: ^1.5.1 + version: 1.5.1 ahooks: specifier: ^3.7.2 version: 3.7.2(react@18.2.0) @@ -104,8 +104,8 @@ devDependencies: specifier: 18.4.3 version: 18.4.3 '@tauri-apps/cli': - specifier: ^1.3.1 - version: 1.3.1 + specifier: ^1.5.7 + version: 1.5.7 '@types/fs-extra': specifier: ^9.0.13 version: 9.0.13 @@ -1729,13 +1729,13 @@ packages: - supports-color dev: true - /@tauri-apps/api@1.3.0: - resolution: {integrity: sha512-AH+3FonkKZNtfRtGrObY38PrzEj4d+1emCbwNGu0V2ENbXjlLHMZQlUh+Bhu/CRmjaIwZMGJ3yFvWaZZgTHoog==} + /@tauri-apps/api@1.5.1: + resolution: {integrity: sha512-6unsZDOdlXTmauU3NhWhn+Cx0rODV+rvNvTdvolE5Kls5ybA6cqndQENDt1+FS0tF7ozCP66jwWoH6a5h90BrA==} engines: {node: '>= 14.6.0', npm: '>= 6.6.0', yarn: '>= 1.19.1'} dev: false - /@tauri-apps/cli-darwin-arm64@1.3.1: - resolution: {integrity: sha512-QlepYVPgOgspcwA/u4kGG4ZUijlXfdRtno00zEy+LxinN/IRXtk+6ErVtsmoLi1ZC9WbuMwzAcsRvqsD+RtNAg==} + /@tauri-apps/cli-darwin-arm64@1.5.7: + resolution: {integrity: sha512-eUpOUhs2IOpKaLa6RyGupP2owDLfd0q2FR/AILzryjtBtKJJRDQQvuotf+LcbEce2Nc2AHeYJIqYAsB4sw9K+g==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] @@ -1743,8 +1743,8 @@ packages: dev: true optional: true - /@tauri-apps/cli-darwin-x64@1.3.1: - resolution: {integrity: sha512-fKcAUPVFO3jfDKXCSDGY0MhZFF/wDtx3rgFnogWYu4knk38o9RaqRkvMvqJhLYPuWaEM5h6/z1dRrr9KKCbrVg==} + /@tauri-apps/cli-darwin-x64@1.5.7: + resolution: {integrity: sha512-zfumTv1xUuR+RB1pzhRy+51tB6cm8I76g0xUBaXOfEdOJ9FqW5GW2jdnEUbpNuU65qJ1lB8LVWHKGrSWWKazew==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] @@ -1752,8 +1752,8 @@ packages: dev: true optional: true - /@tauri-apps/cli-linux-arm-gnueabihf@1.3.1: - resolution: {integrity: sha512-+4H0dv8ltJHYu/Ma1h9ixUPUWka9EjaYa8nJfiMsdCI4LJLNE6cPveE7RmhZ59v9GW1XB108/k083JUC/OtGvA==} + /@tauri-apps/cli-linux-arm-gnueabihf@1.5.7: + resolution: {integrity: sha512-JngWNqS06bMND9PhiPWp0e+yknJJuSozsSbo+iMzHoJNRauBZCUx+HnUcygUR66Cy6qM4eJvLXtsRG7ApxvWmg==} engines: {node: '>= 10'} cpu: [arm] os: [linux] @@ -1761,8 +1761,8 @@ packages: dev: true optional: true - /@tauri-apps/cli-linux-arm64-gnu@1.3.1: - resolution: {integrity: sha512-Pj3odVO1JAxLjYmoXKxcrpj/tPxcA8UP8N06finhNtBtBaxAjrjjxKjO4968KB0BUH7AASIss9EL4Tr0FGnDuw==} + /@tauri-apps/cli-linux-arm64-gnu@1.5.7: + resolution: {integrity: sha512-WyIYP9BskgBGq+kf4cLAyru8ArrxGH2eMYGBJvuNEuSaqBhbV0i1uUxvyWdazllZLAEz1WvSocUmSwLknr1+sQ==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -1770,8 +1770,8 @@ packages: dev: true optional: true - /@tauri-apps/cli-linux-arm64-musl@1.3.1: - resolution: {integrity: sha512-tA0JdDLPFaj42UDIVcF2t8V0tSha40rppcmAR/MfQpTCxih6399iMjwihz9kZE1n4b5O4KTq9GliYo50a8zYlQ==} + /@tauri-apps/cli-linux-arm64-musl@1.5.7: + resolution: {integrity: sha512-OrDpihQP2MB0JY1a/wP9wsl9dDjFDpVEZOQxt4hU+UVGRCZQok7ghPBg4+Xpd1CkNkcCCuIeY8VxRvwLXpnIzg==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] @@ -1779,8 +1779,8 @@ packages: dev: true optional: true - /@tauri-apps/cli-linux-x64-gnu@1.3.1: - resolution: {integrity: sha512-FDU+Mnvk6NLkqQimcNojdKpMN4Y3W51+SQl+NqG9AFCWprCcSg62yRb84751ujZuf2MGT8HQOfmd0i77F4Q3tQ==} + /@tauri-apps/cli-linux-x64-gnu@1.5.7: + resolution: {integrity: sha512-4T7FAYVk76rZi8VkuLpiKUAqaSxlva86C1fHm/RtmoTKwZEV+MI3vIMoVg+AwhyWIy9PS55C75nF7+OwbnFnvQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -1788,8 +1788,8 @@ packages: dev: true optional: true - /@tauri-apps/cli-linux-x64-musl@1.3.1: - resolution: {integrity: sha512-MpO3akXFmK8lZYEbyQRDfhdxz1JkTBhonVuz5rRqxwA7gnGWHa1aF1+/2zsy7ahjB2tQ9x8DDFDMdVE20o9HrA==} + /@tauri-apps/cli-linux-x64-musl@1.5.7: + resolution: {integrity: sha512-LL9aMK601BmQjAUDcKWtt5KvAM0xXi0iJpOjoUD3LPfr5dLvBMTflVHQDAEtuZexLQyqpU09+60781PrI/FCTw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] @@ -1797,8 +1797,17 @@ packages: dev: true optional: true - /@tauri-apps/cli-win32-ia32-msvc@1.3.1: - resolution: {integrity: sha512-9Boeo3K5sOrSBAZBuYyGkpV2RfnGQz3ZhGJt4hE6P+HxRd62lS6+qDKAiw1GmkZ0l1drc2INWrNeT50gwOKwIQ==} + /@tauri-apps/cli-win32-arm64-msvc@1.5.7: + resolution: {integrity: sha512-TmAdM6GVkfir3AUFsDV2gyc25kIbJeAnwT72OnmJGAECHs/t/GLP9IkFLLVcFKsiosRf8BXhVyQ84NYkSWo14w==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@tauri-apps/cli-win32-ia32-msvc@1.5.7: + resolution: {integrity: sha512-bqWfxwCfLmrfZy69sEU19KHm5TFEaMb8KIekd4aRq/kyOlrjKLdZxN1PyNRP8zpJA1lTiRHzfUDfhpmnZH/skg==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] @@ -1806,8 +1815,8 @@ packages: dev: true optional: true - /@tauri-apps/cli-win32-x64-msvc@1.3.1: - resolution: {integrity: sha512-wMrTo91hUu5CdpbElrOmcZEoJR4aooTG+fbtcc87SMyPGQy1Ux62b+ZdwLvL1sVTxnIm//7v6QLRIWGiUjCPwA==} + /@tauri-apps/cli-win32-x64-msvc@1.5.7: + resolution: {integrity: sha512-OxLHVBNdzyQ//xT3kwjQFnJTn/N5zta/9fofAkXfnL7vqmVn6s/RY1LDa3sxCHlRaKw0n3ShpygRbM9M8+sO9w==} engines: {node: '>= 10'} cpu: [x64] os: [win32] @@ -1815,20 +1824,21 @@ packages: dev: true optional: true - /@tauri-apps/cli@1.3.1: - resolution: {integrity: sha512-o4I0JujdITsVRm3/0spfJX7FcKYrYV1DXJqzlWIn6IY25/RltjU6qbC1TPgVww3RsRX63jyVUTcWpj5wwFl+EQ==} + /@tauri-apps/cli@1.5.7: + resolution: {integrity: sha512-z7nXLpDAYfQqR5pYhQlWOr88DgPq1AfQyxHhGiakiVgWlaG0ikEfQxop2txrd52H0TRADG0JHR9vFrVFPv4hVQ==} engines: {node: '>= 10'} hasBin: true optionalDependencies: - '@tauri-apps/cli-darwin-arm64': 1.3.1 - '@tauri-apps/cli-darwin-x64': 1.3.1 - '@tauri-apps/cli-linux-arm-gnueabihf': 1.3.1 - '@tauri-apps/cli-linux-arm64-gnu': 1.3.1 - '@tauri-apps/cli-linux-arm64-musl': 1.3.1 - '@tauri-apps/cli-linux-x64-gnu': 1.3.1 - '@tauri-apps/cli-linux-x64-musl': 1.3.1 - '@tauri-apps/cli-win32-ia32-msvc': 1.3.1 - '@tauri-apps/cli-win32-x64-msvc': 1.3.1 + '@tauri-apps/cli-darwin-arm64': 1.5.7 + '@tauri-apps/cli-darwin-x64': 1.5.7 + '@tauri-apps/cli-linux-arm-gnueabihf': 1.5.7 + '@tauri-apps/cli-linux-arm64-gnu': 1.5.7 + '@tauri-apps/cli-linux-arm64-musl': 1.5.7 + '@tauri-apps/cli-linux-x64-gnu': 1.5.7 + '@tauri-apps/cli-linux-x64-musl': 1.5.7 + '@tauri-apps/cli-win32-arm64-msvc': 1.5.7 + '@tauri-apps/cli-win32-ia32-msvc': 1.5.7 + '@tauri-apps/cli-win32-x64-msvc': 1.5.7 dev: true /@types/babel__core@7.20.3: diff --git a/src/components/layout/layout-control.tsx b/src/components/layout/layout-control.tsx index 7aa29fb661..d50986807e 100644 --- a/src/components/layout/layout-control.tsx +++ b/src/components/layout/layout-control.tsx @@ -1,3 +1,4 @@ +import { save_window_size_state } from "@/services/cmds"; import { CloseRounded, CropSquareRounded, @@ -5,15 +6,22 @@ import { HorizontalRuleRounded, } from "@mui/icons-material"; import { Button } from "@mui/material"; +import { platform, type Platform } from "@tauri-apps/api/os"; import { appWindow } from "@tauri-apps/api/window"; -import { useState } from "react"; +import { useEffect, useState } from "react"; export const LayoutControl = () => { const minWidth = 40; const [isMaximized, setIsMaximized] = useState(false); - appWindow.isMaximized().then((isMaximized) => { - setIsMaximized(() => isMaximized); - }); + const [platfrom, setPlatform] = useState("win32"); + useEffect(() => { + appWindow.isMaximized().then((isMaximized) => { + setIsMaximized(() => isMaximized); + }); + platform().then((platform) => { + setPlatform(() => platform); + }); + }, []); return ( <> diff --git a/src/services/cmds.ts b/src/services/cmds.ts index 1e1222dd93..bab985a4b5 100644 --- a/src/services/cmds.ts +++ b/src/services/cmds.ts @@ -1,6 +1,6 @@ -import dayjs from "dayjs"; -import { invoke } from "@tauri-apps/api/tauri"; import { useNotification } from "@/hooks/use-notification"; +import { invoke } from "@tauri-apps/api/tauri"; +import dayjs from "dayjs"; export async function getClashLogs() { const regex = /time="(.+?)"\s+level=(.+?)\s+msg="(.+?)"/; @@ -186,3 +186,9 @@ export async function invoke_uwp_tool() { useNotification("Error", err?.message || err.toString()), ); } + +export async function save_window_size_state() { + return invoke("save_window_size_state").catch((err) => + useNotification("Error", err?.message || err.toString()), + ); +}