summaryrefslogtreecommitdiff
path: root/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'main.js')
-rw-r--r--main.js86
1 files changed, 86 insertions, 0 deletions
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