const { app, BrowserWindow, Menu } = require('electron'); const path = require('path'); const config = require(path.join(__dirname, 'config.json')); if (config.name) app.setName(config.name); // Load flash let flash; if (process.arch !== 'x64') throw new Error('Only x64 architecture is supported.'); switch (process.platform) { case 'win32': flash = 'pepflashplayer.dll'; break; case 'darwin': flash = 'PepperFlashPlayer.plugin'; break; case 'linux': flash = 'libpepflashplayer.so'; break; default: throw new Error('Only Windows, macOS and Linux platforms are supported.'); } let flashPath = path.join(__dirname, path.basename(__dirname) === 'resources' ? '../flash' : 'flash', process.platform, flash); if (process.platform === 'linux') app.commandLine.appendSwitch('no-sandbox'); app.commandLine.appendSwitch('ppapi-flash-path', flashPath); app.commandLine.appendSwitch('ppapi-flash-version', '32.0.0.371'); // Disable cache - might update something on the game side and just don't cache anything. app.commandLine.appendSwitch('disable-http-cache'); // Menu // https://www.electronjs.org/docs/latest/api/menu const menuTemplate = [ // macOS first menu is always the "app name" one. ...(process.platform === 'darwin' ? [{ label: app.name, submenu: [ { role: 'about' }, { type: 'separator' }, { role: 'quit' } ] }] : []), { label: 'File', submenu: Object.keys(config.urls).map(urlName => ({ label: 'Open ' + urlName, click: function(menuItem, browserWindow, event) { browserWindow.loadURL(config.urls[urlName]); } })).concat(process.platform === 'darwin' ? [] : [ { type: 'separator' }, { role: 'quit' } ]) }, { label: 'View', submenu: [ { role: 'reload' }, { role: 'forceReload' }, { role: 'toggleDevTools' }, { type: 'separator' }, { role: 'resetZoom' }, { role: 'zoomIn' }, { role: 'zoomOut' }, { type: 'separator' }, { role: 'togglefullscreen' } ] } ]; const menu = Menu.buildFromTemplate(menuTemplate); Menu.setApplicationMenu(menu); // Basic auth if required app.on('login', (event, webContents, details, authInfo, callback) => { event.preventDefault(); callback(config.username, config.password); }); const createWindow = () => { const win = new BrowserWindow({ width: 1280, height: 720, useContentSize: true, autoHideMenuBar: true, webPreferences: { plugins: true } }); win.loadURL(config.urls[Object.keys(config.urls)[0]]); }; // On startup... app.whenReady().then(() => { createWindow(); }); app.on('window-all-closed', () => { // Quit when all windows closed - even on macOS. app.quit() });