Skip to content

Commit

Permalink
Add support for visionOS
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Apr 23, 2024
1 parent a16d6ae commit e9bfcac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ core-foundation = "0.9"
jni = "0.21"
ndk-context = "0.1"

[target.'cfg(target_os = "ios")'.dependencies]
[target.'cfg(any(target_os = "ios", target_os = "tvos", target_os = "visionos"))'.dependencies]
raw-window-handle = "0.5.0"
objc = "0.2.7"

Expand Down
4 changes: 3 additions & 1 deletion src/ios.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::{Browser, BrowserOptions, Error, ErrorKind, Result, TargetType};
use objc::{class, msg_send, runtime::Object, sel, sel_impl};

/// Deal with opening of browsers on iOS
/// Deal with opening of browsers on iOS/tvOS/visionOS.
///
/// watchOS doesn't have a browser, so this won't work there.
pub(super) fn open_browser_internal(
_browser: Browser,
target: &TargetType,
Expand Down
34 changes: 24 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
//!
//! ## Platform Support Status
//!
//! | Platform | Supported | Browsers | Test status |
//! |----------|-----------|----------|-------------|
//! | macos | ✅ | default + [others](https://docs.rs/webbrowser/latest/webbrowser/enum.Browser.html) | ✅ |
//! | windows | ✅ | default only | ✅ |
//! | linux/wsl | ✅ | default only (respects $BROWSER env var, so can be used with other browsers) | ✅ |
//! | android | ✅ | default only | ✅ |
//! | ios | ✅ | default only | ✅ |
//! | wasm | ✅ | default only | ✅ |
//! | Platform | Supported | Browsers | Test status |
//! |-----------------------|-----------|----------|-------------|
//! | macOS | ✅ | default + [others](https://docs.rs/webbrowser/latest/webbrowser/enum.Browser.html) | ✅ |
//! | windows | ✅ | default only | ✅ |
//! | linux/wsl | ✅ | default only (respects $BROWSER env var, so can be used with other browsers) | ✅ |
//! | android | ✅ | default only | ✅ |
//! | iOS/tvOS/visionOS | ✅ | default only | ✅ |
//! | wasm | ✅ | default only | ✅ |
//! | unix (*bsd, aix etc.) | ✅ | default only (respects $BROWSER env var, so can be used with other browsers) | Manual |
//!
//! ## Consistent Behaviour
Expand All @@ -39,7 +39,10 @@
//! * `disable-wsl` - this disables WSL `file` implementation (`http` still works)
//! * `wasm-console` - this enables logging to wasm console (valid only on wasm platform)

#[cfg_attr(any(target_os = "ios", target_os = "tvos"), path = "ios.rs")]
#[cfg_attr(
any(target_os = "ios", target_os = "tvos", target_os = "visionos"),
path = "ios.rs"
)]
#[cfg_attr(target_os = "macos", path = "macos.rs")]
#[cfg_attr(target_os = "android", path = "android.rs")]
#[cfg_attr(target_family = "wasm", path = "wasm.rs")]
Expand All @@ -50,6 +53,7 @@
not(any(
target_os = "ios",
target_os = "tvos",
target_os = "visionos",
target_os = "macos",
target_os = "android",
target_family = "wasm",
Expand All @@ -67,6 +71,7 @@ mod os;
not(any(
target_os = "ios",
target_os = "tvos",
target_os = "visionos",
target_os = "macos",
target_os = "android",
target_family = "wasm",
Expand Down Expand Up @@ -316,6 +321,7 @@ pub fn open_browser_with_options(
if cfg!(any(
target_os = "ios",
target_os = "tvos",
target_os = "visionos",
target_os = "macos",
target_os = "android",
target_family = "wasm",
Expand All @@ -338,6 +344,8 @@ impl TargetType {
feature = "hardened",
target_os = "android",
target_os = "ios",
target_os = "tvos",
target_os = "visionos",
target_family = "wasm"
))]
fn is_http(&self) -> bool {
Expand All @@ -346,7 +354,13 @@ impl TargetType {

/// If `target` represents a valid http/https url, return the str corresponding to it
/// else return `std::io::Error` of kind `std::io::ErrorKind::InvalidInput`
#[cfg(any(target_os = "android", target_os = "ios", target_family = "wasm"))]
#[cfg(any(
target_os = "android",
target_os = "ios",
target_os = "tvos",
target_os = "visionos",
target_family = "wasm"
))]
fn get_http_url(&self) -> Result<&str> {
if self.is_http() {
Ok(self.0.as_str())
Expand Down

0 comments on commit e9bfcac

Please sign in to comment.