diff --git a/.changes/fix-deep-link-onopenurl-current.md b/.changes/fix-deep-link-onopenurl-current.md new file mode 100644 index 00000000..3ede6ebd --- /dev/null +++ b/.changes/fix-deep-link-onopenurl-current.md @@ -0,0 +1,6 @@ +--- +deep-link: patch +deep-link-js: patch +--- + +`onOpenUrl()` will now not call `getCurrent()` anymore, matching the documented behavior. diff --git a/plugins/deep-link/guest-js/index.ts b/plugins/deep-link/guest-js/index.ts index 49afbab7..c9190d7a 100644 --- a/plugins/deep-link/guest-js/index.ts +++ b/plugins/deep-link/guest-js/index.ts @@ -99,11 +99,6 @@ export async function isRegistered(protocol: string): Promise { export async function onOpenUrl( handler: (urls: string[]) => void ): Promise { - const current = await getCurrent() - if (current) { - handler(current) - } - return await listen('deep-link://new-url', (event) => { handler(event.payload) }) diff --git a/plugins/deep-link/src/lib.rs b/plugins/deep-link/src/lib.rs index 25cdd317..19065e40 100644 --- a/plugins/deep-link/src/lib.rs +++ b/plugins/deep-link/src/lib.rs @@ -2,8 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use std::sync::Arc; - use tauri::{ plugin::{Builder, PluginApi, TauriPlugin}, AppHandle, EventId, Listener, Manager, Runtime, @@ -478,13 +476,10 @@ impl OpenUrlEvent { } impl DeepLink { - /// Handle a new deep link being triggered to open the app. + /// Helper function for the `deep-link://new-url` event to run a function each time the protocol is triggered while the app is running. /// - /// To avoid race conditions, if the app was started with a deep link, - /// the closure gets immediately called with the deep link URL. + /// Use `get_current` on app load to check whether your app was started via a deep link. pub fn on_open_url(&self, f: F) -> EventId { - let f = Arc::new(f); - let f_ = f.clone(); let event_id = self.app.listen("deep-link://new-url", move |event| { if let Ok(urls) = serde_json::from_str(event.payload()) { f(OpenUrlEvent { @@ -494,13 +489,6 @@ impl DeepLink { } }); - if let Ok(Some(current)) = self.get_current() { - f_(OpenUrlEvent { - id: event_id, - urls: current, - }) - } - event_id } }