docs: add note about getCurrent to get urls that opened the app

This commit is contained in:
FabianLars
2025-08-19 11:56:34 +02:00
parent 22f2646e75
commit aab78609bf

View File

@@ -217,12 +217,18 @@ The deep-link plugin is available in both JavaScript and Rust.
<Tabs syncKey="lang">
<TabItem label="JavaScript">
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) => {
</TabItem>
<TabItem label="Rust">
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());
});