Skip to content

Commit

Permalink
Merge pull request #28 from aspenluxxxy/ios
Browse files Browse the repository at this point in the history
Add iOS support
  • Loading branch information
Byron authored Mar 10, 2021
2 parents ef91705 + 00119a7 commit 049f698
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 = "android",
Expand All @@ -66,6 +69,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 @@ -187,6 +203,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 = "android",
Expand Down

0 comments on commit 049f698

Please sign in to comment.