Skip to content

Commit bd30011

Browse files
committed
[WSL] Try wslview first instead of second
It's more likely to do the right thing vs the `xdg-open` fallback.
1 parent e16875d commit bd30011

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

opener/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ use std::{env, io};
6262
///
6363
/// - On Windows the `ShellExecuteW` Windows API function is used.
6464
/// - On Mac the system `open` command is used.
65-
/// - On Windows Subsystem for Linux (WSL), the system `xdg-open` will be used if available,
66-
/// otherwise the system `wslview` from [`wslu`] is used.
65+
/// - On Windows Subsystem for Linux (WSL), the system `wslview` from [`wslu`] is used if available,
66+
/// otherwise the system `xdg-open` is used, if available.
6767
/// - On non-WSL Linux and other platforms,
6868
/// the system `xdg-open` script is used if available, otherwise an `xdg-open` script embedded in
6969
/// this library is used.

opener/src/linux_and_more.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,32 @@ pub(crate) fn open(path: &OsStr) -> Result<(), OpenError> {
1414
}
1515

1616
fn wsl_open(path: &OsStr) -> Result<(), OpenError> {
17-
let system_xdg_open = Command::new("xdg-open")
17+
let transformed_path = crate::wsl_to_windows_path(path);
18+
let transformed_path = transformed_path.as_deref();
19+
let path = match transformed_path {
20+
None => path,
21+
Some(x) => x,
22+
};
23+
let wslview = Command::new("wslview")
1824
.arg(path)
1925
.stdin(Stdio::null())
2026
.stdout(Stdio::null())
2127
.stderr(Stdio::piped())
2228
.spawn();
2329

24-
if let Ok(mut child) = system_xdg_open {
25-
return crate::wait_child(&mut child, "xdg-open (system)".into());
30+
if let Ok(mut child) = wslview {
31+
return crate::wait_child(&mut child, "wslview".into());
2632
}
2733

28-
let mut wslview = Command::new("wslview")
34+
let mut system_xdg_open = Command::new("xdg-open")
2935
.arg(path)
3036
.stdin(Stdio::null())
3137
.stdout(Stdio::null())
3238
.stderr(Stdio::piped())
3339
.spawn()
3440
.map_err(OpenError::Io)?;
3541

36-
crate::wait_child(&mut wslview, "wslview".into())
42+
crate::wait_child(&mut system_xdg_open, "xdg-open (system)".into())
3743
}
3844

3945
fn non_wsl_open(path: &OsStr) -> Result<(), OpenError> {

0 commit comments

Comments
 (0)