Skip to content

Commit 7370e12

Browse files
committed
refactor: use tauri window position restore plugins instead of self impl
1 parent e4b12cc commit 7370e12

5 files changed

Lines changed: 74 additions & 89 deletions

File tree

src-tauri/Cargo.lock

Lines changed: 60 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ serde = { version = "1.0", features = ["derive"] }
2222
tauri = { version = "1.5.2", features = [ "cli", "api-all", "updater", "devtools", "linux-protocol-headers"] }
2323
winapi = { version = "0.3", features = ["fileapi"] }
2424
tauri-plugin-fs-extra = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
25+
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
2526

2627
[features]
2728
# by default Tauri runs in production mode

src-tauri/src/boot_config.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ pub static APP_CONSTANTS: OnceCell<AppConstants> = OnceCell::new();
1515

1616
#[derive(Serialize)]
1717
pub struct BootConfig {
18-
pub last_window_width: u32,
19-
pub last_window_height: u32,
18+
pub version: u32
2019
}
2120
static BOOT_CONFIG_FILE_NAME: &'static str = "boot_config.json";
2221

@@ -27,20 +26,15 @@ fn get_boot_config_file_path(app_local_data_dir: &PathBuf) -> PathBuf {
2726
}
2827

2928
fn _set_boot_config(boot_config: &mut BootConfig, value: &Value) {
30-
boot_config.last_window_width = match value["last_window_width"].as_u64() {
31-
Some(value) => value as u32,
32-
None => 0
33-
};
34-
boot_config.last_window_height = match value["last_window_height"].as_u64() {
29+
boot_config.version = match value["version"].as_u64() {
3530
Some(value) => value as u32,
3631
None => 0
3732
};
3833
}
3934

4035
pub fn read_boot_config() -> BootConfig {
4136
let mut boot_config = BootConfig {
42-
last_window_width: 0,
43-
last_window_height: 0
37+
version: 1
4438
};
4539
if let Some(app_constants) = APP_CONSTANTS.get() {
4640
let boot_config_file_path = get_boot_config_file_path(&app_constants.app_local_data_dir);
@@ -67,9 +61,9 @@ fn _write_boot_config(boot_config: &BootConfig) {
6761
}
6862
}
6963

70-
pub fn write_boot_config(last_window_width: u32, last_window_height: u32) {
64+
// WARNING: If there are multiple windows, this will be called on each window close.
65+
pub fn write_boot_config(version: u32) {
7166
_write_boot_config(&BootConfig {
72-
last_window_width,
73-
last_window_height
67+
version
7468
})
7569
}

0 commit comments

Comments
 (0)