Skip to content

Commit

Permalink
Fix beep sound, closes #799 (#801)
Browse files Browse the repository at this point in the history
* Beepfix attempt

* Add changefile
  • Loading branch information
probablykasper committed Dec 10, 2022
1 parent e25c72e commit 94256c3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changes/beepfix.md
@@ -0,0 +1,5 @@
---
"wry": patch
---

Fix the beep sound on macOS
8 changes: 7 additions & 1 deletion examples/custom_protocol_page1.html
Expand Up @@ -15,8 +15,14 @@
<h1>Welcome to WRY!</h1>
<p>Page 1</p>
<textarea></textarea>
<p id="keypresses"></p>
<a href="/custom_protocol_page2.html">Link</a>
<script type="text/javascript" src="/custom_protocol_script.js"></script>
<script type="text/javascript">
document.body.addEventListener('keydown', (event) => {
document.querySelector('#keypresses').innerHTML += ' ' + event.key
})
</script>
</body>

</html>
</html>
21 changes: 20 additions & 1 deletion src/webview/wkwebview/mod.rs
Expand Up @@ -687,7 +687,26 @@ r#"Object.defineProperty(window, 'ipc', {
// Inject the web view into the window as main content
#[cfg(target_os = "macos")]
{
let parent_view_cls = class!(NSView);
let parent_view_cls = match ClassDecl::new("WryWebViewParent", class!(NSView)) {
Some(mut decl) => {
decl.add_method(
sel!(keyDown:),
key_down as extern "C" fn(&mut Object, Sel, id),
);

extern "C" fn key_down(_this: &mut Object, _sel: Sel, event: id) {
unsafe {
let app = cocoa::appkit::NSApp();
let menu: id = msg_send![app, mainMenu];
let () = msg_send![menu, performKeyEquivalent: event];
}
}

decl.register()
}
None => class!(NSView),
};

let parent_view: id = msg_send![parent_view_cls, alloc];
let _: () = msg_send![parent_view, init];
parent_view.setAutoresizingMask_(NSViewHeightSizable | NSViewWidthSizable);
Expand Down

0 comments on commit 94256c3

Please sign in to comment.