1
1
const path = require ( 'path' ) ;
2
2
3
- const { app, BrowserWindow, Menu, shell, dialog, ipcMain } = require ( 'electron' ) ;
3
+ const {
4
+ app,
5
+ BrowserWindow,
6
+ Menu,
7
+ shell,
8
+ dialog,
9
+ ipcMain
10
+ } = require ( 'electron' ) ;
4
11
5
12
// Uncomment below for hot reloading during development
6
13
// require('electron-reload')(__dirname);
7
14
8
15
// const isDev = true;
9
- const isDev = process . env . NODE_ENV === 'development' || process . env . NODE_ENV === 'test' ;
16
+ const isDev =
17
+ process . env . NODE_ENV === 'development' || process . env . NODE_ENV === 'test' ;
10
18
11
19
// Keep a global reference of the window object, if you don't, the window will
12
20
// be closed automatically when the JavaScript object is garbage collected.
@@ -20,9 +28,9 @@ function openFile() {
20
28
filters : [
21
29
{
22
30
name : 'Images' ,
23
- extensions : [ 'jpeg' , 'jpg' , 'png' , 'gif' , 'pdf' ] ,
24
- } ,
25
- ] ,
31
+ extensions : [ 'jpeg' , 'jpg' , 'png' , 'gif' , 'pdf' ]
32
+ }
33
+ ]
26
34
} ) ;
27
35
28
36
// if no files
@@ -37,7 +45,7 @@ function openFile() {
37
45
ipcMain . on ( 'choose_app_dir' , event => {
38
46
const directory = dialog . showOpenDialog ( mainWindow , {
39
47
properties : [ 'openDirectory' ] ,
40
- buttonLabel : 'Export' ,
48
+ buttonLabel : 'Export'
41
49
} ) ;
42
50
43
51
if ( ! directory ) return ;
@@ -62,14 +70,14 @@ const createWindow = () => {
62
70
height,
63
71
webPreferences : {
64
72
zoomFactor : 0.7 ,
65
- 'node-Integration' : false ,
73
+ 'node-Integration' : false
66
74
} ,
67
75
show : false ,
68
76
icon : path . join ( __dirname , '/src/public/icons/mac/icon.icns' ) ,
69
77
win : {
70
78
icon : path . join ( __dirname , '/src/public/icons/win/icon.ico' ) ,
71
- target : [ 'portable' ] ,
72
- } ,
79
+ target : [ 'portable' ]
80
+ }
73
81
} ) ;
74
82
75
83
// and load the index.html of the app.
@@ -88,9 +96,9 @@ const createWindow = () => {
88
96
accelerator : process . platform === 'darwin' ? 'Cmd+O' : 'Ctrl+Shift+O' ,
89
97
click ( ) {
90
98
openFile ( ) ;
91
- } ,
92
- } ,
93
- ] ,
99
+ }
100
+ }
101
+ ]
94
102
} ,
95
103
// {
96
104
// label: 'Edit',
@@ -116,12 +124,12 @@ const createWindow = () => {
116
124
{ role : 'zoomin' } ,
117
125
{ role : 'zoomout' } ,
118
126
{ type : 'separator' } ,
119
- { role : 'togglefullscreen' } ,
120
- ] ,
127
+ { role : 'togglefullscreen' }
128
+ ]
121
129
} ,
122
130
{
123
131
role : 'window' ,
124
- submenu : [ { role : 'minimize' } , { role : 'close' } ] ,
132
+ submenu : [ { role : 'minimize' } , { role : 'close' } ]
125
133
} ,
126
134
{
127
135
role : 'help' ,
@@ -130,22 +138,23 @@ const createWindow = () => {
130
138
label : 'Learn More' ,
131
139
click ( ) {
132
140
shell . openExternal ( 'https://electronjs.org' ) ;
133
- } ,
134
- } ,
135
- ] ,
141
+ }
142
+ }
143
+ ]
136
144
} ,
137
145
{
138
146
label : 'Developer' ,
139
147
submenu : [
140
148
{
141
149
label : 'Toggle Developer Tools' ,
142
- accelerator : process . platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I' ,
150
+ accelerator :
151
+ process . platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I' ,
143
152
click ( ) {
144
153
mainWindow . webContents . toggleDevTools ( ) ;
145
- } ,
146
- } ,
147
- ] ,
148
- } ,
154
+ }
155
+ }
156
+ ]
157
+ }
149
158
] ;
150
159
151
160
if ( process . platform === 'darwin' ) {
@@ -160,19 +169,19 @@ const createWindow = () => {
160
169
{ role : 'hideothers' } ,
161
170
{ role : 'unhide' } ,
162
171
{ type : 'separator' } ,
163
- { role : 'quit' } ,
164
- ] ,
172
+ { role : 'quit' }
173
+ ]
165
174
} ) ;
166
175
167
176
// Edit menu
168
177
template [ 2 ] . submenu . push (
169
178
{
170
- type : 'separator' ,
179
+ type : 'separator'
171
180
} ,
172
181
{
173
182
label : 'Speech' ,
174
- submenu : [ { role : 'startspeaking' } , { role : 'stopspeaking' } ] ,
175
- } ,
183
+ submenu : [ { role : 'startspeaking' } , { role : 'stopspeaking' } ]
184
+ }
176
185
) ;
177
186
178
187
// Window menu
@@ -181,7 +190,7 @@ const createWindow = () => {
181
190
{ role : 'minimize' } ,
182
191
{ role : 'zoom' } ,
183
192
{ type : 'separator' } ,
184
- { role : 'front' } ,
193
+ { role : 'front' }
185
194
] ;
186
195
}
187
196
@@ -195,14 +204,21 @@ const createWindow = () => {
195
204
// when you should delete the corresponding element.
196
205
mainWindow = null ;
197
206
} ) ;
207
+
208
+ // dev tools opened on every browser creation
209
+ mainWindow . webContents . openDevTools ( ) ;
198
210
} ;
199
211
200
212
// This method will be called when Electron has finished
201
213
// initialization and is ready to create browser windows.
202
214
// Some APIs can only be used after this event occurs.
203
215
app . on ( 'ready' , ( ) => {
204
216
if ( isDev ) {
205
- const { default : installExtension , REACT_DEVELOPER_TOOLS , REDUX_DEVTOOLS } = require ( 'electron-devtools-installer' ) ;
217
+ const {
218
+ default : installExtension ,
219
+ REACT_DEVELOPER_TOOLS ,
220
+ REDUX_DEVTOOLS
221
+ } = require ( 'electron-devtools-installer' ) ;
206
222
207
223
installExtension ( [ REACT_DEVELOPER_TOOLS , REDUX_DEVTOOLS ] )
208
224
. then ( ( ) => {
0 commit comments