diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d051a37..912d5c8 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -27,6 +27,24 @@ fn show_main(app: &tauri::AppHandle) { /// CustomEvent the client listens for (see useDeepLinkNavigate.ts). Uses /// `eval` so we don't need the @tauri-apps/api event package on the web side. fn forward_deeplink(app: &tauri::AppHandle, url: &str) { + // Dedupe: on a cold start the deep-link plugin's `on_open_url` AND the argv + // fallback (`matrix_url_from_args(std::env::args())`) can both forward the + // same launch URL, navigating the room twice (re-show/re-focus + a duplicate + // `lotus-deeplink`). Drop a repeat of the same URL within a short window. + { + use std::sync::Mutex; + use std::time::{Duration, Instant}; + static LAST: Mutex> = Mutex::new(None); + if let Ok(mut last) = LAST.lock() { + let now = Instant::now(); + if let Some((prev_url, prev_at)) = last.as_ref() { + if prev_url == url && now.duration_since(*prev_at) < Duration::from_millis(1000) { + return; + } + } + *last = Some((url.to_string(), now)); + } + } show_main(app); if let Some(window) = app.get_webview_window("main") { if let Ok(json) = serde_json::to_string(url) {