forked from BoostIO/BoostNote-Legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (65 loc) · 1.74 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const { app } = require('electron')
const ChildProcess = require('child_process')
const path = require('path')
var error = null
function execMainApp() {
const appRootPath = path.join(process.execPath, '../..')
const updateDotExePath = path.join(appRootPath, 'Update.exe')
const exeName = path.basename(process.execPath)
function spawnUpdate(args, cb) {
var stdout = ''
var updateProcess = null
try {
updateProcess = ChildProcess.spawn(updateDotExePath, args)
} catch (e) {
process.nextTick(function() {
cb(e)
})
}
updateProcess.stdout.on('data', function(data) {
stdout += data
})
updateProcess.on('error', function(_error) {
error = _error
})
updateProcess.on('close', function(code, signal) {
if (code !== 0) {
error = new Error('Command failed: #{signal ? code}')
error.code = code
error.stdout = stdout
}
cb(error, stdout)
})
}
var handleStartupEvent = function() {
if (process.platform !== 'win32') {
return false
}
var squirrelCommand = process.argv[1]
switch (squirrelCommand) {
case '--squirrel-install':
spawnUpdate(['--createShortcut', exeName], function(err) {
if (err) console.error(err)
app.quit()
})
return true
case '--squirrel-updated':
app.quit()
return true
case '--squirrel-uninstall':
spawnUpdate(['--removeShortcut', exeName], function(err) {
if (err) console.error(err)
app.quit()
})
return true
case '--squirrel-obsolete':
app.quit()
return true
}
}
if (handleStartupEvent()) {
return
}
require('./lib/main-app')
}
execMainApp()