From beda18bce95fd6e10543b2d8f1eca5fb7ca0655b Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Wed, 22 May 2024 18:57:57 +0200 Subject: [PATCH] fix(cli/add): Fix handling of more rust-only and non cross platform plugins (#9855) --- .changes/fix-cli-add-more-plugins.md | 6 +++++ tooling/cli/src/add.rs | 36 +++++++++++++++++++++------- 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 .changes/fix-cli-add-more-plugins.md diff --git a/.changes/fix-cli-add-more-plugins.md b/.changes/fix-cli-add-more-plugins.md new file mode 100644 index 000000000..1fa8fde95 --- /dev/null +++ b/.changes/fix-cli-add-more-plugins.md @@ -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. diff --git a/tooling/cli/src/add.rs b/tooling/cli/src/add.rs index f2bf55358..f959d1393 100644 --- a/tooling/cli/src/add.rs +++ b/tooling/cli/src/add.rs @@ -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, } @@ -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", @@ -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; } @@ -95,6 +104,15 @@ 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, @@ -102,9 +120,7 @@ pub fn command(options: Options) -> Result<()> { 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 { @@ -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 {