Skip to content

Commit

Permalink
Save window state on quit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Nov 26, 2023
1 parent 41d1a76 commit 166dd79
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7",
"tauri-plugin-websocket-api": "github:tauri-apps/tauri-plugin-websocket#v1",
"tauri-plugin-window-state-api": "github:tauri-apps/tauri-plugin-window-state#v1",
"uuid": "^9.0.1",
"zustand": "^4.4.5"
},
Expand Down
6 changes: 5 additions & 1 deletion apps/desktop/src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use tauri::{
AppHandle, CustomMenuItem, LogicalSize, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu,
};
use tauri_plugin_window_state::{AppHandleExt, StateFlags};

use crate::{
commands::{set_clickthrough, toggle_clickthrough},
Expand Down Expand Up @@ -69,7 +70,10 @@ pub fn handle_tray_events(app: &AppHandle, event: SystemTrayEvent) {
let window = app.get_window(MAIN_WINDOW_NAME).unwrap();
window.open_devtools();
}
TRAY_QUIT => std::process::exit(0),
TRAY_QUIT => {
app.save_window_state(StateFlags::all()); // will save the state of all open windows to disk
std::process::exit(0)
}
_ => {}
},
_ => {}
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/views/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { appConfigDir } from "@tauri-apps/api/path";
import { platform as getPlatform, version as getKernalVersion, arch as getArch } from "@tauri-apps/api/os";
import * as dateFns from "date-fns";
import { shell } from "@tauri-apps/api";
import { saveWindowState, StateFlags } from "tauri-plugin-window-state-api";

import {
Dialog,
DialogTrigger,
Expand Down Expand Up @@ -193,6 +195,7 @@ export const SettingsView = () => {
<form
onSubmit={async event => {
event.preventDefault();
await saveWindowState(StateFlags.ALL);
await exit();
}}
>
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 166dd79

Please sign in to comment.