1
+ import { app , BrowserWindow } from 'electron' ;
2
+ import * as path from 'path' ;
3
+ import * as isDev from 'electron-is-dev' ;
4
+ import installExtension , { REACT_DEVELOPER_TOOLS } from "electron-devtools-installer" ;
5
+ import createMenu from './menu' ;
6
+
7
+ export let win : BrowserWindow | null = null ;
8
+ let modalWin : BrowserWindow | null = null ;
9
+
10
+ function createWindow ( ) {
11
+ win = new BrowserWindow ( {
12
+ width : 1024 ,
13
+ height : 900 ,
14
+ webPreferences : {
15
+ nodeIntegration : true ,
16
+ contextIsolation : false ,
17
+ preload : __dirname + "/preload.js"
18
+ }
19
+ } )
20
+
21
+ modalWin = new BrowserWindow ( {
22
+ width : 1100 ,
23
+ height : 950 ,
24
+ parent : win ,
25
+ modal : true ,
26
+ show : false ,
27
+ minimizable : false ,
28
+ maximizable : true ,
29
+ movable : true ,
30
+ webPreferences : {
31
+ nodeIntegration : true ,
32
+ contextIsolation : false
33
+ }
34
+ } ) ;
35
+
36
+ modalWin . setMenu ( null ) ;
37
+
38
+ win . webContents . on ( 'new-window' , async ( event , url ) => {
39
+ event . preventDefault ( ) ;
40
+ await modalWin ?. loadURL ( "about:blank" ) ;
41
+ console . log ( url ) ;
42
+ modalWin ?. loadURL ( url ) ;
43
+ modalWin ?. show ( ) ;
44
+ } )
45
+
46
+ if ( isDev ) {
47
+ win . loadURL ( 'http://localhost:3000/' ) ;
48
+ } else {
49
+ // 'build/index.html'
50
+ win . loadURL ( `file://${ __dirname } /../index.html` ) ;
51
+ }
52
+
53
+ win . on ( 'closed' , ( ) => { win = null ; modalWin = null } ) ;
54
+ modalWin . on ( 'close' , ( event ) => { event . preventDefault ( ) ; modalWin ?. hide ( ) ; } ) ;
55
+
56
+ win . setMenu ( createMenu ( win ) ) ;
57
+
58
+ // Hot Reloading
59
+ if ( isDev ) {
60
+ // 'node_modules/.bin/electronPath'
61
+ require ( 'electron-reload' ) ( __dirname , {
62
+ electron : path . join ( __dirname , '..' , '..' , 'node_modules' , '.bin' , 'electron' ) ,
63
+ forceHardReset : true ,
64
+ hardResetMethod : 'exit'
65
+ } ) ;
66
+ }
67
+
68
+ // DevTools
69
+ installExtension ( REACT_DEVELOPER_TOOLS )
70
+ . then ( ( name ) => console . log ( `Added Extension: ${ name } ` ) )
71
+ . catch ( ( err ) => console . log ( 'An error occurred: ' , err ) ) ;
72
+
73
+ if ( isDev ) {
74
+ win . webContents . openDevTools ( ) ;
75
+ }
76
+ }
77
+
78
+ app . on ( 'ready' , createWindow ) ;
79
+
80
+ app . on ( 'window-all-closed' , ( ) => {
81
+ if ( process . platform !== 'darwin' ) {
82
+ app . quit ( ) ;
83
+ }
84
+ } ) ;
85
+
86
+ app . on ( 'activate' , ( ) => {
87
+ if ( win === null ) {
88
+ createWindow ( ) ;
89
+ }
90
+ } ) ;
0 commit comments