This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.ts
109 lines (93 loc) · 3.42 KB
/
index.ts
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2018-2019 @paritytech/substrate-light-ui authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { app, BrowserWindow } from 'electron';
import path from 'path';
import url from 'url';
import { isSubstrateRunning } from './app/isSubstrateRunning';
import { initMenu } from './app/menu';
import { killSubstrate, runSubstrateDev } from './app/substrateProcess';
import { productName } from '../../electron-builder.json';
import { version } from '../../package.json';
import { logger, staticPath } from './util';
// https://electronjs.org/docs/tutorial/security#electron-security-warnings
process.env.ELECTRON_ENABLE_SECURITY_WARNINGS = 'true';
const REACT_DEV_LOCALHOST = 'http://localhost:3000';
let sluiApp: Electron.BrowserWindow | undefined;
logger.info(`Starting ${productName} v${version}`);
logger.debug(`Platform detected: ${process.platform}`);
logger.debug(`Process args: ${process.argv}`);
initMenu();
function createWindow (): void {
sluiApp = new BrowserWindow({
height: 1920,
resizable: true,
width: 1440,
webPreferences: {
allowRunningInsecureContent: false,
contextIsolation: true, // prevent context sharing between renderer<->main processes
devTools: true,
enableBlinkFeatures: '', // https://electronjs.org/docs/tutorial/security#9-do-not-use-enableblinkfeatures
enableRemoteModule: false,
experimentalFeatures: false, // Do not set to true
navigateOnDragDrop: false,
nativeWindowOpen: true,
nodeIntegration: false, // https://electronjs.org/docs/tutorial/security#2-disable-nodejs-integration-for-remote-content
nodeIntegrationInWorker: false, // https://electronjs.org/docs/tutorial/security#2-disable-nodejs-integration-for-remote-content
plugins: false,
sandbox: true, // isolate all BrowserWindow instance environments
safeDialogs: true,
safeDialogsMessage: 'Electron consecutive dialog protection was triggered',
webSecurity: true, // https://electronjs.org/docs/tutorial/security#5-do-not-disable-websecurity
webviewTag: false // Associated with `will-attach-webview`
}
});
sluiApp
.loadURL(
process.env.NODE_ENV !== 'production'
? REACT_DEV_LOCALHOST
: url.format({
pathname: path.join(staticPath, 'build', 'index.html'),
protocol: 'file:',
slashes: true
})
)
.catch(logger.error);
sluiApp.on('closed', function () {
sluiApp = undefined;
killSubstrate();
});
}
// eslint-
app.once('ready', (): void => {
isSubstrateRunning()
.then(running => {
if (!running) {
return runSubstrateDev();
}
})
.then(createWindow)
.catch(logger.error);
});
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
killSubstrate();
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (sluiApp === undefined) {
createWindow();
}
});
// Make sure Substrate stops when UI stops
app.on('before-quit', killSubstrate);
app.on('will-quit', killSubstrate);
app.on('quit', () => {
killSubstrate();
});