Prevent global shorcuts from interferring with other applications (#433)

Fixes: https://github.com/resin-io/etcher/issues/389
Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
Juan Cruz Viotti 2016-05-24 12:40:25 -04:00
parent 2948d13075
commit 6af2bd0d30

View File

@ -63,8 +63,22 @@ electron.app.on('ready', function() {
mainWindow = null;
});
electron.globalShortcut.register('CmdOrCtrl+Alt+I', function() {
mainWindow.webContents.openDevTools();
// For some reason, Electron shortcuts are registered
// globally, which means that the app listers for shorcuts
// even if its not currently focused, potentially interferring
// with shorcuts registered by other applications.
// As a workaround, we register all shortcuts when the windows
// gains focus, and unregister them when the windows loses focus.
// See http://electron.atom.io/docs/api/global-shortcut/
mainWindow.on('focus', function() {
electron.globalShortcut.register('CmdOrCtrl+Alt+I', function() {
mainWindow.webContents.openDevTools();
});
});
mainWindow.on('blur', function() {
electron.globalShortcut.unregisterAll();
});
mainWindow.loadURL(`file://${path.join(__dirname, 'index.html')}`);