Skip to content

Commit 056cb00

Browse files
committed
feat(windows): use std Command
Use std `Command` instead of `ShellExecuteW` from windows sys crate. This change was already attempted in: #25 and later reverted in: #27 and it it seems that it didn't work due to incorrect usage of `explorer` instead of `cmd /c start`. (see helix-editor/helix#5820 (comment) for detailed explanation). Related: helix-editor/helix#5820
1 parent eea4f27 commit 056cb00

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@ test = false
1616
doc = false
1717
name = "open"
1818

19-
[target.'cfg(windows)'.dependencies]
20-
windows-sys = { version = "0.42", features = ["Win32_UI_Shell", "Win32_Foundation", "Win32_UI_WindowsAndMessaging"] }
21-
2219
[target.'cfg(all(unix, not(macos)))'.dependencies]
2320
pathdiff = "0.2.0"

src/windows.rs

+12-29
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use std::{
66
};
77

88
use std::os::raw::c_int;
9-
use windows_sys::Win32::UI::Shell::ShellExecuteW;
10-
use windows_sys::Win32::UI::WindowsAndMessaging::SW_SHOW;
119

1210
use crate::IntoResult;
1311

@@ -32,35 +30,20 @@ fn convert_path(path: &OsStr) -> io::Result<Vec<u16>> {
3230

3331
pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
3432
let path = convert_path(path.as_ref())?;
35-
let operation: Vec<u16> = OsStr::new("open\0").encode_wide().collect();
36-
let result = unsafe {
37-
ShellExecuteW(
38-
0,
39-
operation.as_ptr(),
40-
path.as_ptr(),
41-
ptr::null(),
42-
ptr::null(),
43-
SW_SHOW,
44-
)
45-
};
46-
(result as c_int).into_result()
33+
Command::new("cmd")
34+
.arg("/c")
35+
.arg("start")
36+
.arg(path.as_ref())
37+
.status_without_output()
38+
.into_result()
4739
}
4840

4941
pub fn with<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> io::Result<()> {
5042
let path = convert_path(path.as_ref())?;
51-
let operation: Vec<u16> = OsStr::new("open\0").encode_wide().collect();
52-
let app_name: Vec<u16> = OsStr::new(&format!("{}\0", app.into()))
53-
.encode_wide()
54-
.collect();
55-
let result = unsafe {
56-
ShellExecuteW(
57-
0,
58-
operation.as_ptr(),
59-
app_name.as_ptr(),
60-
path.as_ptr(),
61-
ptr::null(),
62-
SW_SHOW,
63-
)
64-
};
65-
(result as c_int).into_result()
43+
Command::new("cmd")
44+
.arg("/c")
45+
.arg(app.into())
46+
.arg(path.as_ref())
47+
.status_without_output()
48+
.into_result()
6649
}

0 commit comments

Comments
 (0)