electron#globalShortcut JavaScript Examples

The following examples show how to use electron#globalShortcut. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.js    From ioHookElectronWebpack with MIT License 6 votes vote down vote up
app.on("ready", async () => {
  try {
    globalShortcut.register('Control+Shift+I', () => {
      if (mainWindow.webContents.isDevToolsOpened()) {
        mainWindow.webContents.closeDevTools()
      } else {
        mainWindow.webContents.openDevTools();
      }
    });

    //protocol.interceptFileProtocol('file', (request, callback) => {
      //const url = request.url.substr(7)    /* all urls start with 'file://' */
      //callback({ path: path.normalize('${__dirname}/${url}')})
    //});

    // Name the protocol whatever you want
    const protocolName = 'safe-file-protocol';

    // NEEDED FOR PROPER IMAGES LOADING
    protocol.registerFileProtocol(protocolName, (request, callback) => {
      const url = request.url.replace(`${protocolName}://`, '');
      try {
        return callback(decodeURIComponent(url))
      } catch (error) {
        // Handle the error as needed
        log.error(error)
      }
    });

    createWindow();
  } catch (error) {
    log.error(error);
    ioHook.stop();
    app.quit();
  }
});
Example #2
Source File: PageConfig.js    From ntfstool with MIT License 6 votes vote down vote up
export function openPages() {
    //shortcut to toggle debug window
    globalShortcut.register('Option+L', () => {
        let focusWin = BrowserWindow.getFocusedWindow()
        focusWin && focusWin.toggleDevTools()
    });

    openHomePage();

    openTrayPage();

    monitorUsb();

    setTimeout(function () {
        openDialogPage("hide");
        openSettingPage("hide");
        openFeedBackPage("hide");
    }, 3000)
}