Skip to content

Commit beda18b

Browse files
authored
fix(cli/add): Fix handling of more rust-only and non cross platform plugins (#9855)
1 parent ae6b13d commit beda18b

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": "patch:bug"
3+
"@tauri-apps/cli": "patch:bug"
4+
---
5+
6+
Fixed an issue that caused `tauri add` to fail for multiple rust-only and platform-specific plugins.

tooling/cli/src/add.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::{collections::HashMap, process::Command};
2121
#[derive(Default)]
2222
struct PluginMetadata {
2323
desktop_only: bool,
24+
mobile_only: bool,
2425
rust_only: bool,
2526
builder: bool,
2627
}
@@ -32,14 +33,22 @@ fn plugins() -> HashMap<&'static str, PluginMetadata> {
3233
// desktop-only
3334
for p in [
3435
"authenticator",
36+
"autostart",
3537
"cli",
3638
"global-shortcut",
39+
"positioner",
40+
"single-instance",
3741
"updater",
3842
"window-state",
3943
] {
4044
plugins.entry(p).or_default().desktop_only = true;
4145
}
4246

47+
// mobile-only
48+
for p in ["barcode-scanner", "biometric", "nfc"] {
49+
plugins.entry(p).or_default().mobile_only = true;
50+
}
51+
4352
// uses builder pattern
4453
for p in [
4554
"global-shortcut",
@@ -56,7 +65,7 @@ fn plugins() -> HashMap<&'static str, PluginMetadata> {
5665

5766
// rust-only
5867
#[allow(clippy::single_element_loop)]
59-
for p in ["localhost"] {
68+
for p in ["localhost", "persisted-scope", "single-instance"] {
6069
plugins.entry(p).or_default().rust_only = true;
6170
}
6271

@@ -95,16 +104,23 @@ pub fn command(options: Options) -> Result<()> {
95104

96105
let tauri_dir = tauri_dir();
97106

107+
let target_str = metadata
108+
.desktop_only
109+
.then_some(r#"cfg(not(any(target_os = "android", target_os = "ios")))"#)
110+
.or_else(|| {
111+
metadata
112+
.mobile_only
113+
.then_some(r#"cfg(any(target_os = "android", target_os = "ios"))"#)
114+
});
115+
98116
cargo::install_one(cargo::CargoInstallOptions {
99117
name: &crate_name,
100118
version,
101119
branch: options.branch.as_deref(),
102120
rev: options.rev.as_deref(),
103121
tag: options.tag.as_deref(),
104122
cwd: Some(&tauri_dir),
105-
target: metadata
106-
.desktop_only
107-
.then_some(r#"cfg(not(any(target_os = "android", target_os = "ios")))"#),
123+
target: target_str,
108124
})?;
109125

110126
if !metadata.rust_only {
@@ -132,16 +148,18 @@ pub fn command(options: Options) -> Result<()> {
132148
};
133149
manager.install(&[npm_spec])?;
134150
}
135-
}
136151

137-
let _ = acl::permission::add::command(acl::permission::add::Options {
138-
identifier: format!("{plugin}:default"),
139-
capability: None,
140-
});
152+
let _ = acl::permission::add::command(acl::permission::add::Options {
153+
identifier: format!("{plugin}:default"),
154+
capability: None,
155+
});
156+
}
141157

142158
// add plugin init code to main.rs or lib.rs
143159
let plugin_init_fn = if plugin == "stronghold" {
144160
"Builder::new(|pass| todo!()).build()"
161+
} else if plugin == "localhost" {
162+
"Builder::new(todo!()).build()"
145163
} else if metadata.builder {
146164
"Builder::new().build()"
147165
} else {

0 commit comments

Comments
 (0)