diff --git a/app/helpers/menu_template.js b/app/helpers/menu_template.js index d9c2e99e..924e3f94 100644 --- a/app/helpers/menu_template.js +++ b/app/helpers/menu_template.js @@ -1,7 +1,21 @@ -const { BrowserWindow } = require('electron') +const { BrowserWindow, dialog } = require('electron') const globalEmitter = require('../lib/globalEmitter') const Update = require('../lib/update') +const toggleDevTools = () => { + const currentWindow = BrowserWindow.getFocusedWindow() + if (currentWindow) { + currentWindow.toggleDevTools() + } else { + dialog.showMessageBox({ + type: 'error', + message: 'No focused window', + detail: 'There are currently no focused windows.', + buttons: ['Ok'], + }) + } +} + const appTemplate = [ { label: 'Zazu', @@ -15,9 +29,7 @@ const appTemplate = [ { label: 'Toggle DevTools', accelerator: 'Alt+CmdOrCtrl+I', - click: function () { - BrowserWindow.getFocusedWindow().toggleDevTools() - }, + click: toggleDevTools, }, { label: 'Quit', @@ -57,9 +69,7 @@ const trayTemplate = [ { label: 'Toggle DevTools', accelerator: 'Alt+CmdOrCtrl+I', - click: function () { - BrowserWindow.getFocusedWindow().toggleDevTools() - }, + click: toggleDevTools, }, ], },