2
2
* Entry point of the Election app.
3
3
*/
4
4
import * as path from 'path' ;
5
- import * as url from 'url' ;
6
5
import * as nodeEnv from '_utils/node-env' ;
7
6
// eslint-disable-next-line import/no-extraneous-dependencies
8
7
import { BrowserWindow , app , ipcMain } from 'electron' ;
9
8
10
9
let mainWindow : Electron . BrowserWindow | undefined ;
11
10
12
- function createWindow ( ) : void {
11
+ function createWindow ( ) {
13
12
// Create the browser window.
14
13
mainWindow = new BrowserWindow ( {
15
14
height : 600 ,
16
15
width : 800 ,
17
16
webPreferences : {
18
17
devTools : nodeEnv . dev ,
19
18
preload : path . join ( __dirname , './preload.bundle.js' ) ,
20
- webSecurity : false ,
19
+ webSecurity : nodeEnv . prod ,
21
20
} ,
22
21
} ) ;
23
22
24
23
// and load the index.html of the app.
25
- mainWindow . loadURL (
26
- url . format ( {
27
- pathname : path . join ( __dirname , './index.html' ) ,
28
- protocol : 'file:' ,
29
- slashes : true ,
30
- } ) ,
31
- ) . finally ( ( ) => { /* no action */ } ) ;
24
+ mainWindow . loadFile ( 'index.html' ) . finally ( ( ) => { /* no action */ } ) ;
32
25
33
26
// Emitted when the window is closed.
34
27
mainWindow . on ( 'closed' , ( ) => {
@@ -42,23 +35,19 @@ function createWindow(): void {
42
35
// This method will be called when Electron has finished
43
36
// initialization and is ready to create browser windows.
44
37
// Some APIs can only be used after this event occurs.
45
- app . on ( 'ready' , createWindow ) ;
38
+ app . whenReady ( ) . then ( ( ) => {
39
+ createWindow ( ) ;
46
40
47
- // Quit when all windows are closed.
48
- app . on ( 'window-all-closed' , ( ) => {
49
- // On OS X it is common for applications and their menu bar
50
- // to stay active until the user quits explicitly with Cmd + Q
51
- if ( process . platform !== 'darwin' ) {
52
- app . quit ( ) ;
53
- }
54
- } ) ;
41
+ app . on ( 'activate' , ( ) => {
42
+ if ( BrowserWindow . getAllWindows . length === 0 ) createWindow ( ) ;
43
+ } ) ;
44
+ } ) . finally ( ( ) => { /* no action */ } ) ;
55
45
56
- app . on ( 'activate' , ( ) => {
57
- // On OS X it"s common to re-create a window in the app when the
58
- // dock icon is clicked and there are no other windows open.
59
- if ( mainWindow === undefined ) {
60
- createWindow ( ) ;
61
- }
46
+ // Quit when all windows are closed, except on macOS. There, it's common
47
+ // for applications and their menu bar to stay active until the user quits
48
+ // explicitly with Cmd + Q.
49
+ app . on ( 'window-all-closed' , ( ) => {
50
+ if ( process . platform !== 'darwin' ) app . quit ( ) ;
62
51
} ) ;
63
52
64
53
ipcMain . on ( 'renderer-ready' , ( ) => {
0 commit comments