Skip to content

Commit

Permalink
fix: override performKeyEquivalent only when creating child webview (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pewsheen authored May 13, 2024
1 parent daa6136 commit 0f3c886
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-macos-key-equivalent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

On macOS, fixed an issue of not being able to listen to the cmd+key event in javascript in single WebView.
24 changes: 15 additions & 9 deletions src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,6 @@ impl InnerWebView {
sel!(acceptsFirstMouse:),
accept_first_mouse as extern "C" fn(&Object, Sel, id) -> BOOL,
);
decl.add_method(
sel!(performKeyEquivalent:),
key_equivalent as extern "C" fn(&mut Object, Sel, id) -> BOOL,
);

extern "C" fn key_equivalent(_this: &mut Object, _sel: Sel, _event: id) -> BOOL {
NO
}

extern "C" fn accept_first_mouse(this: &Object, _sel: Sel, _event: id) -> BOOL {
unsafe {
let accept: bool = *this.get_ivar(ACCEPT_FIRST_MOUSE);
Expand All @@ -417,6 +408,21 @@ impl InnerWebView {
}
}
}

// This is a temporary workaround for https://github.com/tauri-apps/tauri/issues/9426
// FIXME: When the webview is a child webview, performKeyEquivalent always return YES
// and stop propagating the event to the window, hence the menu shortcut won't be
// triggered. However, overriding this method also means the cmd+key event won't be
// handled in webview, which means the key cannot be listened by JavaScript.
if is_child {
decl.add_method(
sel!(performKeyEquivalent:),
key_equivalent as extern "C" fn(&mut Object, Sel, id) -> BOOL,
);
extern "C" fn key_equivalent(_this: &mut Object, _sel: Sel, _event: id) -> BOOL {
NO
}
}
}
decl.register()
}
Expand Down

0 comments on commit 0f3c886

Please sign in to comment.