Looking to mimic something similar to what Discord has implemented. Basically, when someone attempts to open DevTools, I will do a check to determine if they have the permissions to access DevTools. If they do, I want to open DevTools. Otherwise, I just want to do nothing, or maybe do a popup. Currently my issue is I cannot seem to stop the default behavior by using the onkeyup event. Is there a better way to do this? Or something build in by default? I am using a brand new Electron Project with ReactJS (Typescript).
#Looking to add custom functionality to CTRL+SHIFT+I
9 messages · Page 1 of 1 (latest)
i think the default keybind of ctr+shift+i is an accelerator (shortcut) from the default Menu. maybe you could set your own Menu and have ctrl+shift+i just run your custom logic before opening the dev tools
Create native application menus and context menus.
I don't believe that works. At least I cannot get it to work. The menu I have works fine otherwise. It appears that dev tools will always open.
Do you wanna keep the default electron menu? You could remove that and instead use app before-input-event and when f12 is pressed toggle the devtools. That gives you full control on what you wanna do when f12 is pressed
That is how i did it
I don't think I have a need for a menu so that could work. I feel like there should be a way to keep the menu and still have it work though. I don't need the toggle dev tools as a menu option though. Could you provide me a code snippet so I can see what you are talking about? I am new to Electron and inexperienced with JS so learning as I go.
const browserWindow = new BrowserWindow(...);
browserWindow.removeMenu();
browserWindow.webContents.on('before-input-event', (_, input) => {
if (input.type === 'keyDown' && input.key === 'F12') {
browserWindow.webContents.openDevTools({ mode: 'detach' });
}
});
a older way of doing it was setting the menu to null. just in case you stumble on that later. but the new method is more clear i think