DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/NativeHost/
MoveItemToTrash.rs1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3use serde_json::{Value, json};
9
10pub async fn NativeMoveItemToTrash(Arguments:Vec<Value>) -> Result<Value, String> {
11 let Path = Arguments.first().and_then(|V| V.as_str()).unwrap_or("").to_string();
12 if Path.is_empty() {
13 return Ok(json!(false));
14 }
15 crate::dev_log!("nativehost", "nativeHost:moveItemToTrash path={}", Path);
16 let Moved = {
17 #[cfg(target_os = "macos")]
18 {
19 tokio::process::Command::new("osascript")
20 .args([
21 "-e",
22 &format!(
23 "tell application \"Finder\" to delete POSIX file \"{}\"",
24 Path.replace('"', "\\\"")
25 ),
26 ])
27 .status()
28 .await
29 .map(|S| S.success())
30 .unwrap_or(false)
31 }
32 #[cfg(target_os = "linux")]
33 {
34 let Gio = tokio::process::Command::new("gio")
35 .args(["trash", &Path])
36 .status()
37 .await
38 .map(|S| S.success())
39 .unwrap_or(false);
40 if Gio {
41 true
42 } else {
43 tokio::process::Command::new("trash")
44 .arg(&Path)
45 .status()
46 .await
47 .map(|S| S.success())
48 .unwrap_or(false)
49 }
50 }
51 #[cfg(target_os = "windows")]
52 {
53 let Script = format!(
54 "(new-object -comobject Shell.Application).NameSpace(0xA).MoveHere('{}')",
55 Path.replace('\'', "''")
56 );
57 tokio::process::Command::new("powershell.exe")
58 .args(["-NoProfile", "-Command", &Script])
59 .status()
60 .await
61 .map(|S| S.success())
62 .unwrap_or(false)
63 }
64 #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
65 {
66 false
67 }
68 };
69 Ok(json!(Moved))
70}