1
1
const {
2
- app, BrowserWindow, Menu, shell, dialog, ipcMain,
3
- } = require ( 'electron' ) ;
2
+ app,
3
+ BrowserWindow,
4
+ Menu,
5
+ shell,
6
+ dialog,
7
+ ipcMain
8
+ } = require ( "electron" ) ;
4
9
5
10
// Uncomment below for hot reloading during development
6
- require ( ' electron-reload' ) ( __dirname ) ;
11
+ require ( " electron-reload" ) ( __dirname ) ;
7
12
8
13
// const isDev = true;
9
- const isDev = process . env . NODE_ENV === 'development' || process . env . NODE_ENV === 'test' ;
14
+ const isDev =
15
+ process . env . NODE_ENV === "development" || process . env . NODE_ENV === "test" ;
10
16
11
17
// Keep a global reference of the window object, if you don't, the window will
12
18
// be closed automatically when the JavaScript object is garbage collected.
@@ -16,76 +22,76 @@ let mainWindow;
16
22
function openFile ( ) {
17
23
// Opens file dialog looking for markdown
18
24
const files = dialog . showOpenDialog ( mainWindow , {
19
- properties : [ ' openFile' ] ,
25
+ properties : [ " openFile" ] ,
20
26
filters : [
21
27
{
22
- name : ' Images' ,
23
- extensions : [ ' jpeg' , ' jpg' , ' png' , ' gif' , ' pdf' ] ,
24
- } ,
25
- ] ,
28
+ name : " Images" ,
29
+ extensions : [ " jpeg" , " jpg" , " png" , " gif" , " pdf" ]
30
+ }
31
+ ]
26
32
} ) ;
27
33
28
34
// if no files
29
35
if ( ! files ) return ;
30
36
const file = files [ 0 ] ;
31
37
32
38
// Send fileContent to renderer
33
- mainWindow . webContents . send ( ' new-file' , file ) ;
39
+ mainWindow . webContents . send ( " new-file" , file ) ;
34
40
}
35
41
36
42
// Choose directory
37
- ipcMain . on ( ' choose_app_dir' , ( event ) => {
43
+ ipcMain . on ( " choose_app_dir" , event => {
38
44
const directory = dialog . showOpenDialog ( mainWindow , {
39
- properties : [ ' openDirectory' ] ,
40
- buttonLabel : ' Export' ,
45
+ properties : [ " openDirectory" ] ,
46
+ buttonLabel : " Export"
41
47
} ) ;
42
48
43
49
if ( ! directory ) return ;
44
- event . sender . send ( ' app_dir_selected' , directory [ 0 ] ) ;
50
+ event . sender . send ( " app_dir_selected" , directory [ 0 ] ) ;
45
51
} ) ;
46
52
47
- ipcMain . on ( ' view_app_dir' , ( event , appDir ) => {
53
+ ipcMain . on ( " view_app_dir" , ( event , appDir ) => {
48
54
shell . openItem ( appDir ) ;
49
55
} ) ;
50
56
51
57
// Update file
52
- ipcMain . on ( ' update-file' , ( ) => {
58
+ ipcMain . on ( " update-file" , ( ) => {
53
59
openFile ( ) ;
54
60
} ) ;
55
61
56
62
const createWindow = ( ) => {
57
63
// Create the browser window.
58
64
// eslint-disable-next-line
59
- const { width, height } = require ( ' electron' ) . screen . getPrimaryDisplay ( ) . size ;
65
+ const { width, height } = require ( " electron" ) . screen . getPrimaryDisplay ( ) . size ;
60
66
mainWindow = new BrowserWindow ( {
61
67
width,
62
68
height,
63
69
webPreferences : {
64
- zoomFactor : 0.9 ,
65
- ' node-Integration' : false ,
70
+ zoomFactor : 0.7 ,
71
+ " node-Integration" : false
66
72
} ,
67
- show : false ,
73
+ show : false
68
74
} ) ;
69
75
70
76
// and load the index.html of the app.
71
77
mainWindow . loadURL ( `file://${ __dirname } /build/index.html` ) ;
72
78
// load page once window is loaded
73
- mainWindow . once ( ' ready-to-show' , ( ) => {
79
+ mainWindow . once ( " ready-to-show" , ( ) => {
74
80
mainWindow . show ( ) ;
75
81
} ) ;
76
82
77
83
const template = [
78
84
{
79
- label : ' File' ,
85
+ label : " File" ,
80
86
submenu : [
81
87
{
82
- label : ' Open File' ,
83
- accelerator : process . platform === ' darwin' ? ' Cmd+O' : ' Ctrl+Shift+O' ,
88
+ label : " Open File" ,
89
+ accelerator : process . platform === " darwin" ? " Cmd+O" : " Ctrl+Shift+O" ,
84
90
click ( ) {
85
91
openFile ( ) ;
86
- } ,
87
- } ,
88
- ] ,
92
+ }
93
+ }
94
+ ]
89
95
} ,
90
96
// {
91
97
// label: 'Edit',
@@ -102,89 +108,90 @@ const createWindow = () => {
102
108
// ],
103
109
// },
104
110
{
105
- label : ' View' ,
111
+ label : " View" ,
106
112
submenu : [
107
- { role : ' reload' } ,
108
- { role : ' forcereload' } ,
109
- { type : ' separator' } ,
110
- { role : ' resetzoom' } ,
111
- { role : ' zoomin' } ,
112
- { role : ' zoomout' } ,
113
- { type : ' separator' } ,
114
- { role : ' togglefullscreen' } ,
115
- ] ,
113
+ { role : " reload" } ,
114
+ { role : " forcereload" } ,
115
+ { type : " separator" } ,
116
+ { role : " resetzoom" } ,
117
+ { role : " zoomin" } ,
118
+ { role : " zoomout" } ,
119
+ { type : " separator" } ,
120
+ { role : " togglefullscreen" }
121
+ ]
116
122
} ,
117
123
{
118
- role : ' window' ,
119
- submenu : [ { role : ' minimize' } , { role : ' close' } ] ,
124
+ role : " window" ,
125
+ submenu : [ { role : " minimize" } , { role : " close" } ]
120
126
} ,
121
127
{
122
- role : ' help' ,
128
+ role : " help" ,
123
129
submenu : [
124
130
{
125
- label : ' Learn More' ,
131
+ label : " Learn More" ,
126
132
click ( ) {
127
- shell . openExternal ( ' https://electronjs.org' ) ;
128
- } ,
129
- } ,
130
- ] ,
133
+ shell . openExternal ( " https://electronjs.org" ) ;
134
+ }
135
+ }
136
+ ]
131
137
} ,
132
138
{
133
- label : ' Developer' ,
139
+ label : " Developer" ,
134
140
submenu : [
135
141
{
136
- label : 'Toggle Developer Tools' ,
137
- accelerator : process . platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I' ,
142
+ label : "Toggle Developer Tools" ,
143
+ accelerator :
144
+ process . platform === "darwin" ? "Alt+Command+I" : "Ctrl+Shift+I" ,
138
145
click ( ) {
139
146
mainWindow . webContents . toggleDevTools ( ) ;
140
- } ,
141
- } ,
142
- ] ,
143
- } ,
147
+ }
148
+ }
149
+ ]
150
+ }
144
151
] ;
145
152
146
- if ( process . platform === ' darwin' ) {
153
+ if ( process . platform === " darwin" ) {
147
154
template . unshift ( {
148
155
label : app . getName ( ) ,
149
156
submenu : [
150
- { role : ' about' } ,
151
- { type : ' separator' } ,
152
- { role : ' services' , submenu : [ ] } ,
153
- { type : ' separator' } ,
154
- { role : ' hide' } ,
155
- { role : ' hideothers' } ,
156
- { role : ' unhide' } ,
157
- { type : ' separator' } ,
158
- { role : ' quit' } ,
159
- ] ,
157
+ { role : " about" } ,
158
+ { type : " separator" } ,
159
+ { role : " services" , submenu : [ ] } ,
160
+ { type : " separator" } ,
161
+ { role : " hide" } ,
162
+ { role : " hideothers" } ,
163
+ { role : " unhide" } ,
164
+ { type : " separator" } ,
165
+ { role : " quit" }
166
+ ]
160
167
} ) ;
161
168
162
169
// Edit menu
163
170
template [ 2 ] . submenu . push (
164
171
{
165
- type : ' separator' ,
172
+ type : " separator"
166
173
} ,
167
174
{
168
- label : ' Speech' ,
169
- submenu : [ { role : ' startspeaking' } , { role : ' stopspeaking' } ] ,
170
- } ,
175
+ label : " Speech" ,
176
+ submenu : [ { role : " startspeaking" } , { role : " stopspeaking" } ]
177
+ }
171
178
) ;
172
179
173
180
// Window menu
174
181
template [ 4 ] . submenu = [
175
- { role : ' close' } ,
176
- { role : ' minimize' } ,
177
- { role : ' zoom' } ,
178
- { type : ' separator' } ,
179
- { role : ' front' } ,
182
+ { role : " close" } ,
183
+ { role : " minimize" } ,
184
+ { role : " zoom" } ,
185
+ { type : " separator" } ,
186
+ { role : " front" }
180
187
] ;
181
188
}
182
189
183
190
const menu = Menu . buildFromTemplate ( template ) ;
184
191
Menu . setApplicationMenu ( menu ) ;
185
192
186
193
// Emitted when the window is closed.
187
- mainWindow . on ( ' closed' , ( ) => {
194
+ mainWindow . on ( " closed" , ( ) => {
188
195
// Dereference the window object, usually you would store windows
189
196
// in an array if your app supports multi windows, this is the time
190
197
// when you should delete the corresponding element.
@@ -195,13 +202,13 @@ const createWindow = () => {
195
202
// This method will be called when Electron has finished
196
203
// initialization and is ready to create browser windows.
197
204
// Some APIs can only be used after this event occurs.
198
- app . on ( ' ready' , ( ) => {
205
+ app . on ( " ready" , ( ) => {
199
206
if ( isDev ) {
200
207
const {
201
208
default : installExtension ,
202
209
REACT_DEVELOPER_TOOLS ,
203
- REDUX_DEVTOOLS ,
204
- } = require ( ' electron-devtools-installer' ) ;
210
+ REDUX_DEVTOOLS
211
+ } = require ( " electron-devtools-installer" ) ;
205
212
206
213
installExtension ( [ REACT_DEVELOPER_TOOLS , REDUX_DEVTOOLS ] )
207
214
. then ( ( ) => {
@@ -214,15 +221,15 @@ app.on('ready', () => {
214
221
} ) ;
215
222
216
223
// Quit when all windows are closed.
217
- app . on ( ' window-all-closed' , ( ) => {
224
+ app . on ( " window-all-closed" , ( ) => {
218
225
// On OS X it is common for applications and their menu bar
219
226
// to stay active until the user quits explicitly with Cmd + Q
220
- if ( process . platform !== ' darwin' ) {
227
+ if ( process . platform !== " darwin" ) {
221
228
app . quit ( ) ;
222
229
}
223
230
} ) ;
224
231
225
- app . on ( ' activate' , ( ) => {
232
+ app . on ( " activate" , ( ) => {
226
233
// On OS X it's common to re-create a window in the app when the
227
234
// dock icon is clicked and there are no other windows open.
228
235
if ( mainWindow === null ) {
0 commit comments