Skip to content

Commit

Permalink
fix(mac): unsuppressing media permission request only for macOS 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pewsheen committed Mar 20, 2024
1 parent 3ec2ea9 commit 90a5447
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-unsuppress-media-request-for-mac.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

On macOS 14.0, unsuppressing the media permission request.
35 changes: 30 additions & 5 deletions src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ mod synthetic_mouse_events;
use cocoa::appkit::{NSView, NSViewHeightSizable, NSViewMinYMargin, NSViewWidthSizable};
use cocoa::{
base::{id, nil, NO, YES},
foundation::{NSDictionary, NSFastEnumeration, NSInteger},
foundation::{
NSDictionary, NSFastEnumeration, NSInteger, NSOperatingSystemVersion, NSProcessInfo,
},
};
use raw_window_handle::{HasWindowHandle, RawWindowHandle};

Expand Down Expand Up @@ -806,10 +808,19 @@ impl InnerWebView {
run_file_upload_panel as extern "C" fn(&Object, Sel, id, id, id, id),
);

ctl.add_method(
sel!(webView:requestMediaCapturePermissionForOrigin:initiatedByFrame:type:decisionHandler:),
request_media_capture_permission as extern "C" fn(&Object, Sel, id, id, id, id, id),
);
#[cfg(target_os = "macos")]
match operating_system_version() {
(14, 0, _) => {
// Do not suppress media request on 14.0:
// https://github.com/tauri-apps/wry/issues/1101
}
_ => {
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()
}
Expand Down Expand Up @@ -1201,8 +1212,22 @@ pub fn url_from_webview(webview: id) -> Result<String> {
.map_err(Into::into)
}

pub fn operating_system_version() -> (u64, u64, u64) {
unsafe {
let process_info: id = msg_send![class!(NSProcessInfo), processInfo];
let version: NSOperatingSystemVersion = msg_send![process_info, operatingSystemVersion];
(
version.majorVersion,
version.minorVersion,
version.patchVersion,
)
}
}

/// **Warning:** Panic occurs when caller application's `CFBundleDisplayName` contains non-ASCII characters.
pub fn platform_webview_version() -> Result<String> {
unsafe {
// bundleWithIdentifier: panic when CFBundleDisplayName contains non-ASCII characters.
let bundle: id =
msg_send![class!(NSBundle), bundleWithIdentifier: NSString::new("com.apple.WebKit")];
let dict: id = msg_send![bundle, infoDictionary];
Expand Down

0 comments on commit 90a5447

Please sign in to comment.