Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added visionOS support for Apple Vision Pro #1286

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
Prev Previous commit
Next Next commit
more visionos configuration
eugenehp committed May 29, 2024
commit a979127af84e849687937a3fce09ab6fa403b437
2 changes: 2 additions & 0 deletions bench/tests/src/cpu_intensive.rs
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -36,6 +37,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
2 changes: 2 additions & 0 deletions bench/tests/src/custom_protocol.rs
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -60,6 +61,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
2 changes: 2 additions & 0 deletions bench/tests/src/hello_world.rs
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -48,6 +49,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

fn main() {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
if target_os == "macos" || target_os == "ios" {
if target_os == "macos" || target_os == "ios" || target_os == "visionos" {
println!("cargo:rustc-link-lib=framework=WebKit");
}

2 changes: 2 additions & 0 deletions examples/async_custom_protocol.rs
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -30,6 +31,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
2 changes: 2 additions & 0 deletions examples/custom_protocol.rs
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -30,6 +31,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
2 changes: 2 additions & 0 deletions examples/custom_titlebar.rs
Original file line number Diff line number Diff line change
@@ -245,6 +245,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -253,6 +254,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
3 changes: 3 additions & 0 deletions examples/gtk_multiwebview.rs
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let fixed = {
@@ -38,6 +39,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
return WebViewBuilder::new_as_child(&window);
@@ -46,6 +48,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
{
2 changes: 2 additions & 0 deletions examples/multiwindow.rs
Original file line number Diff line number Diff line change
@@ -96,6 +96,7 @@ fn create_new_window(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -104,6 +105,7 @@ fn create_new_window(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
5 changes: 5 additions & 0 deletions examples/reparent.rs
Original file line number Diff line number Diff line change
@@ -19,12 +19,14 @@ use {tao::platform::windows::WindowExtWindows, wry::WebViewExtWindows};
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
use {
@@ -41,6 +43,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -49,6 +52,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
@@ -97,6 +101,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
webview
2 changes: 2 additions & 0 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -25,6 +26,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
2 changes: 2 additions & 0 deletions examples/streaming.rs
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -35,6 +36,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
2 changes: 2 additions & 0 deletions examples/transparent.rs
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
))]
let builder = WebViewBuilder::new(&window);
@@ -42,6 +43,7 @@ fn main() -> wry::Result<()> {
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "android"
)))]
let builder = {
10 changes: 5 additions & 5 deletions src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ impl InnerWebView {
let ns_view = match window.window_handle()?.as_raw() {
#[cfg(target_os = "macos")]
RawWindowHandle::AppKit(w) => w.ns_view.as_ptr(),
#[cfg(target_os = "ios")]
#[cfg(any(target_os = "ios", target_os = "visionos"))]
RawWindowHandle::UiKit(w) => w.ui_view.as_ptr(),
_ => return Err(Error::UnsupportedWindowHandle),
};
@@ -141,7 +141,7 @@ impl InnerWebView {
let ns_view = match window.window_handle()?.as_raw() {
#[cfg(target_os = "macos")]
RawWindowHandle::AppKit(w) => w.ns_view.as_ptr(),
#[cfg(target_os = "ios")]
#[cfg(any(target_os = "ios", target_os = "visionos"))]
RawWindowHandle::UiKit(w) => w.ui_view.as_ptr(),
_ => return Err(Error::UnsupportedWindowHandle),
};
@@ -478,7 +478,7 @@ impl InnerWebView {

let _: id = msg_send![_preference, setValue:_yes forKey:NSString::new("allowsPictureInPictureMediaPlayback")];

#[cfg(target_os = "ios")]
#[cfg(any(target_os = "ios", target_os = "visionos"))]
let _: id = msg_send![config, setAllowsInlineMediaPlayback: YES];

if attributes.autoplay {
@@ -544,7 +544,7 @@ impl InnerWebView {
}
}

#[cfg(target_os = "ios")]
#[cfg(any(target_os = "ios", target_os = "visionos"))]
{
let frame: CGRect = msg_send![ns_view, frame];
// set all autoresizingmasks
@@ -1022,7 +1022,7 @@ r#"Object.defineProperty(window, 'ipc', {
let _: () = msg_send![app, activateIgnoringOtherApps: YES];
}

#[cfg(target_os = "ios")]
#[cfg(any(target_os = "ios", target_os = "visionos"))]
{
let _: () = msg_send![ns_view, addSubview: webview];
}