From c7afd053563916f2409fdc7913738a4f864ce9a0 Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Sun, 14 Aug 2022 01:54:58 +1000 Subject: Initial commit Note that Electron 11 must be used, as Electron 12 uses Chromium 88, where plugins were removed. --- main.js | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 main.js (limited to 'main.js') diff --git a/main.js b/main.js new file mode 100644 index 0000000..566a954 --- /dev/null +++ b/main.js @@ -0,0 +1,86 @@ +const { app, BrowserWindow, Menu } = require('electron'); +const path = require('path'); + +const config = require(path.join(__dirname, 'config.json')); + +// 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'); + +// Menu +// https://www.electronjs.org/docs/latest/api/menu +const menuTemplate = [ + { + label: 'File', + submenu: Object.keys(config.urls).map(urlName => ({ + label: 'Open ' + urlName, + click: function(menuItem, browserWindow, event) { + browserWindow.loadURL(config.urls[urlName]); + } + })).concat([ + { type: 'separator' }, + { role: 'quit' } + ]) + }, + { + label: 'View', + submenu: [ + { role: 'reload' }, + { role: 'forceReload' }, + { 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() +}); \ No newline at end of file -- cgit