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

Fix: Remove extra soft prompt asking for media permission on every app launch in macOS #694

Merged
merged 4 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/fix-double-dialog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

Fix double permission dialog on macOS 12+ and iOS 15+.
23 changes: 23 additions & 0 deletions src/webview/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,35 @@ impl InnerWebView {
}
}

extern "C" fn request_media_capture_permission(
_this: &Object,
_: Sel,
_webview: id,
_origin: id,
_frame: id,
_type: id,
decision_handler: id,
) {
unsafe {
let decision_handler = decision_handler as *mut block::Block<(NSInteger,), c_void>;
//https://developer.apple.com/documentation/webkit/wkpermissiondecision?language=objc
(*decision_handler).call((1,));
}
}

let ui_delegate = match ClassDecl::new("WebViewUIDelegate", class!(NSObject)) {
Some(mut ctl) => {
ctl.add_method(
sel!(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:),
run_file_upload_panel as extern "C" fn(&Object, Sel, id, id, id, id),
);

// Disable media dialogs
ctl.add_method(
sel!(webView:requestMediaCapturePermissionForOrigin:initiatedByFrame:type:decisionHandler:),
request_media_capture_permission as extern "C" fn(&Object, Sel, id, id, id, id, id),
);

ctl.register()
}
None => class!(WebViewUIDelegate),
Expand Down