Skip to content

Commit 41b73f2

Browse files
lucasfernogSir-Thom
authored andcommitted
feat(deep-link): implement getCurrent on Windows/Linux (tauri-apps#1759)
* feat(deep-link): implement getCurrent on Windows/Linux checks std::env::args() on initialization, also includes integration with the single-instance plugin * fmt * update docs, fix event * add register_all function * expose api * be nicer on docs, clippy
1 parent 9b0e105 commit 41b73f2

File tree

13 files changed

+171
-24
lines changed

13 files changed

+171
-24
lines changed

.changes/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@
268268
},
269269
"single-instance": {
270270
"path": "./plugins/single-instance",
271-
"manager": "rust"
271+
"manager": "rust",
272+
"dependencies": ["deep-link"]
272273
},
273274
"sql": {
274275
"path": "./plugins/sql",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"deep-link": patch
3+
---
4+
5+
Implement `get_current` on Linux and Windows.

.changes/deep-link-register-all.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"deep-link": patch
3+
---
4+
5+
Added `register_all` to register all desktop schemes - useful for Linux to not require a formal AppImage installation.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"single-instance": patch
3+
---
4+
5+
Integrate with the deep link plugin out of the box.

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/deep-link/examples/app/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ dist-ssr
2121
*.njsproj
2222
*.sln
2323
*.sw?
24+
25+
dist/

plugins/deep-link/examples/app/src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ serde_json = { workspace = true }
2222
tauri = { workspace = true, features = ["wry", "compression"] }
2323
tauri-plugin-deep-link = { path = "../../../" }
2424
tauri-plugin-log = { path = "../../../../log" }
25+
tauri-plugin-single-instance = { path = "../../../../single-instance" }
2526
log = "0.4"
2627

2728
[features]

plugins/deep-link/examples/app/src-tauri/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,26 @@ fn greet(name: &str) -> String {
1313
#[cfg_attr(mobile, tauri::mobile_entry_point)]
1414
pub fn run() {
1515
tauri::Builder::default()
16+
.plugin(tauri_plugin_single_instance::init(|_app, argv, _cwd| {
17+
println!("single instance triggered: {argv:?}");
18+
}))
1619
.plugin(tauri_plugin_deep_link::init())
1720
.plugin(
1821
tauri_plugin_log::Builder::default()
1922
.level(log::LevelFilter::Info)
2023
.build(),
2124
)
2225
.setup(|app| {
26+
// ensure deep links are registered on the system
27+
// this is useful because AppImages requires additional setup to be available in the system
28+
// and calling register() makes the deep links immediately available - without any user input
29+
#[cfg(target_os = "linux")]
30+
{
31+
use tauri_plugin_deep_link::DeepLinkExt;
32+
33+
app.deep_link().register_all()?;
34+
}
35+
2336
app.listen("deep-link://new-url", |url| {
2437
dbg!(url);
2538
});

plugins/deep-link/examples/app/src-tauri/tauri.conf.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
},
3030
"deep-link": {
3131
"mobile": [
32-
{ "host": "fabianlars.de", "pathPrefix": ["/intent"] },
33-
{ "host": "tauri.app" }
32+
{
33+
"host": "fabianlars.de",
34+
"pathPrefix": ["/intent"]
35+
},
36+
{
37+
"host": "tauri.app"
38+
}
3439
],
3540
"desktop": {
3641
"schemes": ["fabianlars", "my-tauri-app"]

plugins/deep-link/src/config.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use serde::{Deserialize, Deserializer};
88
use tauri_utils::config::DeepLinkProtocol;
99

10-
#[derive(Deserialize)]
10+
#[derive(Deserialize, Clone)]
1111
pub struct AssociatedDomain {
1212
#[serde(deserialize_with = "deserialize_associated_host")]
1313
pub host: String,
@@ -29,7 +29,7 @@ where
2929
}
3030
}
3131

32-
#[derive(Deserialize)]
32+
#[derive(Deserialize, Clone)]
3333
pub struct Config {
3434
/// Mobile requires `https://<host>` urls.
3535
#[serde(default)]
@@ -41,7 +41,7 @@ pub struct Config {
4141
pub desktop: DesktopProtocol,
4242
}
4343

44-
#[derive(Deserialize)]
44+
#[derive(Deserialize, Clone)]
4545
#[serde(untagged)]
4646
#[allow(unused)] // Used in tauri-bundler
4747
pub enum DesktopProtocol {
@@ -54,3 +54,26 @@ impl Default for DesktopProtocol {
5454
Self::List(Vec::new())
5555
}
5656
}
57+
58+
impl DesktopProtocol {
59+
#[allow(dead_code)]
60+
pub fn contains_scheme(&self, scheme: &String) -> bool {
61+
match self {
62+
Self::One(protocol) => protocol.schemes.contains(scheme),
63+
Self::List(protocols) => protocols
64+
.iter()
65+
.any(|protocol| protocol.schemes.contains(scheme)),
66+
}
67+
}
68+
69+
#[allow(dead_code)]
70+
pub fn schemes(&self) -> Vec<String> {
71+
match self {
72+
Self::One(protocol) => protocol.schemes.clone(),
73+
Self::List(protocols) => protocols
74+
.iter()
75+
.flat_map(|protocol| protocol.schemes.clone())
76+
.collect(),
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)