mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-08-16 19:30:27 +03:00
fix(cli/add): Fix handling of more rust-only and non cross platform plugins (#9855)
This commit is contained in:
parent
ae6b13dfc0
commit
beda18bce9
6
.changes/fix-cli-add-more-plugins.md
Normal file
6
.changes/fix-cli-add-more-plugins.md
Normal file
@ -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.
|
@ -21,6 +21,7 @@ use std::{collections::HashMap, process::Command};
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct PluginMetadata {
|
struct PluginMetadata {
|
||||||
desktop_only: bool,
|
desktop_only: bool,
|
||||||
|
mobile_only: bool,
|
||||||
rust_only: bool,
|
rust_only: bool,
|
||||||
builder: bool,
|
builder: bool,
|
||||||
}
|
}
|
||||||
@ -32,14 +33,22 @@ fn plugins() -> HashMap<&'static str, PluginMetadata> {
|
|||||||
// desktop-only
|
// desktop-only
|
||||||
for p in [
|
for p in [
|
||||||
"authenticator",
|
"authenticator",
|
||||||
|
"autostart",
|
||||||
"cli",
|
"cli",
|
||||||
"global-shortcut",
|
"global-shortcut",
|
||||||
|
"positioner",
|
||||||
|
"single-instance",
|
||||||
"updater",
|
"updater",
|
||||||
"window-state",
|
"window-state",
|
||||||
] {
|
] {
|
||||||
plugins.entry(p).or_default().desktop_only = true;
|
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
|
// uses builder pattern
|
||||||
for p in [
|
for p in [
|
||||||
"global-shortcut",
|
"global-shortcut",
|
||||||
@ -56,7 +65,7 @@ fn plugins() -> HashMap<&'static str, PluginMetadata> {
|
|||||||
|
|
||||||
// rust-only
|
// rust-only
|
||||||
#[allow(clippy::single_element_loop)]
|
#[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;
|
plugins.entry(p).or_default().rust_only = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +104,15 @@ pub fn command(options: Options) -> Result<()> {
|
|||||||
|
|
||||||
let tauri_dir = tauri_dir();
|
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 {
|
cargo::install_one(cargo::CargoInstallOptions {
|
||||||
name: &crate_name,
|
name: &crate_name,
|
||||||
version,
|
version,
|
||||||
@ -102,9 +120,7 @@ pub fn command(options: Options) -> Result<()> {
|
|||||||
rev: options.rev.as_deref(),
|
rev: options.rev.as_deref(),
|
||||||
tag: options.tag.as_deref(),
|
tag: options.tag.as_deref(),
|
||||||
cwd: Some(&tauri_dir),
|
cwd: Some(&tauri_dir),
|
||||||
target: metadata
|
target: target_str,
|
||||||
.desktop_only
|
|
||||||
.then_some(r#"cfg(not(any(target_os = "android", target_os = "ios")))"#),
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if !metadata.rust_only {
|
if !metadata.rust_only {
|
||||||
@ -132,16 +148,18 @@ pub fn command(options: Options) -> Result<()> {
|
|||||||
};
|
};
|
||||||
manager.install(&[npm_spec])?;
|
manager.install(&[npm_spec])?;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let _ = acl::permission::add::command(acl::permission::add::Options {
|
let _ = acl::permission::add::command(acl::permission::add::Options {
|
||||||
identifier: format!("{plugin}:default"),
|
identifier: format!("{plugin}:default"),
|
||||||
capability: None,
|
capability: None,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// add plugin init code to main.rs or lib.rs
|
// add plugin init code to main.rs or lib.rs
|
||||||
let plugin_init_fn = if plugin == "stronghold" {
|
let plugin_init_fn = if plugin == "stronghold" {
|
||||||
"Builder::new(|pass| todo!()).build()"
|
"Builder::new(|pass| todo!()).build()"
|
||||||
|
} else if plugin == "localhost" {
|
||||||
|
"Builder::new(todo!()).build()"
|
||||||
} else if metadata.builder {
|
} else if metadata.builder {
|
||||||
"Builder::new().build()"
|
"Builder::new().build()"
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user