Skip to content

Commit

Permalink
fix(cli/add): Fix handling of more rust-only and non cross platform p…
Browse files Browse the repository at this point in the history
…lugins (#9855)
  • Loading branch information
FabianLars authored May 22, 2024
1 parent ae6b13d commit beda18b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-cli-add-more-plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": "patch:bug"
"@tauri-apps/cli": "patch:bug"
---

Fixed an issue that caused `tauri add` to fail for multiple rust-only and platform-specific plugins.
36 changes: 27 additions & 9 deletions tooling/cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::{collections::HashMap, process::Command};
#[derive(Default)]
struct PluginMetadata {
desktop_only: bool,
mobile_only: bool,
rust_only: bool,
builder: bool,
}
Expand All @@ -32,14 +33,22 @@ fn plugins() -> HashMap<&'static str, PluginMetadata> {
// desktop-only
for p in [
"authenticator",
"autostart",
"cli",
"global-shortcut",
"positioner",
"single-instance",
"updater",
"window-state",
] {
plugins.entry(p).or_default().desktop_only = true;
}

// mobile-only
for p in ["barcode-scanner", "biometric", "nfc"] {
plugins.entry(p).or_default().mobile_only = true;
}

// uses builder pattern
for p in [
"global-shortcut",
Expand All @@ -56,7 +65,7 @@ fn plugins() -> HashMap<&'static str, PluginMetadata> {

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

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

let tauri_dir = tauri_dir();

let target_str = metadata
.desktop_only
.then_some(r#"cfg(not(any(target_os = "android", target_os = "ios")))"#)
.or_else(|| {
metadata
.mobile_only
.then_some(r#"cfg(any(target_os = "android", target_os = "ios"))"#)
});

cargo::install_one(cargo::CargoInstallOptions {
name: &crate_name,
version,
branch: options.branch.as_deref(),
rev: options.rev.as_deref(),
tag: options.tag.as_deref(),
cwd: Some(&tauri_dir),
target: metadata
.desktop_only
.then_some(r#"cfg(not(any(target_os = "android", target_os = "ios")))"#),
target: target_str,
})?;

if !metadata.rust_only {
Expand Down Expand Up @@ -132,16 +148,18 @@ pub fn command(options: Options) -> Result<()> {
};
manager.install(&[npm_spec])?;
}
}

let _ = acl::permission::add::command(acl::permission::add::Options {
identifier: format!("{plugin}:default"),
capability: None,
});
let _ = acl::permission::add::command(acl::permission::add::Options {
identifier: format!("{plugin}:default"),
capability: None,
});
}

// add plugin init code to main.rs or lib.rs
let plugin_init_fn = if plugin == "stronghold" {
"Builder::new(|pass| todo!()).build()"
} else if plugin == "localhost" {
"Builder::new(todo!()).build()"
} else if metadata.builder {
"Builder::new().build()"
} else {
Expand Down

0 comments on commit beda18b

Please sign in to comment.