Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/fix-deep-link-onopenurl-current.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
deep-link: patch
deep-link-js: patch
---

`onOpenUrl()` will now not call `getCurrent()` anymore, matching the documented behavior.
5 changes: 0 additions & 5 deletions plugins/deep-link/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ export async function isRegistered(protocol: string): Promise<boolean> {
export async function onOpenUrl(
handler: (urls: string[]) => void
): Promise<UnlistenFn> {
const current = await getCurrent()
if (current) {
handler(current)
}

return await listen<string[]>('deep-link://new-url', (event) => {
handler(event.payload)
})
Expand Down
16 changes: 2 additions & 14 deletions plugins/deep-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -478,13 +476,10 @@ impl OpenUrlEvent {
}

impl<R: Runtime> DeepLink<R> {
/// 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<F: Fn(OpenUrlEvent) + Send + Sync + 'static>(&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 {
Expand All @@ -494,13 +489,6 @@ impl<R: Runtime> DeepLink<R> {
}
});

if let Ok(Some(current)) = self.get_current() {
f_(OpenUrlEvent {
id: event_id,
urls: current,
})
}

event_id
}
}
Expand Down
Loading