add menu and shortcuts
This commit is contained in:
@@ -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 fs = require('fs');
|
||||
const os = require('os');
|
||||
@@ -7,6 +7,7 @@ const { linkExists } = require('link-exists');
|
||||
const { setInterval } = require('node:timers/promises');
|
||||
const { type } = require('node:os');
|
||||
|
||||
const isMac = process.platform === 'darwin';
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Properties
|
||||
@@ -14,6 +15,7 @@ const { type } = require('node:os');
|
||||
|
||||
let config;
|
||||
let win;
|
||||
let menu;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Function
|
||||
@@ -33,8 +35,7 @@ let win;
|
||||
function loadConfig() {
|
||||
const locations = [
|
||||
'/assets/presentation',
|
||||
os.platform() == 'darwin' ?
|
||||
path.resolve(app.getPath('exe'), "../../../../") : app.getPath('exe'),
|
||||
isMac ? path.resolve(app.getPath('exe'), "../../../../") : app.getPath('exe'),
|
||||
__dirname
|
||||
];
|
||||
|
||||
@@ -114,9 +115,32 @@ async function createWindow() {
|
||||
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
|
||||
* 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.info('----------------------------------------------');
|
||||
log.info('Starting Tooloop Kiosk Browser...');
|
||||
|
||||
createMenu();
|
||||
createWindow();
|
||||
});
|
||||
|
||||
Menu.setApplicationMenu(null);
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
app.quit()
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
app.quit()
|
||||
});
|
||||
|
||||
app.on('quit', () => {
|
||||
log.info('Quit');
|
||||
});
|
||||
Reference in New Issue
Block a user