From ce54e8d9a1553504a1e4f57fce1b3d9143ee0d5f Mon Sep 17 00:00:00 2001 From: Alex Anderson Date: Tue, 7 May 2019 21:08:07 -0600 Subject: [PATCH] Fixes an issue where kiosk mode doesn't work properly. --- src/helpers/menuTemplate.js | 86 ------------------------------ src/helpers/setMenubar.js | 101 +++++++++++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 93 deletions(-) delete mode 100644 src/helpers/menuTemplate.js diff --git a/src/helpers/menuTemplate.js b/src/helpers/menuTemplate.js deleted file mode 100644 index d1a18ed..0000000 --- a/src/helpers/menuTemplate.js +++ /dev/null @@ -1,86 +0,0 @@ -const { BrowserWindow, app } = require("electron"); -const { windows, addWindow } = require("./multiWindow"); -const { getLoadedUrl } = require("./loadedUrl"); -const { clearMenubar, setMenubar } = require("./setMenubar"); - -module.exports = function() { - var template = [ - { - label: "Application", - submenu: [ - { - label: "About Application", - selector: "orderFrontStandardAboutPanel:" - }, - { - label: "Quit", - accelerator: "CmdOrCtrl+Alt+Q", - click: function() { - app.quit(); - } - } - ] - }, - { - label: "File", - submenu: [ - { - label: "New Window", - accelerator: "CmdOrCtrl+N", - click: function() { - addWindow({ loadedUrl: getLoadedUrl() }); - } - }, - { - label: "Reload", - accelerator: "CmdOrCtrl+Alt+R", - click: function() { - windows.forEach(mainWindow => { - mainWindow && mainWindow.reload(); - }); - } - }, - - { - label: "Kiosk", - accelerator: "CmdOrCtrl+Alt+K", - click: function() { - if (windows[0] && windows[0].isKiosk()) { - windows.forEach(mainWindow => { - mainWindow.setKiosk(false); - setMenubar(); - }); - } else { - windows.forEach(mainWindow => { - mainWindow.setKiosk(true); - clearMenubar(); - }); - } - } - }, - { - label: "Dev Tools", - accelerator: "CmdOrCtrl+Alt+I", - click: function() { - const focused = BrowserWindow.getFocusedWindow(); - focused && focused.webContents.openDevTools(); - } - } - ] - }, - { - label: "Edit", - submenu: [ - { label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" }, - { label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" }, - { label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" }, - { - label: "Select All", - accelerator: "CmdOrCtrl+A", - selector: "selectAll:" - } - ] - } - ]; - return template; -}; diff --git a/src/helpers/setMenubar.js b/src/helpers/setMenubar.js index f209881..882a748 100644 --- a/src/helpers/setMenubar.js +++ b/src/helpers/setMenubar.js @@ -1,16 +1,103 @@ -const { Menu } = require("electron"); -const templateFunc = require("./menuTemplate"); -const { windows } = require("./multiWindow"); +const { Menu, BrowserWindow, app } = require("electron"); +const { windows, addWindow } = require("./multiWindow"); +const { getLoadedUrl } = require("./loadedUrl"); -module.exports.setMenubar = function setMenubar() { +function templateFunc() { + var template = [ + { + label: "Application", + submenu: [ + { + label: "About Application", + selector: "orderFrontStandardAboutPanel:" + }, + { + label: "Quit", + accelerator: "CmdOrCtrl+Alt+Q", + click: function() { + app.quit(); + } + } + ] + }, + { + label: "File", + submenu: [ + { + label: "New Window", + accelerator: "CmdOrCtrl+N", + click: function() { + addWindow({ loadedUrl: getLoadedUrl() }); + } + }, + { + label: "Reload", + accelerator: "CmdOrCtrl+Alt+R", + click: function() { + windows.forEach(mainWindow => { + mainWindow && mainWindow.reload(); + }); + } + }, + + { + label: "Kiosk", + accelerator: "CmdOrCtrl+Alt+K", + click: function() { + if (windows[0] && windows[0].isKiosk()) { + windows.forEach(mainWindow => { + mainWindow.setKiosk(false); + setMenubar(); + }); + } else { + windows.forEach(mainWindow => { + mainWindow.setKiosk(true); + + clearMenubar(); + }); + } + } + }, + { + label: "Dev Tools", + accelerator: "CmdOrCtrl+Alt+I", + click: function() { + const focused = BrowserWindow.getFocusedWindow(); + focused && focused.webContents.openDevTools(); + } + } + ] + }, + { + label: "Edit", + submenu: [ + { label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" }, + { label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" }, + { label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" }, + { + label: "Select All", + accelerator: "CmdOrCtrl+A", + selector: "selectAll:" + } + ] + } + ]; + return template; +} + +function setMenubar() { const template = templateFunc(); Menu.setApplicationMenu(Menu.buildFromTemplate(template)); windows.forEach(w => { w.setMenuBarVisibility(true); w.setAutoHideMenuBar(false); }); -}; +} -module.exports.clearMenubar = function clearMenubar() { +function clearMenubar() { Menu.setApplicationMenu(null); -}; +} + +module.exports.setMenubar = setMenubar; + +module.exports.clearMenubar = clearMenubar;