summaryrefslogtreecommitdiff
path: root/main.js
blob: 566a95430bb0525a9019a3d8b14af7a0181345a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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()
});