blob: a4beb715cee154d6464b4dce529b2853d6dc6e8b (
plain)
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
|
import { app, BrowserWindow } from 'electron';
import * as path from 'path';
import { format as formatUrl } from 'url';
const isDevelopment = process.env.NODE_ENV !== 'production';
let mainWindow: BrowserWindow|null = null;
function getIndexURL(): string {
if (isDevelopment)
return `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`;
return formatUrl({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true,
});
}
function createMainWindow(): BrowserWindow {
const window = new BrowserWindow();
if (isDevelopment)
window.webContents.openDevTools();
window.loadURL(getIndexURL());
window.on('closed', () => {
mainWindow = null;
});
window.webContents.on('devtools-opened', () => {
window.webContents.focus();
});
return window;
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin')
app.quit();
});
app.on('activate', () => {
if (!mainWindow)
mainWindow = createMainWindow();
});
app.on('ready', () => {
mainWindow = createMainWindow();
});
|