1
- const { app, BrowserWindow, shell, Menu } = require ( 'electron' ) ;
2
- const createRPC = require ( './rpc' ) ;
3
- const createMenu = require ( './menu' ) ;
1
+ const { parse : parseUrl } = require ( 'url' ) ;
2
+ const { resolve} = require ( 'path' ) ;
3
+
4
+ const { app, BrowserWindow, shell, Menu} = require ( 'electron' ) ;
4
5
const uuid = require ( 'uuid' ) ;
5
- const { resolve } = require ( 'path' ) ;
6
- const { parse : parseUrl } = require ( 'url' ) ;
7
6
const fileUriToPath = require ( 'file-uri-to-path' ) ;
8
7
const isDev = require ( 'electron-is-dev' ) ;
9
8
const AutoUpdater = require ( './auto-updater' ) ;
10
9
const toElectronBackgroundColor = require ( './utils/to-electron-background-color' ) ;
10
+
11
+ const createMenu = require ( './menu' ) ;
12
+ const createRPC = require ( './rpc' ) ;
11
13
const notify = require ( './notify' ) ;
12
14
13
15
app . commandLine . appendSwitch ( 'js-flags' , '--harmony' ) ;
14
16
15
17
// set up config
16
18
const config = require ( './config' ) ;
19
+
17
20
config . init ( ) ;
21
+
18
22
const plugins = require ( './plugins' ) ;
19
23
const Session = require ( './session' ) ;
20
24
@@ -28,7 +32,9 @@ app.getWindows = () => new Set([...windowSet]); // return a clone
28
32
// function to retrive the last focused window in windowSet;
29
33
// added to app object in order to expose it to plugins.
30
34
app . getLastFocusedWindow = ( ) => {
31
- if ( ! windowSet . size ) return null ;
35
+ if ( ! windowSet . size ) {
36
+ return null ;
37
+ }
32
38
return Array . from ( windowSet ) . reduce ( ( lastWindow , win ) => {
33
39
return win . focusTime > lastWindow . focusTime ? win : lastWindow ;
34
40
} ) ;
@@ -48,11 +54,11 @@ const url = 'file://' + resolve(
48
54
console . log ( 'electron will open' , url ) ;
49
55
50
56
app . on ( 'ready' , ( ) => {
51
- function createWindow ( fn ) {
57
+ function createWindow ( fn ) {
52
58
let cfg = plugins . getDecoratedConfig ( ) ;
53
59
54
60
const [ width , height ] = cfg . windowSize || [ 540 , 380 ] ;
55
- const { screen } = require ( 'electron' ) ;
61
+ const { screen} = require ( 'electron' ) ;
56
62
57
63
let startX = 50 ;
58
64
let startY = 50 ;
@@ -63,7 +69,7 @@ app.on('ready', () => {
63
69
const focusedWindow = BrowserWindow . getFocusedWindow ( ) || app . getLastFocusedWindow ( ) ;
64
70
if ( focusedWindow ) {
65
71
const points = focusedWindow . getPosition ( ) ;
66
- const currentScreen = screen . getDisplayNearestPoint ( { x : points [ 0 ] , y : points [ 1 ] } ) ;
72
+ const currentScreen = screen . getDisplayNearestPoint ( { x : points [ 0 ] , y : points [ 1 ] } ) ;
67
73
68
74
const biggestX = ( ( points [ 0 ] + 100 + width ) - currentScreen . bounds . x ) ;
69
75
const biggestY = ( ( points [ 1 ] + 100 + height ) - currentScreen . bounds . y ) ;
@@ -132,7 +138,9 @@ app.on('ready', () => {
132
138
133
139
// If no callback is passed to createWindow,
134
140
// a new session will be created by default.
135
- if ( ! fn ) fn = ( win ) => win . rpc . emit ( 'session add req' ) ;
141
+ if ( ! fn ) {
142
+ fn = win => win . rpc . emit ( 'session add req' ) ;
143
+ }
136
144
137
145
// app.windowCallback is the createWindow callback
138
146
// that can be setted before the 'ready' app event
@@ -149,29 +157,29 @@ app.on('ready', () => {
149
157
}
150
158
} ) ;
151
159
152
- rpc . on ( 'new' , ( { rows = 40 , cols = 100 , cwd = process . env . HOME } ) => {
160
+ rpc . on ( 'new' , ( { rows = 40 , cols = 100 , cwd = process . env . HOME } ) => {
153
161
const shell = cfg . shell ;
154
162
const shellArgs = cfg . shellArgs && Array . from ( cfg . shellArgs ) ;
155
163
156
- initSession ( { rows, cols, cwd, shell, shellArgs } , ( uid , session ) => {
164
+ initSession ( { rows, cols, cwd, shell, shellArgs} , ( uid , session ) => {
157
165
sessions . set ( uid , session ) ;
158
166
rpc . emit ( 'session add' , {
159
167
uid,
160
168
shell : session . shell ,
161
169
pid : session . pty . pid
162
170
} ) ;
163
171
164
- session . on ( 'data' , ( data ) => {
165
- rpc . emit ( 'session data' , { uid, data } ) ;
172
+ session . on ( 'data' , data => {
173
+ rpc . emit ( 'session data' , { uid, data} ) ;
166
174
} ) ;
167
175
168
- session . on ( 'title' , ( title ) => {
176
+ session . on ( 'title' , title => {
169
177
win . setTitle ( title ) ;
170
- rpc . emit ( 'session title' , { uid, title } ) ;
178
+ rpc . emit ( 'session title' , { uid, title} ) ;
171
179
} ) ;
172
180
173
181
session . on ( 'exit' , ( ) => {
174
- rpc . emit ( 'session exit' , { uid } ) ;
182
+ rpc . emit ( 'session exit' , { uid} ) ;
175
183
sessions . delete ( uid ) ;
176
184
} ) ;
177
185
} ) ;
@@ -180,7 +188,7 @@ app.on('ready', () => {
180
188
// TODO: this goes away when we are able to poll
181
189
// for the title ourseleves, instead of relying
182
190
// on Session and focus/blur to subscribe
183
- rpc . on ( 'focus' , ( { uid } ) => {
191
+ rpc . on ( 'focus' , ( { uid} ) => {
184
192
const session = sessions . get ( uid ) ;
185
193
if ( typeof session !== 'undefined' && typeof session . lastTitle !== 'undefined' ) {
186
194
win . setTitle ( session . lastTitle ) ;
@@ -191,7 +199,7 @@ app.on('ready', () => {
191
199
console . log ( 'session not found by' , uid ) ;
192
200
}
193
201
} ) ;
194
- rpc . on ( 'blur' , ( { uid } ) => {
202
+ rpc . on ( 'blur' , ( { uid} ) => {
195
203
const session = sessions . get ( uid ) ;
196
204
197
205
if ( session ) {
@@ -201,7 +209,7 @@ app.on('ready', () => {
201
209
}
202
210
} ) ;
203
211
204
- rpc . on ( 'exit' , ( { uid } ) => {
212
+ rpc . on ( 'exit' , ( { uid} ) => {
205
213
const session = sessions . get ( uid ) ;
206
214
207
215
if ( session ) {
@@ -219,17 +227,17 @@ app.on('ready', () => {
219
227
win . maximize ( ) ;
220
228
} ) ;
221
229
222
- rpc . on ( 'resize' , ( { cols, rows } ) => {
223
- sessions . forEach ( ( session ) => {
224
- session . resize ( { cols, rows } ) ;
230
+ rpc . on ( 'resize' , ( { cols, rows} ) => {
231
+ sessions . forEach ( session => {
232
+ session . resize ( { cols, rows} ) ;
225
233
} ) ;
226
234
} ) ;
227
235
228
- rpc . on ( 'data' , ( { uid, data } ) => {
236
+ rpc . on ( 'data' , ( { uid, data} ) => {
229
237
sessions . get ( uid ) . write ( data ) ;
230
238
} ) ;
231
239
232
- rpc . on ( 'open external' , ( { url } ) => {
240
+ rpc . on ( 'open external' , ( { url} ) => {
233
241
shell . openExternal ( url ) ;
234
242
} ) ;
235
243
@@ -257,11 +265,11 @@ app.on('ready', () => {
257
265
// If file is dropped onto the terminal window, navigate event is prevented
258
266
// and his path is added to active session.
259
267
win . webContents . on ( 'will-navigate' , ( event , url ) => {
260
- var protocol = typeof url === 'string' && parseUrl ( url ) . protocol ;
268
+ const protocol = typeof url === 'string' && parseUrl ( url ) . protocol ;
261
269
if ( protocol === 'file:' ) {
262
270
event . preventDefault ( ) ;
263
- let path = fileUriToPath ( url ) . replace ( / / g, '\\ ' ) ;
264
- rpc . emit ( 'session data send' , { data : path } ) ;
271
+ const path = fileUriToPath ( url ) . replace ( / / g, '\\ ' ) ;
272
+ rpc . emit ( 'session data send' , { data : path } ) ;
265
273
}
266
274
} ) ;
267
275
@@ -276,7 +284,7 @@ app.on('ready', () => {
276
284
// load plugins
277
285
load ( ) ;
278
286
279
- const pluginsUnsubscribe = plugins . subscribe ( ( err ) => {
287
+ const pluginsUnsubscribe = plugins . subscribe ( err => {
280
288
if ( ! err ) {
281
289
load ( ) ;
282
290
win . webContents . send ( 'plugins change' ) ;
@@ -331,16 +339,18 @@ app.on('ready', () => {
331
339
const tpl = plugins . decorateMenu ( createMenu ( {
332
340
createWindow,
333
341
updatePlugins : ( ) => {
334
- plugins . updatePlugins ( { force : true } ) ;
342
+ plugins . updatePlugins ( { force : true } ) ;
335
343
}
336
344
} ) ) ;
337
345
338
346
// If we're on Mac make a Dock Menu
339
347
if ( process . platform === 'darwin' ) {
340
- const { app, Menu } = require ( 'electron' ) ;
341
- const dockMenu = Menu . buildFromTemplate ( [
342
- { label : 'New Window' , click ( ) { createWindow ( ) ; } }
343
- ] ) ;
348
+ const dockMenu = Menu . buildFromTemplate ( [ {
349
+ label : 'New Window' ,
350
+ click ( ) {
351
+ createWindow ( ) ;
352
+ }
353
+ } ] ) ;
344
354
app . dock . setMenu ( dockMenu ) ;
345
355
}
346
356
@@ -356,16 +366,16 @@ app.on('ready', () => {
356
366
plugins . subscribe ( load ) ;
357
367
} ) ;
358
368
359
- function initSession ( opts , fn ) {
369
+ function initSession ( opts , fn ) {
360
370
fn ( uuid . v4 ( ) , new Session ( opts ) ) ;
361
371
}
362
372
363
373
app . on ( 'open-file' , ( event , path ) => {
364
374
const lastWindow = app . getLastFocusedWindow ( ) ;
365
- const callback = win => win . rpc . emit ( 'open file' , { path } ) ;
375
+ const callback = win => win . rpc . emit ( 'open file' , { path} ) ;
366
376
if ( lastWindow ) {
367
377
callback ( lastWindow ) ;
368
- } else if ( ! lastWindow && app . hasOwnProperty ( 'createWindow' ) ) {
378
+ } else if ( ! lastWindow && { } . hasOwnProperty . call ( app , 'createWindow' ) ) {
369
379
app . createWindow ( callback ) ;
370
380
} else {
371
381
// if createWindow not exists yet ('ready' event was not fired),
0 commit comments