Skip to content

Commit

Permalink
chore: add error when failed to register url scheme on macOS, close #…
Browse files Browse the repository at this point in the history
…1295 (#1301)

* chore: add error when failed to register url scheme on macOS

* chore: add changelog
  • Loading branch information
pewsheen authored Jun 24, 2024
1 parent f56ae29 commit 556a359
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/chore-mac-add-url-scheme-register-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

On macOS, emit an error when the URL scheme registration fails.
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ pub enum Error {
CrossBeamRecvError(#[from] crossbeam_channel::RecvError),
#[error("Custom protocol task is invalid.")]
CustomProtocolTaskInvalid,
#[error("Failed to register URL scheme: {0}, could be due to invalid URL scheme or the scheme is already registered.")]
UrlSchemeRegisterError(String),
}
8 changes: 7 additions & 1 deletion src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,13 @@ impl InnerWebView {

(*handler).set_ivar("function", function as *mut _ as *mut c_void);
(*handler).set_ivar("webview_id", webview_id);
let () = msg_send![config, setURLSchemeHandler:handler forURLScheme:NSString::new(&name)];

(*config)
.send_message::<(id, NSString), ()>(
sel!(setURLSchemeHandler:forURLScheme:),
(handler, NSString::new(&name)),
)
.map_err(|_| crate::Error::UrlSchemeRegisterError(name))?;
}

// WebView and manager
Expand Down

0 comments on commit 556a359

Please sign in to comment.