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(macos): override performKeyEquivalent only when creating child WebView #1260

Merged
merged 1 commit into from
May 13, 2024
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-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
Loading