Google Chrome shortcuts can be used to create new windows.
ItsPi3141 opened this issue · 4 comments
ItsPi3141 commented
How to reproduce:
- Open DDC, either in prod or dev env
- Press Ctrl+N (Cmd+N on MacOS)
- A new Google chrome (or whatever browser Lorca is using) window will open up
Possible fix:
Use JavaScript to add an event listener to capture shortcut key events that would otherwise trigger Chrome shortcuts.
SirReadsALot commented
doing that will no longer create a new window
ItsPi3141 commented
Why would it not create a new window? I when I tested it, it launched just fine. So there's obviously no problem with it.
Here's the code I used (put it in src/script.js):
const ctrlOrCmdCodes = new Set(["KeyD", "KeyE", "KeyD", "KeyG", "KeyN", "KeyO", "KeyP", "KeyQ", "KeyR", "KeyS", "KeyT", "KeyW", "KeyY", "Tab", "PageUp", "PageDown", "F4"]);
const cmdCodes = new Set(["BracketLeft", "BracketRight", "Comma"]);
const cmdOptionCodes = new Set(["ArrowLeft", "ArrowRight", "KeyB"]);
const ctrlShiftCodes = new Set(["KeyQ", "KeyW"]);
const altCodes = new Set(["Home", "ArrowLeft", "ArrowRight", "F4"]);
function preventDefaultShortcuts(event) {
let prevent = false;
if (navigator.userAgent.match(/Mac OS X/)) {
if (event.metaKey) {
if (event.keyCode > 48 && event.keyCode <= 57)
// 1-9
prevent = true;
if (ctrlOrCmdCodes.has(event.code) || cmdCodes.has(event.code)) prevent = true;
if (event.shiftKey && cmdOptionCodes.has(event.code)) prevent = true;
if (event.code === "ArrowLeft" || event.code === "ArrowRight") {
if (!event.contentEditable && event.target.nodeName !== "INPUT" && event.target.nodeName !== "TEXTAREA") prevent = true;
}
}
} else {
if (event.code === "F4") prevent = true;
if (event.ctrlKey) {
if (event.keyCode > 48 && event.keyCode <= 57)
// 1-9
prevent = true;
if (ctrlOrCmdCodes.has(event.code)) prevent = true;
if (event.shiftKey && ctrlShiftCodes.has(event.code)) prevent = true;
}
if (event.altKey && altCodes.has(event.code)) prevent = true;
}
if (prevent) event.preventDefault();
}
document.addEventListener("keydown", preventDefaultShortcuts, false);
document.addEventListener("keydown", (event) => {
if ((event.key === "q" || event.key === "Q") && (event.metaKey || event.ctrlKey)) {
event.preventDefault();
}
});
SirReadsALot commented
yeah because I used that code
I put in some bits of your original pull request code into the actual code
ItsPi3141 commented
Does it show the splash screen and then not show the webpage? Or does the splash screen not show?
I'll take a look at this later. But as I remember it, it worked fine with the eventlistener.