Skip to content

Commit

Permalink
fix(macos): download breaking app on macOS older than 11.3, closes #755
Browse files Browse the repository at this point in the history
… (#756)

* fix(macos): download breaking app on macOS older than 11.3, closes #755

* fix ci
  • Loading branch information
lucasfernog committed Nov 15, 2022
1 parent 3d3ea80 commit e69ddc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/download-macos-version.md
@@ -0,0 +1,5 @@
---
"wry": patch
---

Fix download implementation on macOS older than 11.3.
13 changes: 10 additions & 3 deletions src/webview/wkwebview/mod.rs
Expand Up @@ -371,17 +371,24 @@ impl InnerWebView {
// Navigation handler
extern "C" fn navigation_policy(this: &Object, _: Sel, _: id, action: id, handler: id) {
unsafe {
// shouldPerformDownload is only available on macOS 11.3+
let can_download: BOOL =
msg_send![action, respondsToSelector: sel!(shouldPerformDownload)];
let should_download: BOOL = if can_download == YES {
msg_send![action, shouldPerformDownload]
} else {
NO
};
let request: id = msg_send![action, request];
let url: id = msg_send![request, URL];
let url: id = msg_send![url, absoluteString];
let url = NSString(url);
let should_download: bool = msg_send![action, shouldPerformDownload];
let target_frame: id = msg_send![action, targetFrame];
let is_main_frame: bool = msg_send![target_frame, isMainFrame];

let handler = handler as *mut block::Block<(NSInteger,), c_void>;

if should_download {
if should_download == YES {
let has_download_handler = this.get_ivar::<*mut c_void>("HasDownloadHandler");
if !has_download_handler.is_null() {
let has_download_handler = &mut *(*has_download_handler as *mut Box<bool>);
Expand Down Expand Up @@ -491,7 +498,7 @@ impl InnerWebView {
let download_delegate = if attributes.download_started_handler.is_some()
|| attributes.download_completed_handler.is_some()
{
let cls = match ClassDecl::new("DownloadDelegate", class!(NSObject)) {
let cls = match ClassDecl::new("WryDownloadDelegate", class!(NSObject)) {
Some(mut cls) => {
cls.add_ivar::<*mut c_void>("started");
cls.add_ivar::<*mut c_void>("completed");
Expand Down

0 comments on commit e69ddc6

Please sign in to comment.