Skip to content

Commit bb28d04

Browse files
authored
Merge pull request #121 from gsurrel/wine-awareness
fix(windows): delegate to winebrowser under Wine
2 parents 7bd519c + f72e644 commit bb28d04

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

β€Žsrc/windows.rsβ€Ž

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,42 @@ use std::os::windows::process::CommandExt;
77

88
const CREATE_NO_WINDOW: u32 = 0x08000000;
99

10+
/// Detects if the current process is running under Wine by checking environment
11+
/// variables that Wine injects into guest processes.
12+
fn is_running_under_wine() -> bool {
13+
std::env::var_os("WINEPREFIX").is_some()
14+
|| std::env::var_os("WINELOADER").is_some()
15+
|| std::env::var_os("WINEDEBUG").is_some()
16+
}
17+
18+
/// Constructs a Command to invoke Wine's winebrowser utility, which forwards
19+
/// file/URL open requests to the host OS's default handler.
20+
fn winebrowser_command<T: AsRef<OsStr>>(path: T) -> Command {
21+
let mut cmd = Command::new("winebrowser");
22+
cmd.arg(path.as_ref());
23+
// Match Windows behavior: suppress console window flash
24+
cmd.creation_flags(CREATE_NO_WINDOW);
25+
cmd
26+
}
27+
1028
pub fn commands<T: AsRef<OsStr>>(path: T) -> Vec<Command> {
29+
let mut cmds = Vec::new();
30+
let path = path.as_ref();
31+
32+
// When under Wine, try winebrowser first for seamless host integration.
33+
if is_running_under_wine() {
34+
cmds.push(winebrowser_command(path));
35+
}
36+
1137
let mut cmd = Command::new("cmd");
1238
cmd.arg("/c")
1339
.arg("start")
1440
.raw_arg("\"\"")
1541
.raw_arg(wrap_in_quotes(path))
1642
.creation_flags(CREATE_NO_WINDOW);
17-
vec![cmd]
43+
cmds.push(cmd);
44+
45+
cmds
1846
}
1947

2048
pub fn with_command<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> Command {

0 commit comments

Comments
Β (0)