@@ -8,76 +8,11 @@ const ChildProcess = require('child_process')
8
8
const _ = require ( 'lodash' )
9
9
const GhReleases = require ( 'electron-gh-releases' )
10
10
// electron.crashReporter.start()
11
+ require ( './ipc' )
11
12
12
13
var mainWindow = null
13
- var finderProcess = null
14
14
var finderWindow = null
15
15
16
- const appRootPath = path . join ( process . execPath , '../..' )
17
- const updateDotExePath = path . join ( appRootPath , 'Update.exe' )
18
- const exeName = path . basename ( process . execPath )
19
-
20
- // For windows app
21
- function spawnUpdate ( args , cb ) {
22
- var stdout = ''
23
- var updateProcess = null
24
- try {
25
- updateProcess = ChildProcess . spawn ( updateDotExePath , args )
26
- } catch ( e ) {
27
- process . nextTick ( function ( ) {
28
- cb ( e )
29
- } )
30
- }
31
-
32
- updateProcess . stdout . on ( 'data' , function ( data ) {
33
- stdout += data
34
- } )
35
-
36
- error = null
37
- updateProcess . on ( 'error' , function ( _error ) {
38
- error = _error
39
- } )
40
- updateProcess . on ( 'close' , function ( code , signal ) {
41
- if ( code !== 0 ) {
42
- error = new Error ( "Command failed: #{signal ? code}" )
43
- error . code = code
44
- error . stdout = stdout
45
- }
46
-
47
- cb ( error , stdout )
48
- } )
49
- }
50
-
51
- var handleStartupEvent = function ( ) {
52
- if ( process . platform !== 'win32' ) {
53
- return false
54
- }
55
-
56
- var squirrelCommand = process . argv [ 1 ]
57
- switch ( squirrelCommand ) {
58
- case '--squirrel-install' :
59
- spawnUpdate ( [ '--createShortcut' , exeName ] , function ( err ) {
60
- app . quit ( )
61
- } )
62
- return true
63
- case '--squirrel-updated' :
64
- app . quit ( )
65
- return true
66
- case '--squirrel-uninstall' :
67
- spawnUpdate ( [ '--removeShortcut' , exeName ] , function ( err ) {
68
- app . quit ( )
69
- } )
70
- return true
71
- case '--squirrel-obsolete' :
72
- app . quit ( )
73
- return true
74
- }
75
- }
76
-
77
- if ( handleStartupEvent ( ) ) {
78
- return
79
- }
80
-
81
16
var shouldQuit = app . makeSingleInstance ( function ( commandLine , workingDirectory ) {
82
17
if ( mainWindow ) {
83
18
if ( process . platform === 'win32' ) {
@@ -90,7 +25,6 @@ var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory)
90
25
} )
91
26
92
27
if ( shouldQuit ) {
93
- if ( mainWindow != null ) mainWindow . removeAllListeners ( )
94
28
app . quit ( )
95
29
return
96
30
}
@@ -117,15 +51,10 @@ function checkUpdate () {
117
51
if ( err ) {
118
52
var isLatest = err . message === 'There is no newer version.'
119
53
if ( ! isLatest ) console . error ( 'Updater error! %s' , err . message )
54
+ return
120
55
}
121
- if ( ! err ) {
122
- if ( status ) {
123
- // Download start
124
- mainWindow . webContents . send ( 'update-found' , 'Update found!' )
125
- updater . download ( )
126
- } else {
127
- // Latest version
128
- }
56
+ if ( status ) {
57
+ updater . download ( )
129
58
}
130
59
} )
131
60
}
@@ -137,69 +66,53 @@ updater.on('update-downloaded', (info) => {
137
66
}
138
67
} )
139
68
140
-
141
- function spawnFinder ( ) {
142
- if ( process . platform === 'darwin' ) {
143
- var finderArgv = [ path . join ( __dirname , 'finder-app.js' ) , '--finder' ]
144
- if ( _ . find ( process . argv , a => a === '--hot' ) ) finderArgv . push ( '--hot' )
145
- finderProcess = ChildProcess
146
- . execFile ( process . execPath , finderArgv )
69
+ ipc . on ( 'update-app-confirm' , function ( event , msg ) {
70
+ if ( isUpdateReady ) {
71
+ updater . install ( )
147
72
}
148
- }
149
-
150
- app . on ( 'ready' , function ( ) {
151
- var template = require ( './main-menu' )
152
- var menu = Menu . buildFromTemplate ( template )
153
- if ( process . platform === 'darwin' || process . platform === 'linux' ) {
154
- Menu . setApplicationMenu ( menu )
155
- }
156
-
157
- // Check update every 24 hours
158
- setInterval ( function ( ) {
159
- checkUpdate ( )
160
- } , 1000 * 60 * 60 * 24 )
161
-
162
- ipc . on ( 'check-update' , function ( event , msg ) {
163
- checkUpdate ( )
164
- } )
73
+ } )
165
74
166
- ipc . on ( 'update-app-confirm' , function ( event , msg ) {
167
- if ( isUpdateReady ) {
168
- mainWindow . removeAllListeners ( )
169
- updater . install ( )
170
- }
171
- } )
75
+ function spawnFinder ( ) {
76
+ var finderArgv = [ path . join ( __dirname , 'finder-app.js' ) , '--finder' ]
77
+ if ( _ . find ( process . argv , a => a === '--hot' ) ) finderArgv . push ( '--hot' )
78
+ var finderProcess = ChildProcess
79
+ . execFile ( process . execPath , finderArgv )
172
80
173
- ipc . on ( 'quit-app-confirm' , function ( ) {
174
- mainWindow . removeAllListeners ( )
175
- app . quit ( )
81
+ app . on ( 'before-quit' , function ( ) {
82
+ finderProcess . kill ( )
176
83
} )
84
+ }
177
85
178
- checkUpdate ( )
179
-
86
+ app . on ( 'ready' , function ( ) {
180
87
mainWindow = require ( './main-window' )
181
- if ( process . platform === 'win32' || process . platform === 'linux' ) {
182
- mainWindow . setMenu ( menu )
183
- }
184
88
89
+ var template = require ( './main-menu' )
90
+ var menu = Menu . buildFromTemplate ( template )
185
91
switch ( process . platform ) {
186
92
case 'darwin' :
187
93
spawnFinder ( )
94
+ Menu . setApplicationMenu ( menu )
188
95
break
189
96
case 'win32' :
190
97
finderWindow = require ( './finder-window' )
191
- finderWindow . on ( 'close' , function ( e ) {
192
- e . preventDefault ( )
193
- finderWindow . hide ( )
194
- } )
98
+ mainWindow . setMenu ( menu )
195
99
break
196
100
case 'linux' :
197
101
// Finder is available on cinnamon only.
198
102
if ( process . env . DESKTOP_SESSION === 'cinnamon' ) {
199
103
finderWindow = require ( './finder-window' )
200
104
}
105
+ Menu . setApplicationMenu ( menu )
106
+ mainWindow . setMenu ( menu )
201
107
}
202
108
109
+ // Check update every hour
110
+ setInterval ( function ( ) {
111
+ checkUpdate ( )
112
+ } , 1000 * 60 * 60 )
113
+
114
+ checkUpdate ( )
115
+
203
116
require ( './hotkey' )
204
117
} )
205
118
0 commit comments