From 8471a3961c7e32d7a78c3b766989d443c0158544 Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Fri, 25 Oct 2019 15:28:31 -0400 Subject: [PATCH 1/5] Add Debian's x-www-browser to the end of the Linux fallback chain (This alias is created and maintained by Debian's "alternatives" system, which is integrated with the APT package manager. It serves to act as a system-wide default on Debian-family distros (eg. Ubuntu, Mint) which applications can fall back to if the user hasn't specified a preference.) --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6ff7b16..a3b9d15 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -271,7 +271,8 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result { Browser::Default => open_on_unix_using_browser_env(url) .or_else(|_| -> Result { Command::new("xdg-open").arg(url).status() }) .or_else(|_| -> Result { Command::new("gvfs-open").arg(url).status() }) - .or_else(|_| -> Result { Command::new("gnome-open").arg(url).status() }), + .or_else(|_| -> Result { Command::new("gnome-open").arg(url).status() }) + .or_else(|_| -> Result { Command::new("x-www-browser").arg(url).status() }), _ => Err(Error::new( ErrorKind::NotFound, "Only the default browser is supported on this platform right now", From a5d047737a682facd762f59c2555f7fcf6722814 Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Fri, 25 Oct 2019 23:27:33 -0400 Subject: [PATCH 2/5] Add kioclient to the Linux/BSD fallback chain after gnome-open `kioclient exec` is KDE's equivalent to gvfs-open. In this version using a fixed precedence order, it is added after all entries which existed in the previous released version to ensure that it will not change the behaviour for users of non-KDE desktops. Were this starting a new major version, I would put kioclient ahead of gvfs-open and gnome-open in the precedence order since it's more common to find GTK+ applications on KDE desktops (and, thus `gvfs-open` too) than to find KDE applications on GNOME desktops. --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index a3b9d15..40e2fd3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -272,6 +272,7 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result { .or_else(|_| -> Result { Command::new("xdg-open").arg(url).status() }) .or_else(|_| -> Result { Command::new("gvfs-open").arg(url).status() }) .or_else(|_| -> Result { Command::new("gnome-open").arg(url).status() }) + .or_else(|_| -> Result { Command::new("kioclient").arg("exec").arg(url).status() }) .or_else(|_| -> Result { Command::new("x-www-browser").arg(url).status() }), _ => Err(Error::new( ErrorKind::NotFound, From f7603bdfb39a79778e98d5ed7d66192f61f6f381 Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Sat, 26 Oct 2019 00:15:33 -0400 Subject: [PATCH 3/5] Under KDE, let kioclient take precendence over gvfs-open (This maximizes the chance of doing what the user expects if their KDE and GTK/GNOME URL-handling preferences disagree.) Fixes #16 --- src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 40e2fd3..36dbeff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -270,7 +270,14 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result { match browser { Browser::Default => open_on_unix_using_browser_env(url) .or_else(|_| -> Result { Command::new("xdg-open").arg(url).status() }) - .or_else(|_| -> Result { Command::new("gvfs-open").arg(url).status() }) + .or_else(|r| -> Result { + if let Ok(desktop) = ::std::env::var("XDG_CURRENT_DESKTOP") { + if desktop == "KDE" { + return Command::new("kioclient").arg("exec").arg(url).status() + } + } + Err(r) // If either `if` check fails, fall through to the next or_else + }).or_else(|_| -> Result { Command::new("gvfs-open").arg(url).status() }) .or_else(|_| -> Result { Command::new("gnome-open").arg(url).status() }) .or_else(|_| -> Result { Command::new("kioclient").arg("exec").arg(url).status() }) .or_else(|_| -> Result { Command::new("x-www-browser").arg(url).status() }), From e5d32e7b0966ccfd217a816cb8fbe10c87067af9 Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Sat, 26 Oct 2019 00:33:17 -0400 Subject: [PATCH 4/5] Run `cargo fmt` --- src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 36dbeff..c9c3c92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -273,13 +273,16 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result { .or_else(|r| -> Result { if let Ok(desktop) = ::std::env::var("XDG_CURRENT_DESKTOP") { if desktop == "KDE" { - return Command::new("kioclient").arg("exec").arg(url).status() + return Command::new("kioclient").arg("exec").arg(url).status(); } } - Err(r) // If either `if` check fails, fall through to the next or_else - }).or_else(|_| -> Result { Command::new("gvfs-open").arg(url).status() }) + Err(r) // If either `if` check fails, fall through to the next or_else + }) + .or_else(|_| -> Result { Command::new("gvfs-open").arg(url).status() }) .or_else(|_| -> Result { Command::new("gnome-open").arg(url).status() }) - .or_else(|_| -> Result { Command::new("kioclient").arg("exec").arg(url).status() }) + .or_else(|_| -> Result { + Command::new("kioclient").arg("exec").arg(url).status() + }) .or_else(|_| -> Result { Command::new("x-www-browser").arg(url).status() }), _ => Err(Error::new( ErrorKind::NotFound, From f3f86c794cd0930c94ac29aeeeeff5d7ffea7aee Mon Sep 17 00:00:00 2001 From: Stephan Sokolow Date: Mon, 28 Oct 2019 01:05:54 -0400 Subject: [PATCH 5/5] Don't wait for x-www-browser to exit before returning (Temporary solution to resolve by far the most likely place for this command to block in headless test conditions.) --- src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c9c3c92..7ee5b6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -283,7 +283,12 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result { .or_else(|_| -> Result { Command::new("kioclient").arg("exec").arg(url).status() }) - .or_else(|_| -> Result { Command::new("x-www-browser").arg(url).status() }), + .or_else(|e| -> Result { + if let Ok(_child) = Command::new("x-www-browser").arg(url).spawn() { + return Ok(ExitStatusExt::from_raw(0)); + } + Err(e) + }), _ => Err(Error::new( ErrorKind::NotFound, "Only the default browser is supported on this platform right now",