add menu and shortcuts

This commit is contained in:
2024-05-31 10:57:15 +02:00
parent 1ddead6d4a
commit 57588242c4
+41 -11
View File
@@ -1,4 +1,4 @@
const { app, BrowserWindow, nativeTheme, Menu } = require('electron/main'); const { app, BrowserWindow, nativeTheme, Menu, MenuItem, globalShortcut } = require('electron/main');
const path = require('node:path'); const path = require('node:path');
const fs = require('fs'); const fs = require('fs');
const os = require('os'); const os = require('os');
@@ -7,6 +7,7 @@ const { linkExists } = require('link-exists');
const { setInterval } = require('node:timers/promises'); const { setInterval } = require('node:timers/promises');
const { type } = require('node:os'); const { type } = require('node:os');
const isMac = process.platform === 'darwin';
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Properties // Properties
@@ -14,6 +15,7 @@ const { type } = require('node:os');
let config; let config;
let win; let win;
let menu;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Function // Function
@@ -33,8 +35,7 @@ let win;
function loadConfig() { function loadConfig() {
const locations = [ const locations = [
'/assets/presentation', '/assets/presentation',
os.platform() == 'darwin' ? isMac ? path.resolve(app.getPath('exe'), "../../../../") : app.getPath('exe'),
path.resolve(app.getPath('exe'), "../../../../") : app.getPath('exe'),
__dirname __dirname
]; ];
@@ -114,9 +115,32 @@ async function createWindow() {
win.loadFile('index.html'); win.loadFile('index.html');
} }
} }
} }
/**
* Creates all available keyboard shortcuts
*/
function createMenu() {
menu = new Menu();
menu.append(new MenuItem({
label: app.name,
submenu: [
{
label: 'Toggle Fullscreen',
accelerator: isMac ? 'Cmd+F' : 'Ctrl+F',
click: () => { win.setKiosk(!win.kiosk); }
},
{ role: 'reload', },
{ role: 'quit', }
]
}));
Menu.setApplicationMenu(menu);
}
/** /**
* Validates the url of a navigatio event against the list of allowed domains in * Validates the url of a navigatio event against the list of allowed domains in
* the config file. See https://www.electronjs.org/docs/latest/api/web-contents#event-will-frame-navigate * the config file. See https://www.electronjs.org/docs/latest/api/web-contents#event-will-frame-navigate
@@ -190,17 +214,23 @@ app.whenReady().then(() => {
log.transports.file.resolvePathFn = () => config.logPath; log.transports.file.resolvePathFn = () => config.logPath;
} }
log.info('----------------------------------------------');
log.info('Starting Tooloop Kiosk Browser...');
createMenu();
createWindow(); createWindow();
}); });
Menu.setApplicationMenu(null);
app.on('window-all-closed', () => {
app.quit()
});
app.on('activate', () => { app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) { if (BrowserWindow.getAllWindows().length === 0) {
createWindow(); createWindow();
} }
}) })
app.on('window-all-closed', () => {
app.quit()
});
app.on('quit', () => {
log.info('Quit');
});