summarylogtreecommitdiffstats
path: root/single_instance_support.patch
blob: 0069385b819e4fa34b24e3024fe964f4ea69268f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
From ababdf4ae3f10f94241f14c1c87a2f6ba05d7557 Mon Sep 17 00:00:00 2001
From: bytedream <me@bytedream.dev>
Date: Wed, 29 Oct 2025 15:40:28 +0100
Subject: [PATCH] add single instance support

---
 src-tauri/Cargo.toml  |  1 +
 src-tauri/src/main.rs | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 371df47..bc354dd 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -19,6 +19,7 @@ serde_json = "1.0.109"
 serde = { version = "1.0.193", features = ["derive"] }
 tauri = { version = "1.8.0", features = ["api-all", "devtools", "system-tray", "updater"] }
 tauri-plugin-localhost = "0.1.0"
+tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
 tauri-plugin-window-state = "0.1.1"
 
 [features]
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 0682873..02733d8 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -7,7 +7,7 @@
 mod menu;
 mod tray;
 
-use tauri::{utils::config::AppUrl, WindowUrl};
+use tauri::{utils::config::AppUrl, Manager, WindowUrl};
 
 fn main() {
     let port = 44548;
@@ -29,6 +29,14 @@ fn main() {
 
     builder
         .plugin(tauri_plugin_localhost::Builder::new(port).build())
+        .plugin(tauri_plugin_single_instance::init(|app, _, _| {
+            let window = app.get_window("main").unwrap();
+            let tray_handle = match app.tray_handle_by_id(tray::TRAY_LABEL) {
+                Some(h) => h,
+                None => return,
+            };
+            tray::toggle_window_state(window, tray_handle)
+        }))
         .plugin(tauri_plugin_window_state::Builder::default().build())
         .on_window_event(tray::window_event_handler)
         .run(context)
-- 
2.51.2