Skip to content

Commit 8494d28

Browse files
committed
feat: enforce single instance by focusing existing window
1 parent dd3d46d commit 8494d28

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src-tauri/src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use tauri::Manager;
2+
13
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
24
#[tauri::command]
35
fn network_connect(network_id: &str) -> String {
@@ -7,7 +9,23 @@ fn network_connect(network_id: &str) -> String {
79
#[cfg_attr(mobile, tauri::mobile_entry_point)]
810
pub fn run() {
911
tauri::Builder::default()
10-
.plugin(tauri_plugin_single_instance::init())
12+
// NOTE: Currently, plugins run in the order they were added in to the builder,
13+
// so `tauri_plugin_single_instance` needs to be registered first.
14+
// See: https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/single-instance
15+
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
16+
#[cfg(desktop)]
17+
{
18+
let windows = app.webview_windows();
19+
for (name, window) in windows {
20+
if name == "main" {
21+
window.show().unwrap();
22+
window.unminimize().unwrap();
23+
window.set_focus().unwrap();
24+
break;
25+
}
26+
}
27+
}
28+
}))
1129
.plugin(tauri_plugin_store::Builder::new().build())
1230
.plugin(
1331
tauri_plugin_log::Builder::new()

0 commit comments

Comments
 (0)