Skip to content

Commit

Permalink
refactor(core): remove shell APIs (#6749)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Apr 20, 2023
1 parent 0c11023 commit 96639ca
Show file tree
Hide file tree
Showing 33 changed files with 74 additions and 2,433 deletions.
8 changes: 8 additions & 0 deletions .changes/move-shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"api": patch
"tauri": patch
"tauri-codegen": patch
"tauri-macros": patch
---

Moved the `shell` functionality to its own plugin in the plugins-workspace repository.
5 changes: 5 additions & 0 deletions .changes/process-mod-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Moved the `tauri::api::process` module to `tauri::process`.
2 changes: 0 additions & 2 deletions core/tauri-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ tauri-utils = { version = "2.0.0-alpha.4", path = "../tauri-utils", features = [
thiserror = "1"
walkdir = "2"
brotli = { version = "3", optional = true, default-features = false, features = [ "std" ] }
regex = { version = "1.7.1", optional = true }
uuid = { version = "1", features = [ "v4" ] }
semver = "1"
ico = "0.3"
Expand All @@ -39,6 +38,5 @@ time = { version = "0.3", features = [ "parsing", "formatting" ] }
default = [ "compression" ]
compression = [ "brotli", "tauri-utils/compression" ]
isolation = [ "tauri-utils/isolation" ]
shell-scope = [ "regex" ]
config-json5 = [ "tauri-utils/config-json5" ]
config-toml = [ "tauri-utils/config-toml" ]
111 changes: 0 additions & 111 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ use tauri_utils::html::{
inject_nonce_token, parse as parse_html, serialize_node as serialize_html_node,
};

#[cfg(feature = "shell-scope")]
use tauri_utils::config::{ShellAllowedArg, ShellAllowedArgs, ShellAllowlistScope};

use crate::embedded_assets::{AssetOptions, CspHashes, EmbeddedAssets, EmbeddedAssetsError};

/// Necessary data needed by [`context_codegen`] to generate code for a Tauri application context.
Expand Down Expand Up @@ -424,38 +421,6 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
}
};

#[cfg(feature = "shell-scope")]
let with_shell_scope_code = {
use regex::Regex;
use tauri_utils::config::ShellAllowlistOpen;

let shell_scopes = get_allowed_clis(&root, &config.tauri.allowlist.shell.scope);

let shell_scope_constructor = match &config.tauri.allowlist.shell.open {
ShellAllowlistOpen::Flag(false) => quote!(#root::ShellScopeConfig::new().skip_validation()),
ShellAllowlistOpen::Flag(true) => quote!(#root::ShellScopeConfig::new()),
ShellAllowlistOpen::Validate(regex) => match Regex::new(regex) {
Ok(_) => {
quote!(#root::ShellScopeConfig::with_validator(#root::regex::Regex::new(#regex).unwrap()))
}
Err(error) => {
let error = error.to_string();
quote!({
compile_error!(#error);
#root::ShellScopeConfig::with_validator(#root::regex::Regex::new(#regex).unwrap())
})
}
},
_ => panic!("unknown shell open format, unable to prepare"),
};
let shell_scope = quote!(#shell_scope_constructor.set_allowed_commands(#shell_scopes));

quote!(context.set_shell_scope(#shell_scope);)
};

#[cfg(not(feature = "shell-scope"))]
let with_shell_scope_code = quote!();

Ok(quote!({
#[allow(unused_mut, clippy::let_and_return)]
let mut context = #root::Context::new(
Expand All @@ -468,7 +433,6 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
#pattern,
);
#with_system_tray_icon_code
#with_shell_scope_code
context
}))
}
Expand Down Expand Up @@ -587,78 +551,3 @@ fn find_icon<F: Fn(&&String) -> bool>(
.unwrap_or_else(|| default.to_string());
config_parent.join(icon_path)
}

#[cfg(feature = "shell-scope")]
fn get_allowed_clis(root: &TokenStream, scope: &ShellAllowlistScope) -> TokenStream {
let commands = scope
.0
.iter()
.map(|scope| {
let sidecar = &scope.sidecar;

let name = &scope.name;
let name = quote!(#name.into());

let command = scope.command.to_string_lossy();
let command = quote!(::std::path::PathBuf::from(#command));

let args = match &scope.args {
ShellAllowedArgs::Flag(true) => quote!(::std::option::Option::None),
ShellAllowedArgs::Flag(false) => quote!(::std::option::Option::Some(::std::vec![])),
ShellAllowedArgs::List(list) => {
let list = list.iter().map(|arg| match arg {
ShellAllowedArg::Fixed(fixed) => {
quote!(#root::scope::ShellScopeAllowedArg::Fixed(#fixed.into()))
}
ShellAllowedArg::Var { validator } => {
let validator = match regex::Regex::new(validator) {
Ok(regex) => {
let regex = regex.as_str();
quote!(#root::regex::Regex::new(#regex).unwrap())
}
Err(error) => {
let error = error.to_string();
quote!({
compile_error!(#error);
#root::regex::Regex::new(#validator).unwrap()
})
}
};

quote!(#root::scope::ShellScopeAllowedArg::Var { validator: #validator })
}
_ => panic!("unknown shell scope arg, unable to prepare"),
});

quote!(::std::option::Option::Some(::std::vec![#(#list),*]))
}
_ => panic!("unknown shell scope command, unable to prepare"),
};

(
quote!(#name),
quote!(
#root::scope::ShellScopeAllowedCommand {
command: #command,
args: #args,
sidecar: #sidecar,
}
),
)
})
.collect::<Vec<_>>();

if commands.is_empty() {
quote!(::std::collections::HashMap::new())
} else {
let insertions = commands
.iter()
.map(|(name, value)| quote!(hashmap.insert(#name, #value);));

quote!({
let mut hashmap = ::std::collections::HashMap::new();
#(#insertions)*
hashmap
})
}
}
1 change: 0 additions & 1 deletion core/tauri-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ tauri-utils = { version = "2.0.0-alpha.4", path = "../tauri-utils" }
custom-protocol = [ ]
compression = [ "tauri-codegen/compression" ]
isolation = [ "tauri-codegen/isolation" ]
shell-scope = [ "tauri-codegen/shell-scope" ]
config-json5 = [ "tauri-codegen/config-json5", "tauri-utils/config-json5" ]
config-toml = [ "tauri-codegen/config-toml", "tauri-utils/config-toml" ]
12 changes: 3 additions & 9 deletions core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,10 @@ percent-encoding = "2.2"
base64 = { version = "0.21", optional = true }
reqwest = { version = "0.11", default-features = false, features = [ "json", "stream" ] }
bytes = { version = "1", features = [ "serde" ] }
open = { version = "3.0", optional = true }
shared_child = { version = "1.0", optional = true }
os_pipe = { version = "1.0", optional = true }
raw-window-handle = "0.5"
minisign-verify = { version = "0.2", optional = true }
time = { version = "0.3", features = [ "parsing", "formatting" ], optional = true }
os_info = { version = "3", optional = true }
regex = { version = "1.6.0", optional = true }
glob = "0.3"
data-url = { version = "0.2", optional = true }
serialize-to-javascript = "=0.1.1"
Expand Down Expand Up @@ -141,12 +137,10 @@ updater = [
"dialog-ask",
"fs-extract-api"
]
shell-open-api = [ "open", "regex", "tauri-macros/shell-scope" ]
fs-extract-api = [ "zip" ]
native-tls = [ "reqwest/native-tls" ]
native-tls-vendored = [ "reqwest/native-tls-vendored" ]
rustls-tls = [ "reqwest/rustls-tls" ]
process-command-api = [ "shared_child", "os_pipe" ]
system-tray = [ "tauri-runtime/system-tray", "tauri-runtime-wry/system-tray" ]
devtools = [ "tauri-runtime/devtools", "tauri-runtime-wry/devtools" ]
dox = [ "tauri-runtime-wry/dox" ]
Expand Down Expand Up @@ -212,9 +206,9 @@ process-relaunch-dangerous-allow-symlink-macos = [ "tauri-utils/process-relaunch
protocol-all = [ "protocol-asset" ]
protocol-asset = [ ]
shell-all = [ "shell-execute", "shell-sidecar", "shell-open" ]
shell-execute = [ "process-command-api", "regex", "tauri-macros/shell-scope" ]
shell-sidecar = [ "process-command-api", "regex", "tauri-macros/shell-scope" ]
shell-open = [ "shell-open-api" ]
shell-execute = [ ]
shell-sidecar = [ ]
shell-open = [ ]
window-all = [
"window-create",
"window-center",
Expand Down
4 changes: 0 additions & 4 deletions core/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ fn main() {
);

alias_module("shell", &["execute", "sidecar", "open"], api_all);
// helper for the command module macro
let shell_script = has_feature("shell-execute") || has_feature("shell-sidecar");
alias("shell_script", shell_script);
alias("shell_scope", has_feature("shell-open-api") || shell_script);

if !mobile {
alias_module(
Expand Down
7 changes: 3 additions & 4 deletions core/tauri/scripts/bundle.global.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions core/tauri/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
pub mod dir;
pub mod file;
pub mod ipc;
pub mod process;
#[cfg(feature = "shell-open-api")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "shell-open-api")))]
pub mod shell;
pub mod version;

mod error;
Expand Down
Loading

0 comments on commit 96639ca

Please sign in to comment.