Skip to content

Commit a192f51

Browse files
n0tooseamodm
authored andcommitted
Added initial support for Haiku
1 parent dd2a0bb commit a192f51

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/lib.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ pub enum Browser {
7171

7272
///Mac OS Safari
7373
Safari,
74+
75+
///Haiku's WebPositive
76+
WebPositive,
7477
}
7578

7679
///The Error type for parsing a string into a Browser.
@@ -104,6 +107,7 @@ impl fmt::Display for Browser {
104107
Browser::Chrome => f.write_str("Chrome"),
105108
Browser::Opera => f.write_str("Opera"),
106109
Browser::Safari => f.write_str("Safari"),
110+
Browser::WebPositive => f.write_str("WebPositive"),
107111
}
108112
}
109113
}
@@ -119,6 +123,7 @@ impl FromStr for Browser {
119123
"chrome" => Ok(Browser::Chrome),
120124
"opera" => Ok(Browser::Opera),
121125
"safari" => Ok(Browser::Safari),
126+
"webpositive" => Ok(Browser::WebPositive),
122127
_ => Err(ParseBrowserError),
123128
}
124129
}
@@ -240,6 +245,7 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result<ExitStatus> {
240245
Browser::Chrome => Some("Google Chrome"),
241246
Browser::Opera => Some("Opera"),
242247
Browser::Safari => Some("Safari"),
248+
Browser::WebPositive => Some("WebPositive"),
243249
_ => None,
244250
};
245251
match app {
@@ -257,13 +263,14 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result<ExitStatus> {
257263
///
258264
/// The mechanism of opening the default browser is as follows:
259265
/// 1. Attempt to use $BROWSER env var if available
260-
/// 2. Attempt to open the url via xdg-open, gvfs-open, gnome-open, respectively, whichever works
266+
/// 2. Attempt to open the url via xdg-open, gvfs-open, gnome-open, open, respectively, whichever works
261267
/// first
262268
#[cfg(any(
263269
target_os = "linux",
264270
target_os = "freebsd",
265271
target_os = "netbsd",
266-
target_os = "openbsd"
272+
target_os = "openbsd",
273+
target_os = "haiku"
267274
))]
268275
#[inline]
269276
fn open_browser_internal(browser: Browser, url: &str) -> Result<ExitStatus> {
@@ -280,6 +287,7 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result<ExitStatus> {
280287
})
281288
.or_else(|_| -> Result<ExitStatus> { Command::new("gvfs-open").arg(url).status() })
282289
.or_else(|_| -> Result<ExitStatus> { Command::new("gnome-open").arg(url).status() })
290+
.or_else(|_| -> Result<ExitStatus> { Command::new("open").arg(url).status() })
283291
.or_else(|_| -> Result<ExitStatus> {
284292
Command::new("kioclient").arg("exec").arg(url).status()
285293
})
@@ -299,7 +307,8 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result<ExitStatus> {
299307
target_os = "linux",
300308
target_os = "freebsd",
301309
target_os = "netbsd",
302-
target_os = "openbsd"
310+
target_os = "openbsd",
311+
target_os = "haiku"
303312
))]
304313
fn open_on_unix_using_browser_env(url: &str) -> Result<ExitStatus> {
305314
let browsers = ::std::env::var("BROWSER")
@@ -339,9 +348,10 @@ fn open_on_unix_using_browser_env(url: &str) -> Result<ExitStatus> {
339348
target_os = "linux",
340349
target_os = "freebsd",
341350
target_os = "netbsd",
342-
target_os = "openbsd"
351+
target_os = "openbsd",
352+
target_os = "haiku"
343353
)))]
344-
compile_error!("Only Windows, Mac OS, Linux and *BSD are currently supported");
354+
compile_error!("Only Windows, Mac OS, Linux, *BSD and Haiku are currently supported");
345355

346356
#[test]
347357
fn test_open_default() {
@@ -373,3 +383,9 @@ fn test_open_internet_explorer() {
373383
fn test_open_safari() {
374384
assert!(open_browser(Browser::Safari, "http://github.com").is_ok());
375385
}
386+
387+
#[test]
388+
#[ignore]
389+
fn test_open_webpositive() {
390+
assert!(open_browser(Browser::WebPositive, "http://github.com").is_ok());
391+
}

0 commit comments

Comments
 (0)