Skip to content

Commit

Permalink
Add iOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
aspen committed Mar 9, 2021
1 parent 330c2d0 commit 00119a7
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub use windows::{that, with};
#[cfg(target_os = "macos")]
pub use macos::{that, with};

#[cfg(target_os = "ios")]
pub use ios::{that, with};

#[cfg(any(
target_os = "linux",
target_os = "freebsd",
Expand All @@ -65,6 +68,19 @@ pub use macos::{that, with};
))]
pub use unix::{that, with};

#[cfg(not(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_os = "windows",
)))]
compile_error!("open is not supported on this platform");

/// Convenience function for opening the passed path in a new thread.
/// See documentation of `that(...)` for more details.
pub fn that_in_background<T: AsRef<OsStr> + Sized>(
Expand Down Expand Up @@ -186,6 +202,35 @@ mod macos {
}
}

#[cfg(target_os = "ios")]
mod ios {
use std::{
ffi::OsStr,
io::Result,
process::{Command, ExitStatus, Stdio},
};

pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> Result<ExitStatus> {
Command::new("uiopen")
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg("--url")
.arg(path.as_ref())
.spawn()?
.wait()
}

pub fn with<T: AsRef<OsStr> + Sized>(path: T, app: impl Into<String>) -> Result<ExitStatus> {
Command::new("uiopen")
.arg("--url")
.arg(path.as_ref())
.arg("--bundleid")
.arg(app.into())
.spawn()?
.wait()
}
}

#[cfg(any(
target_os = "linux",
target_os = "freebsd",
Expand Down

0 comments on commit 00119a7

Please sign in to comment.