diff --git a/Cargo.toml b/Cargo.toml index 268168b..e37dcb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,5 @@ test = false doc = false name = "open" -[target.'cfg(windows)'.dependencies] -windows-sys = { version = "0.42", features = ["Win32_UI_Shell", "Win32_Foundation", "Win32_UI_WindowsAndMessaging"] } - [target.'cfg(all(unix, not(macos)))'.dependencies] pathdiff = "0.2.0" diff --git a/src/windows.rs b/src/windows.rs index 125770e..7bd5bcb 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -6,8 +6,6 @@ use std::{ }; use std::os::raw::c_int; -use windows_sys::Win32::UI::Shell::ShellExecuteW; -use windows_sys::Win32::UI::WindowsAndMessaging::SW_SHOW; use crate::IntoResult; @@ -32,35 +30,20 @@ fn convert_path(path: &OsStr) -> io::Result> { pub fn that>(path: T) -> io::Result<()> { let path = convert_path(path.as_ref())?; - let operation: Vec = OsStr::new("open\0").encode_wide().collect(); - let result = unsafe { - ShellExecuteW( - 0, - operation.as_ptr(), - path.as_ptr(), - ptr::null(), - ptr::null(), - SW_SHOW, - ) - }; - (result as c_int).into_result() + Command::new("cmd") + .arg("/c") + .arg("start") + .arg(path.as_ref()) + .status_without_output() + .into_result() } pub fn with>(path: T, app: impl Into) -> io::Result<()> { let path = convert_path(path.as_ref())?; - let operation: Vec = OsStr::new("open\0").encode_wide().collect(); - let app_name: Vec = OsStr::new(&format!("{}\0", app.into())) - .encode_wide() - .collect(); - let result = unsafe { - ShellExecuteW( - 0, - operation.as_ptr(), - app_name.as_ptr(), - path.as_ptr(), - ptr::null(), - SW_SHOW, - ) - }; - (result as c_int).into_result() + Command::new("cmd") + .arg("/c") + .arg(app.into()) + .arg(path.as_ref()) + .status_without_output() + .into_result() }