Skip to content

Commit 96639ca

Browse files
authored
refactor(core): remove shell APIs (#6749)
1 parent 0c11023 commit 96639ca

File tree

33 files changed

+74
-2433
lines changed

33 files changed

+74
-2433
lines changed

.changes/move-shell.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"api": patch
3+
"tauri": patch
4+
"tauri-codegen": patch
5+
"tauri-macros": patch
6+
---
7+
8+
Moved the `shell` functionality to its own plugin in the plugins-workspace repository.

.changes/process-mod-refactor.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Moved the `tauri::api::process` module to `tauri::process`.

core/tauri-codegen/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ tauri-utils = { version = "2.0.0-alpha.4", path = "../tauri-utils", features = [
2323
thiserror = "1"
2424
walkdir = "2"
2525
brotli = { version = "3", optional = true, default-features = false, features = [ "std" ] }
26-
regex = { version = "1.7.1", optional = true }
2726
uuid = { version = "1", features = [ "v4" ] }
2827
semver = "1"
2928
ico = "0.3"
@@ -39,6 +38,5 @@ time = { version = "0.3", features = [ "parsing", "formatting" ] }
3938
default = [ "compression" ]
4039
compression = [ "brotli", "tauri-utils/compression" ]
4140
isolation = [ "tauri-utils/isolation" ]
42-
shell-scope = [ "regex" ]
4341
config-json5 = [ "tauri-utils/config-json5" ]
4442
config-toml = [ "tauri-utils/config-toml" ]

core/tauri-codegen/src/context.rs

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ use tauri_utils::html::{
1616
inject_nonce_token, parse as parse_html, serialize_node as serialize_html_node,
1717
};
1818

19-
#[cfg(feature = "shell-scope")]
20-
use tauri_utils::config::{ShellAllowedArg, ShellAllowedArgs, ShellAllowlistScope};
21-
2219
use crate::embedded_assets::{AssetOptions, CspHashes, EmbeddedAssets, EmbeddedAssetsError};
2320

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

427-
#[cfg(feature = "shell-scope")]
428-
let with_shell_scope_code = {
429-
use regex::Regex;
430-
use tauri_utils::config::ShellAllowlistOpen;
431-
432-
let shell_scopes = get_allowed_clis(&root, &config.tauri.allowlist.shell.scope);
433-
434-
let shell_scope_constructor = match &config.tauri.allowlist.shell.open {
435-
ShellAllowlistOpen::Flag(false) => quote!(#root::ShellScopeConfig::new().skip_validation()),
436-
ShellAllowlistOpen::Flag(true) => quote!(#root::ShellScopeConfig::new()),
437-
ShellAllowlistOpen::Validate(regex) => match Regex::new(regex) {
438-
Ok(_) => {
439-
quote!(#root::ShellScopeConfig::with_validator(#root::regex::Regex::new(#regex).unwrap()))
440-
}
441-
Err(error) => {
442-
let error = error.to_string();
443-
quote!({
444-
compile_error!(#error);
445-
#root::ShellScopeConfig::with_validator(#root::regex::Regex::new(#regex).unwrap())
446-
})
447-
}
448-
},
449-
_ => panic!("unknown shell open format, unable to prepare"),
450-
};
451-
let shell_scope = quote!(#shell_scope_constructor.set_allowed_commands(#shell_scopes));
452-
453-
quote!(context.set_shell_scope(#shell_scope);)
454-
};
455-
456-
#[cfg(not(feature = "shell-scope"))]
457-
let with_shell_scope_code = quote!();
458-
459424
Ok(quote!({
460425
#[allow(unused_mut, clippy::let_and_return)]
461426
let mut context = #root::Context::new(
@@ -468,7 +433,6 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
468433
#pattern,
469434
);
470435
#with_system_tray_icon_code
471-
#with_shell_scope_code
472436
context
473437
}))
474438
}
@@ -587,78 +551,3 @@ fn find_icon<F: Fn(&&String) -> bool>(
587551
.unwrap_or_else(|| default.to_string());
588552
config_parent.join(icon_path)
589553
}
590-
591-
#[cfg(feature = "shell-scope")]
592-
fn get_allowed_clis(root: &TokenStream, scope: &ShellAllowlistScope) -> TokenStream {
593-
let commands = scope
594-
.0
595-
.iter()
596-
.map(|scope| {
597-
let sidecar = &scope.sidecar;
598-
599-
let name = &scope.name;
600-
let name = quote!(#name.into());
601-
602-
let command = scope.command.to_string_lossy();
603-
let command = quote!(::std::path::PathBuf::from(#command));
604-
605-
let args = match &scope.args {
606-
ShellAllowedArgs::Flag(true) => quote!(::std::option::Option::None),
607-
ShellAllowedArgs::Flag(false) => quote!(::std::option::Option::Some(::std::vec![])),
608-
ShellAllowedArgs::List(list) => {
609-
let list = list.iter().map(|arg| match arg {
610-
ShellAllowedArg::Fixed(fixed) => {
611-
quote!(#root::scope::ShellScopeAllowedArg::Fixed(#fixed.into()))
612-
}
613-
ShellAllowedArg::Var { validator } => {
614-
let validator = match regex::Regex::new(validator) {
615-
Ok(regex) => {
616-
let regex = regex.as_str();
617-
quote!(#root::regex::Regex::new(#regex).unwrap())
618-
}
619-
Err(error) => {
620-
let error = error.to_string();
621-
quote!({
622-
compile_error!(#error);
623-
#root::regex::Regex::new(#validator).unwrap()
624-
})
625-
}
626-
};
627-
628-
quote!(#root::scope::ShellScopeAllowedArg::Var { validator: #validator })
629-
}
630-
_ => panic!("unknown shell scope arg, unable to prepare"),
631-
});
632-
633-
quote!(::std::option::Option::Some(::std::vec![#(#list),*]))
634-
}
635-
_ => panic!("unknown shell scope command, unable to prepare"),
636-
};
637-
638-
(
639-
quote!(#name),
640-
quote!(
641-
#root::scope::ShellScopeAllowedCommand {
642-
command: #command,
643-
args: #args,
644-
sidecar: #sidecar,
645-
}
646-
),
647-
)
648-
})
649-
.collect::<Vec<_>>();
650-
651-
if commands.is_empty() {
652-
quote!(::std::collections::HashMap::new())
653-
} else {
654-
let insertions = commands
655-
.iter()
656-
.map(|(name, value)| quote!(hashmap.insert(#name, #value);));
657-
658-
quote!({
659-
let mut hashmap = ::std::collections::HashMap::new();
660-
#(#insertions)*
661-
hashmap
662-
})
663-
}
664-
}

core/tauri-macros/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ tauri-utils = { version = "2.0.0-alpha.4", path = "../tauri-utils" }
2727
custom-protocol = [ ]
2828
compression = [ "tauri-codegen/compression" ]
2929
isolation = [ "tauri-codegen/isolation" ]
30-
shell-scope = [ "tauri-codegen/shell-scope" ]
3130
config-json5 = [ "tauri-codegen/config-json5", "tauri-utils/config-json5" ]
3231
config-toml = [ "tauri-codegen/config-toml", "tauri-utils/config-toml" ]

core/tauri/Cargo.toml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,10 @@ percent-encoding = "2.2"
6363
base64 = { version = "0.21", optional = true }
6464
reqwest = { version = "0.11", default-features = false, features = [ "json", "stream" ] }
6565
bytes = { version = "1", features = [ "serde" ] }
66-
open = { version = "3.0", optional = true }
67-
shared_child = { version = "1.0", optional = true }
68-
os_pipe = { version = "1.0", optional = true }
6966
raw-window-handle = "0.5"
7067
minisign-verify = { version = "0.2", optional = true }
7168
time = { version = "0.3", features = [ "parsing", "formatting" ], optional = true }
7269
os_info = { version = "3", optional = true }
73-
regex = { version = "1.6.0", optional = true }
7470
glob = "0.3"
7571
data-url = { version = "0.2", optional = true }
7672
serialize-to-javascript = "=0.1.1"
@@ -141,12 +137,10 @@ updater = [
141137
"dialog-ask",
142138
"fs-extract-api"
143139
]
144-
shell-open-api = [ "open", "regex", "tauri-macros/shell-scope" ]
145140
fs-extract-api = [ "zip" ]
146141
native-tls = [ "reqwest/native-tls" ]
147142
native-tls-vendored = [ "reqwest/native-tls-vendored" ]
148143
rustls-tls = [ "reqwest/rustls-tls" ]
149-
process-command-api = [ "shared_child", "os_pipe" ]
150144
system-tray = [ "tauri-runtime/system-tray", "tauri-runtime-wry/system-tray" ]
151145
devtools = [ "tauri-runtime/devtools", "tauri-runtime-wry/devtools" ]
152146
dox = [ "tauri-runtime-wry/dox" ]
@@ -212,9 +206,9 @@ process-relaunch-dangerous-allow-symlink-macos = [ "tauri-utils/process-relaunch
212206
protocol-all = [ "protocol-asset" ]
213207
protocol-asset = [ ]
214208
shell-all = [ "shell-execute", "shell-sidecar", "shell-open" ]
215-
shell-execute = [ "process-command-api", "regex", "tauri-macros/shell-scope" ]
216-
shell-sidecar = [ "process-command-api", "regex", "tauri-macros/shell-scope" ]
217-
shell-open = [ "shell-open-api" ]
209+
shell-execute = [ ]
210+
shell-sidecar = [ ]
211+
shell-open = [ ]
218212
window-all = [
219213
"window-create",
220214
"window-center",

core/tauri/build.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ fn main() {
108108
);
109109

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

116112
if !mobile {
117113
alias_module(

core/tauri/scripts/bundle.global.js

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/src/api/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
pub mod dir;
88
pub mod file;
99
pub mod ipc;
10-
pub mod process;
11-
#[cfg(feature = "shell-open-api")]
12-
#[cfg_attr(doc_cfg, doc(cfg(feature = "shell-open-api")))]
13-
pub mod shell;
1410
pub mod version;
1511

1612
mod error;

0 commit comments

Comments
 (0)