diff --git a/.gitignore b/.gitignore index de67bee8b8..55eaa3ef35 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ compile_commands.json .envrc .cache yarn-error.log +.DS_Store # Coverage coverage diff --git a/static/templates/accelerator/main.js b/static/templates/globalShortcut/main.js similarity index 59% rename from static/templates/accelerator/main.js rename to static/templates/globalShortcut/main.js index 7124ce7a60..5696010a47 100644 --- a/static/templates/accelerator/main.js +++ b/static/templates/globalShortcut/main.js @@ -1,9 +1,17 @@ +// The globalShortcut module can register/unregister a global keyboard shortcut +// with the operating system so that you can customize the operations for various +// shortcuts. +// +// Note: The shortcut is global; it will work even if the app does not have the +// keyboard focus. You should not use this module until the ready event of the +// app module is emitted. In this example, we're using "Accelerators": // Accelerators are Strings that can contain multiple modifiers and key codes, // combined by the + character, and are used to define keyboard shortcuts // throughout your application. // // For more info, see: // https://electronjs.org/docs/api/accelerator +// https://electronjs.org/docs/api/global-shortcut const { app, globalShortcut } = require('electron') @@ -22,3 +30,11 @@ app.on('ready', () => { globalShortcut.register('VolumeUp', () => console.log(`Turn it up!`)) globalShortcut.register('VolumeDown', () => console.log(`Turn it down!`)) }) + +app.on('will-quit', () => { + // Unregister a shortcut. + globalShortcut.unregister('CommandOrControl+Y') + + // Unregister all shortcuts. + globalShortcut.unregisterAll() +})