Skip to content

Commit 6fd3b91

Browse files
authored
Merge pull request #18 from ZeroKnowledgeNetwork/15-single-instance
feat: restrict app to single running instance
2 parents 284a8f4 + 8494d28 commit 6fd3b91

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src-tauri/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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ tauri-plugin-log = "2"
3131
time = { version = "0.3", features = ["formatting"] }
3232
tauri-plugin-store = "2"
3333

34+
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
35+
tauri-plugin-single-instance = "2"
36+

src-tauri/src/lib.rs

Lines changed: 19 additions & 0 deletions
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,6 +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()
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+
}))
1029
.plugin(tauri_plugin_store::Builder::new().build())
1130
.plugin(
1231
tauri_plugin_log::Builder::new()

0 commit comments

Comments
 (0)