Skip to content

Commit b2aea04

Browse files
authored
fix(deep-link): Remove getCurrent call in onOpenUrl (#2008)
1 parent 3449dd5 commit b2aea04

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
deep-link: patch
3+
deep-link-js: patch
4+
---
5+
6+
`onOpenUrl()` will now not call `getCurrent()` anymore, matching the documented behavior.

plugins/deep-link/guest-js/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ export async function isRegistered(protocol: string): Promise<boolean> {
9999
export async function onOpenUrl(
100100
handler: (urls: string[]) => void
101101
): Promise<UnlistenFn> {
102-
const current = await getCurrent()
103-
if (current) {
104-
handler(current)
105-
}
106-
107102
return await listen<string[]>('deep-link://new-url', (event) => {
108103
handler(event.payload)
109104
})

plugins/deep-link/src/lib.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use std::sync::Arc;
6-
75
use tauri::{
86
plugin::{Builder, PluginApi, TauriPlugin},
97
AppHandle, EventId, Listener, Manager, Runtime,
@@ -478,13 +476,10 @@ impl OpenUrlEvent {
478476
}
479477

480478
impl<R: Runtime> DeepLink<R> {
481-
/// Handle a new deep link being triggered to open the app.
479+
/// Helper function for the `deep-link://new-url` event to run a function each time the protocol is triggered while the app is running.
482480
///
483-
/// To avoid race conditions, if the app was started with a deep link,
484-
/// the closure gets immediately called with the deep link URL.
481+
/// Use `get_current` on app load to check whether your app was started via a deep link.
485482
pub fn on_open_url<F: Fn(OpenUrlEvent) + Send + Sync + 'static>(&self, f: F) -> EventId {
486-
let f = Arc::new(f);
487-
let f_ = f.clone();
488483
let event_id = self.app.listen("deep-link://new-url", move |event| {
489484
if let Ok(urls) = serde_json::from_str(event.payload()) {
490485
f(OpenUrlEvent {
@@ -494,13 +489,6 @@ impl<R: Runtime> DeepLink<R> {
494489
}
495490
});
496491

497-
if let Ok(Some(current)) = self.get_current() {
498-
f_(OpenUrlEvent {
499-
id: event_id,
500-
urls: current,
501-
})
502-
}
503-
504492
event_id
505493
}
506494
}

0 commit comments

Comments
 (0)