fix(deep-link): Remove getCurrent call in onOpenUrl (#2008)

pull/2032/head
Fabian-Lars 7 months ago committed by GitHub
parent 3449dd5a8f
commit b2aea04567
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,6 @@
---
deep-link: patch
deep-link-js: patch
---
`onOpenUrl()` will now not call `getCurrent()` anymore, matching the documented behavior.

@ -99,11 +99,6 @@ export async function isRegistered(protocol: string): Promise<boolean> {
export async function onOpenUrl( export async function onOpenUrl(
handler: (urls: string[]) => void handler: (urls: string[]) => void
): Promise<UnlistenFn> { ): Promise<UnlistenFn> {
const current = await getCurrent()
if (current) {
handler(current)
}
return await listen<string[]>('deep-link://new-url', (event) => { return await listen<string[]>('deep-link://new-url', (event) => {
handler(event.payload) handler(event.payload)
}) })

@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
use std::sync::Arc;
use tauri::{ use tauri::{
plugin::{Builder, PluginApi, TauriPlugin}, plugin::{Builder, PluginApi, TauriPlugin},
AppHandle, EventId, Listener, Manager, Runtime, AppHandle, EventId, Listener, Manager, Runtime,
@ -478,13 +476,10 @@ impl OpenUrlEvent {
} }
impl<R: Runtime> DeepLink<R> { 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, /// Use `get_current` on app load to check whether your app was started via a deep link.
/// the closure gets immediately called with the deep link URL.
pub fn on_open_url<F: Fn(OpenUrlEvent) + Send + Sync + 'static>(&self, f: F) -> EventId { 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| { let event_id = self.app.listen("deep-link://new-url", move |event| {
if let Ok(urls) = serde_json::from_str(event.payload()) { if let Ok(urls) = serde_json::from_str(event.payload()) {
f(OpenUrlEvent { f(OpenUrlEvent {
@ -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 event_id
} }
} }

Loading…
Cancel
Save