-
-
Notifications
You must be signed in to change notification settings - Fork 307
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): global keys shortcuts #1156
Conversation
I think I need an example to test that menu item accelerator works on both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
I've tested it on Tauri examples with single and multiple webviews, and it works after this patch.
Before we merge this commit, the CI requires you to add a change file in the .changes
folder, and also needs you to sign your commits.
For the change file, you can reference the README.md
or existing change file under .changes
folder.
Signing commit: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
@thewh1teagle You will need to sign your commits and then I could merge the PR. |
1ddd267
to
a0fcc42
Compare
Signed and added a file to |
* fix: send key equivalent to menu * Create wkwebview.md * Update wkwebview.md
@wusyong @pewsheen this is breaking client-side shortcut handling. For instance this code: ;(function () {
function toggleDevtoolsHotkey() {
const osName = __TEMPLATE_os_name__
const isHotkey =
osName === 'macos'
? (event) => event.metaKey && event.altKey && event.key === 'I'
: (event) => event.ctrlKey && event.shiftKey && event.key === 'I'
document.addEventListener('keydown', (event) => {
if (isHotkey(event)) {
window.__TAURI_INTERNALS__.invoke(
'plugin:webview|internal_toggle_devtools'
)
}
})
}
if (
document.readyState === 'complete' ||
document.readyState === 'interactive'
) {
toggleDevtoolsHotkey()
} else {
window.addEventListener('DOMContentLoaded', toggleDevtoolsHotkey, true)
}
})() I won't get the third event because the menu consumed it (I think). |
@lucasfernog @thewh1teagle For now, I'll revert the MR first and see if we have a better way to deal with it. Btw, the toggle devtool shortcut on Mac seems to have another issue telling it is the |
Yeah I noticed the key code issue working on another project. Thanks for investigating it! |
I found that if we return Also checked menu_shortcuts.patch# wry - patch which fix global menu keyboard shortcuts on multiwebview window in wry library - by github.com/thewh1teagle
diff --git a/src/wkwebview/mod.rs b/src/wkwebview/mod.rs
index d6a9ef4..7538f1c 100644
--- a/src/wkwebview/mod.rs
+++ b/src/wkwebview/mod.rs
@@ -339,6 +339,14 @@ 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 { |
Cool! It looks good on my side. Would you mind opening another PR for this? |
Since
WkWebview
implementation usedwebview::new_as_child
, global keyboard shortcuts didn't worked inMacOS
even when there's a menu with global shortcuts.for instnace,
command + h
(for hiding the window) didn't worked, and any other menu shortcut inMacOS
Resolve
tauri-apps/tauri#8676
Context
https://discord.com/channels/616186924390023171/1199750637240459327