Skip to content

Commit 6055279

Browse files
authored
fix: prevent duplicate tray instances on relaunch (#1458)
1 parent 2af293a commit 6055279

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 16 additions & 0 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
@@ -54,6 +54,7 @@ async-trait = "0.1"
5454
tauri-plugin-os = "2.3.2"
5555
tauri-plugin-clipboard-manager = "2.3.2"
5656
tauri-plugin-opener = "2.5.3"
57+
tauri-plugin-single-instance = "2.4.2"
5758

5859
[dependencies.uuid]
5960
version = "1.23.1"

src-tauri/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ pub fn run() {
150150

151151
let mut tauri_builder = tauri::Builder::<Wry>::default()
152152
.invoke_handler(builder.invoke_handler())
153+
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
154+
lifecycle::on_second_instance(app);
155+
}))
153156
.setup(move |app| {
154157
let path_resolver = app.path();
155158

src-tauri/src/lifecycle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ pub fn on_close_requested(window: &Window) {
9393
});
9494
}
9595

96+
/// Hook into second launch attempts while this process is already running.
97+
pub fn on_second_instance(app: &tauri::AppHandle) {
98+
restore_main_window(app);
99+
}
100+
96101
/// Hook into app-level runtime events that affect the main window lifecycle.
97102
pub fn on_run_event(app: &tauri::AppHandle, event: tauri::RunEvent) {
98103
#[cfg(target_os = "macos")]

0 commit comments

Comments
 (0)