Skip to content

Commit

Permalink
feat(macos): use WKWebView's inspectable property (#923)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Apr 9, 2023
1 parent 3cc45cb commit c3f7304
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/inspector-ios-16.4-macos-13.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Use the new WKWebView `inspectable` property if available (iOS 16.4, macOS 13.3).
20 changes: 12 additions & 8 deletions src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,6 @@ impl InnerWebView {
#[cfg(target_os = "macos")]
(*webview).set_ivar(ACCEPT_FIRST_MOUSE, attributes.accept_first_mouse);

#[cfg(any(debug_assertions, feature = "devtools"))]
if attributes.devtools {
// Equivalent Obj-C:
// [[config preferences] setValue:@YES forKey:@"developerExtrasEnabled"];
let dev = NSString::new("developerExtrasEnabled");
let _: id = msg_send![_preference, setValue:_yes forKey:dev];
}

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

if attributes.autoplay {
Expand Down Expand Up @@ -360,6 +352,18 @@ impl InnerWebView {
let _: () = msg_send![scroll, setBounces: NO];
}

#[cfg(any(debug_assertions, feature = "devtools"))]
if attributes.devtools {
let has_inspectable_property: BOOL =
msg_send![webview, respondsToSelector: sel!(setInspectable:)];
if has_inspectable_property == YES {
let _: () = msg_send![webview, setInspectable: YES];
}
// this cannot be on an `else` statement, it does not work on macOS :(
let dev = NSString::new("developerExtrasEnabled");
let _: id = msg_send![_preference, setValue:_yes forKey:dev];
}

// allowsBackForwardNavigation
#[cfg(target_os = "macos")]
{
Expand Down

0 comments on commit c3f7304

Please sign in to comment.