-
Notifications
You must be signed in to change notification settings - Fork 22
/
electron.js
59 lines (50 loc) · 1.75 KB
/
electron.js
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
// Aug 2019 https://nimadez.github.io/
// Voxel Builder Electron
if (!require('electron').app.requestSingleInstanceLock())
require('electron').app.exit(0);
const { app, BrowserWindow, globalShortcut } = require('electron');
function createWindow() {
const mainWindow = new BrowserWindow({
icon: './src/assets/appicon.png',
width: 1200,
height: 800,
autoHideMenuBar: true,
resizable: true,
alwaysOnTop: false,
webPreferences: {
nodeIntegration: false
}
});
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
details.responseHeaders['Cross-Origin-Opener-Policy'] = ['same-origin'];
details.responseHeaders['Cross-Origin-Embedder-Policy'] = ['require-corp', 'credentialless'];
callback({ responseHeaders: details.responseHeaders });
});
mainWindow.loadFile('src/index.html');
mainWindow.removeMenu();
const reload = () => mainWindow.reload();
const devTools = () => mainWindow.webContents.toggleDevTools();
const register = () => {
globalShortcut.register('f5', reload);
globalShortcut.register('f1', devTools);
};
const unregister = () => {
globalShortcut.unregister('f5', reload);
globalShortcut.unregister('f1', devTools);
}
mainWindow.on('focus', register);
mainWindow.on('blur', unregister);
mainWindow.on('beforeunload', unregister);
mainWindow.on('closed', () => {});
}
app.whenReady().then(() => {
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0)
createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin')
app.quit();
});