Skip to content

Commit aab7860

Browse files
committed
docs: add note about getCurrent to get urls that opened the app
1 parent 22f2646 commit aab7860

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/content/docs/plugin/deep-linking.mdx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,18 @@ The deep-link plugin is available in both JavaScript and Rust.
217217
<Tabs syncKey="lang">
218218
<TabItem label="JavaScript">
219219

220-
When a deep link triggers your app to be opened, the `onOpenUrl` callback is executed:
220+
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.
221221

222222
```javascript
223-
import { onOpenUrl } from '@tauri-apps/plugin-deep-link';
223+
import { getCurrent, onOpenUrl } from '@tauri-apps/plugin-deep-link';
224224
// when using `"withGlobalTauri": true`, you may use
225-
// const { onOpenUrl } = window.__TAURI__.deepLink;
225+
// const { getCurrent, onOpenUrl } = window.__TAURI__.deepLink;
226+
227+
const startUrls = await getCurrent();
228+
if (startUrls) {
229+
// App was likely started via a deep link
230+
// Note that getCurrent's return value will also get updated every time onOpenUrl gets triggered.
231+
}
226232

227233
await onOpenUrl((urls) => {
228234
console.log('deep link:', urls);
@@ -232,7 +238,7 @@ await onOpenUrl((urls) => {
232238
</TabItem>
233239
<TabItem label="Rust">
234240

235-
When a deep link triggers your app to be opened, the `on_open_url` closure is called:
241+
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.
236242

237243
```rust title="src-tauri/src/lib.rs"
238244
use tauri_plugin_deep_link::DeepLinkExt;
@@ -242,6 +248,13 @@ pub fn run() {
242248
tauri::Builder::default()
243249
.plugin(tauri_plugin_deep_link::init())
244250
.setup(|app| {
251+
// Note that get_current's return value will also get updated every time on_open_url gets triggered.
252+
let start_urls = app.deep_link().get_current()?;
253+
if let Some(urls) = start_urls {
254+
// app was likely started by a deep link
255+
println!("deep link URLs: {:?}", urls);
256+
}
257+
245258
app.deep_link().on_open_url(|event| {
246259
println!("deep link URLs: {:?}", event.urls());
247260
});

0 commit comments

Comments
 (0)