From d4cc496725cc5181c9df784486ae5839865a2b62 Mon Sep 17 00:00:00 2001 From: Dung Nguyen Date: Thu, 18 Apr 2024 21:29:01 +0700 Subject: [PATCH] feat: save window state (#220) --- package.json | 1 + pnpm-lock.yaml | 16 ++++++++++++++++ src-tauri/Cargo.lock | 28 ++++++++++++++++++++++++++-- src-tauri/Cargo.toml | 1 + src-tauri/src/bin/defguard-client.rs | 1 + 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a7bdaef0..7e8e4847 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "rehype-sanitize": "^6.0.0", "rxjs": "^7.8.1", "tauri-plugin-log-api": "github:tauri-apps/tauri-plugin-log", + "tauri-plugin-window-state-api": "github:tauri-apps/tauri-plugin-window-state#v1", "use-breakpoint": "^4.0.1", "zod": "^3.22.4", "zustand": "^4.4.7" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 91835893..12b14990 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -116,6 +116,9 @@ dependencies: tauri-plugin-log-api: specifier: github:tauri-apps/tauri-plugin-log version: github.com/tauri-apps/tauri-plugin-log/a428c4c4833027865898ef0f284a69b1978fcd94 + tauri-plugin-window-state-api: + specifier: github:tauri-apps/tauri-plugin-window-state#v1 + version: github.com/tauri-apps/tauri-plugin-window-state/002cf15f6a1e4969a678a4ade680cd60477a8a53 use-breakpoint: specifier: ^4.0.1 version: 4.0.1(react-dom@18.2.0)(react@18.2.0) @@ -1420,6 +1423,11 @@ packages: engines: {node: '>= 14.6.0', npm: '>= 6.6.0', yarn: '>= 1.19.1'} dev: false + /@tauri-apps/api@1.5.3: + resolution: {integrity: sha512-zxnDjHHKjOsrIzZm6nO5Xapb/BxqUq1tc7cGkFXsFkGTsSWgCPH1D8mm0XS9weJY2OaR73I3k3S+b7eSzJDfqA==} + engines: {node: '>= 14.6.0', npm: '>= 6.6.0', yarn: '>= 1.19.1'} + dev: false + /@tauri-apps/cli-darwin-arm64@1.5.7: resolution: {integrity: sha512-eUpOUhs2IOpKaLa6RyGupP2owDLfd0q2FR/AILzryjtBtKJJRDQQvuotf+LcbEce2Nc2AHeYJIqYAsB4sw9K+g==} engines: {node: '>= 10'} @@ -7395,3 +7403,11 @@ packages: dependencies: '@tauri-apps/api': 1.5.1 dev: false + + github.com/tauri-apps/tauri-plugin-window-state/002cf15f6a1e4969a678a4ade680cd60477a8a53: + resolution: {tarball: https://codeload.github.com/tauri-apps/tauri-plugin-window-state/tar.gz/002cf15f6a1e4969a678a4ade680cd60477a8a53} + name: tauri-plugin-window-state-api + version: 0.0.0 + dependencies: + '@tauri-apps/api': 1.5.3 + dev: false diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 34c6b525..070ec4fe 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -491,6 +491,15 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -1199,6 +1208,7 @@ dependencies = [ "tauri-build", "tauri-plugin-log", "tauri-plugin-single-instance", + "tauri-plugin-window-state", "thiserror", "tokio", "tokio-util", @@ -5273,7 +5283,7 @@ dependencies = [ [[package]] name = "tauri-plugin-log" version = "0.0.0" -source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#775f7b88edd60df724f7e106ff748cdb967d851e" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#8cd4a39864986ae3600be9f23d089afd3988c43a" dependencies = [ "byte-unit", "fern", @@ -5288,7 +5298,7 @@ dependencies = [ [[package]] name = "tauri-plugin-single-instance" version = "0.0.0" -source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#775f7b88edd60df724f7e106ff748cdb967d851e" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#8cd4a39864986ae3600be9f23d089afd3988c43a" dependencies = [ "log", "serde", @@ -5299,6 +5309,20 @@ dependencies = [ "zbus", ] +[[package]] +name = "tauri-plugin-window-state" +version = "0.1.1" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#8cd4a39864986ae3600be9f23d089afd3988c43a" +dependencies = [ + "bincode", + "bitflags 2.4.1", + "log", + "serde", + "serde_json", + "tauri", + "thiserror", +] + [[package]] name = "tauri-runtime" version = "0.14.2" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 482baa24..916c0b5e 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -40,6 +40,7 @@ webbrowser = "0.8" tauri = { version = "1.5", features = [ "dialog-all", "clipboard-all", "http-all", "window-all", "system-tray", "native-tls-vendored", "icon-png", "fs-all"] } tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } +tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } thiserror = "1.0" tokio = { version = "1", features = ["macros", "rt-multi-thread"] } tokio-util = "0.7" diff --git a/src-tauri/src/bin/defguard-client.rs b/src-tauri/src/bin/defguard-client.rs index aa828692..1d792752 100644 --- a/src-tauri/src/bin/defguard-client.rs +++ b/src-tauri/src/bin/defguard-client.rs @@ -135,6 +135,7 @@ async fn main() { }) .build(), ) + .plugin(tauri_plugin_window_state::Builder::default().build()) .manage(AppState::default()) .build(tauri::generate_context!()) .expect("error while running tauri application");