diff --git a/Cargo.lock b/Cargo.lock index 95a8a0a99..a49d97f31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3353,15 +3353,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "open" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd61e3bf9d78956c72ee864bba52431f7f43994b21a17e9e72596a81bd61075b" -dependencies = [ - "pathdiff", -] - [[package]] name = "openssl" version = "0.10.38" @@ -3485,12 +3476,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "pathdiff" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" - [[package]] name = "pem" version = "1.1.1" @@ -6106,7 +6091,6 @@ dependencies = [ name = "wezterm-open-url" version = "0.1.0" dependencies = [ - "open", "winapi", ] diff --git a/wezterm-open-url/Cargo.toml b/wezterm-open-url/Cargo.toml index 102c8fd1f..aa792764e 100644 --- a/wezterm-open-url/Cargo.toml +++ b/wezterm-open-url/Cargo.toml @@ -6,5 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -open = "4.0" winapi = {version="0.3", features=["shellapi"]} diff --git a/wezterm-open-url/src/lib.rs b/wezterm-open-url/src/lib.rs index d8ef32547..9a61fd947 100644 --- a/wezterm-open-url/src/lib.rs +++ b/wezterm-open-url/src/lib.rs @@ -1,14 +1,57 @@ +// Portions of this file are derived from code that is +// Copyright © 2015 Sebastian Thiel +// + #[cfg(not(windows))] pub fn open_url(url: &str) { let url = url.to_string(); std::thread::spawn(move || { - let _ = open::that(&url); + #[cfg(target_os = "macos")] + let candidates: &[&[&str]] = &[&["/usr/bin/open", &url]]; + + #[cfg(not(target_os = "macos"))] + let candidates: &[&[&str]] = &[ + &["xdg-open", &url], + &["gio", "open", &url] as &[_], + &["gnome-open", &url], + &["kde-open", &url], + &["wslview", &url], + ]; + + for candidate in candidates { + let mut cmd = std::process::Command::new(candidate[0]); + cmd.args(&candidate[1..]); + + if let Ok(status) = cmd.status() { + if status.success() { + return; + } + } + } }); } #[cfg(not(windows))] pub fn open_with(url: &str, app: &str) { - open::with_in_background(url, app); + let url = url.to_string(); + let app = app.to_string(); + + std::thread::spawn(move || { + #[cfg(target_os = "macos")] + let args: &[&str] = &["/usr/bin/open", "-a", &app, &url]; + + #[cfg(not(target_os = "macos"))] + let args: &[&str] = &[&app, &url]; + + let mut cmd = std::process::Command::new(args[0]); + cmd.args(&args[1..]); + + if let Ok(status) = cmd.status() { + if status.success() { + return; + } + } + }); } #[cfg(windows)]