chore: fix wry example context menu closes immediately

This commit is contained in:
amrbashir 2023-07-26 03:37:19 +03:00
parent 98701d0b32
commit 5fbe39e995
No known key found for this signature in database
GPG key ID: BBD7A47A2003FF33

View file

@ -166,7 +166,15 @@ fn main() -> wry::Result<()> {
<script>
window.addEventListener('contextmenu', (e) => {
e.preventDefault();
window.ipc.postMessage(`showContextMenu:${e.clientX},${e.clientY}`);
// if e.button is -1 on chromuim or e.buttons is 0 (as a fallback on webkit2gtk) then this event was fired by keyboard
if (e.button === -1 || e.buttons === 0) {
window.ipc.postMessage(`showContextMenu:${e.clientX},${e.clientY}`);
}
})
window.addEventListener('mouseup', (e) => {
if (e.button === 2) {
window.ipc.postMessage(`showContextMenu:${e.clientX},${e.clientY}`);
}
})
</script>
</body>