Skip to content

Commit

Permalink
Merge pull request #18 from ZeroKnowledgeNetwork/15-single-instance
Browse files Browse the repository at this point in the history
feat: restrict app to single running instance
  • Loading branch information
xendarboh authored Feb 25, 2025
2 parents 284a8f4 + 8494d28 commit 6fd3b91
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src-tauri/Cargo.lock

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

3 changes: 3 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ tauri-plugin-log = "2"
time = { version = "0.3", features = ["formatting"] }
tauri-plugin-store = "2"

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

19 changes: 19 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tauri::Manager;

// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn network_connect(network_id: &str) -> String {
Expand All @@ -7,6 +9,23 @@ fn network_connect(network_id: &str) -> String {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
// NOTE: Currently, plugins run in the order they were added in to the builder,
// so `tauri_plugin_single_instance` needs to be registered first.
// See: https://github.com/tauri-apps/plugins-workspace/tree/v2/plugins/single-instance
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
#[cfg(desktop)]
{
let windows = app.webview_windows();
for (name, window) in windows {
if name == "main" {
window.show().unwrap();
window.unminimize().unwrap();
window.set_focus().unwrap();
break;
}
}
}
}))
.plugin(tauri_plugin_store::Builder::new().build())
.plugin(
tauri_plugin_log::Builder::new()
Expand Down

0 comments on commit 6fd3b91

Please sign in to comment.