diff --git a/src/content/docs/plugin/deep-linking.mdx b/src/content/docs/plugin/deep-linking.mdx index 402b94e64..2f4f9cd07 100644 --- a/src/content/docs/plugin/deep-linking.mdx +++ b/src/content/docs/plugin/deep-linking.mdx @@ -217,12 +217,18 @@ The deep-link plugin is available in both JavaScript and Rust. -When a deep link triggers your app to be opened, the `onOpenUrl` callback is executed: +When a deep link triggers your app while it's running, the `onOpenUrl` callback is called. To detect whether your app was opened via a deep link, use `getCurrent` on app start. ```javascript -import { onOpenUrl } from '@tauri-apps/plugin-deep-link'; +import { getCurrent, onOpenUrl } from '@tauri-apps/plugin-deep-link'; // when using `"withGlobalTauri": true`, you may use -// const { onOpenUrl } = window.__TAURI__.deepLink; +// const { getCurrent, onOpenUrl } = window.__TAURI__.deepLink; + +const startUrls = await getCurrent(); +if (startUrls) { + // App was likely started via a deep link + // Note that getCurrent's return value will also get updated every time onOpenUrl gets triggered. +} await onOpenUrl((urls) => { console.log('deep link:', urls); @@ -232,7 +238,7 @@ await onOpenUrl((urls) => { -When a deep link triggers your app to be opened, the `on_open_url` closure is called: +When a deep link triggers your app while it's running, the plugin's `on_open_url` closure is called. To detect whether your app was opened via a deep link, use `get_current` on app start. ```rust title="src-tauri/src/lib.rs" use tauri_plugin_deep_link::DeepLinkExt; @@ -242,6 +248,13 @@ pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_deep_link::init()) .setup(|app| { + // Note that get_current's return value will also get updated every time on_open_url gets triggered. + let start_urls = app.deep_link().get_current()?; + if let Some(urls) = start_urls { + // app was likely started by a deep link + println!("deep link URLs: {:?}", urls); + } + app.deep_link().on_open_url(|event| { println!("deep link URLs: {:?}", event.urls()); });