use std::path::PathBuf;
use schemars::JsonSchema;
#[path = "src/scope_entry.rs"]
mod scope_entry;
#[derive(Debug, PartialEq, Eq, Clone, Hash, schemars::JsonSchema)]
#[serde(untagged, deny_unknown_fields)]
#[non_exhaustive]
pub enum ShellScopeEntryAllowedArg {
Fixed(String),
Var {
validator: String,
#[serde(default)]
raw: bool,
},
}
#[derive(Debug, PartialEq, Eq, Clone, Hash, JsonSchema)]
#[serde(untagged, deny_unknown_fields)]
#[non_exhaustive]
pub enum ShellScopeEntryAllowedArgs {
Flag(bool),
List(Vec<ShellScopeEntryAllowedArg>),
}
impl Default for ShellScopeEntryAllowedArgs {
fn default() -> Self {
Self::Flag(false)
}
}
#[derive(JsonSchema)]
#[serde(untagged, deny_unknown_fields)]
#[allow(unused)]
pub(crate) enum ShellScopeEntry {
Command {
name: String,
#[serde(rename = "cmd")]
command: PathBuf,
#[serde(default)]
args: ShellScopeEntryAllowedArgs,
},
Sidecar {
name: String,
#[serde(default)]
args: ShellScopeEntryAllowedArgs,
sidecar: bool,
},
}
#[allow(clippy::unnecessary_operation)]
fn _f() {
match (ShellScopeEntry::Sidecar {
name: String::new(),
args: ShellScopeEntryAllowedArgs::Flag(false),
sidecar: true,
}) {
ShellScopeEntry::Command {
name,
command,
args,
} => scope_entry::EntryRaw {
name,
command: Some(command),
args: match args {
ShellScopeEntryAllowedArgs::Flag(flag) => scope_entry::ShellAllowedArgs::Flag(flag),
ShellScopeEntryAllowedArgs::List(vec) => scope_entry::ShellAllowedArgs::List(
vec.into_iter()
.map(|s| match s {
ShellScopeEntryAllowedArg::Fixed(fixed) => {
scope_entry::ShellAllowedArg::Fixed(fixed)
}
ShellScopeEntryAllowedArg::Var { validator, raw } => {
scope_entry::ShellAllowedArg::Var { validator, raw }
}
})
.collect(),
),
},
sidecar: false,
},
ShellScopeEntry::Sidecar {
name,
args,
sidecar,
} => scope_entry::EntryRaw {
name,
command: None,
args: match args {
ShellScopeEntryAllowedArgs::Flag(flag) => scope_entry::ShellAllowedArgs::Flag(flag),
ShellScopeEntryAllowedArgs::List(vec) => scope_entry::ShellAllowedArgs::List(
vec.into_iter()
.map(|s| match s {
ShellScopeEntryAllowedArg::Fixed(fixed) => {
scope_entry::ShellAllowedArg::Fixed(fixed)
}
ShellScopeEntryAllowedArg::Var { validator, raw } => {
scope_entry::ShellAllowedArg::Var { validator, raw }
}
})
.collect(),
),
},
sidecar,
},
};
}
const COMMANDS: &[&str] = &["execute", "spawn", "stdin_write", "kill", "open"];
fn main() {
tauri_plugin::Builder::new(COMMANDS)
.global_api_script_path("./api-iife.js")
.global_scope_schema(schemars::schema_for!(ShellScopeEntry))
.android_path("android")
.ios_path("ios")
.build();
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let mobile = target_os == "ios" || target_os == "android";
alias("desktop", !mobile);
alias("mobile", mobile);
}
fn alias(alias: &str, has_feature: bool) {
println!("cargo:rustc-check-cfg=cfg({alias})");
if has_feature {
println!("cargo:rustc-cfg={alias}");
}
}