SirReadsALot / Deeeep.io-Desktop-Client

A desktop client with good features for the hit io game, deeeep.io!

Home Page:https://sirreadsalot.github.io/sralcodeproj/Deeeep.io_Desktop_Client.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google Chrome shortcuts can be used to create new windows.

ItsPi3141 opened this issue · comments

commented

How to reproduce:

  1. Open DDC, either in prod or dev env
  2. Press Ctrl+N (Cmd+N on MacOS)
  3. 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.

doing that will no longer create a new window

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(); 
         } 
 }); 

yeah because I used that code
I put in some bits of your original pull request code into the actual code

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.