AutoUpdate Windows: Don't spawn if running
Previously, the auto updater would run as many squirrel processes as told. This introduces a little change where instead of spawning a second process, we attach to the already running process - or, if different arguments are passed, return and emit an error. This is not failsafe, but it ensures that we don't run into simple race condition crashes. Closes $5097
This commit is contained in:
parent
313883b1fc
commit
a5b93211e6
1 changed files with 25 additions and 5 deletions
|
@ -7,17 +7,34 @@ const appFolder = path.dirname(process.execPath)
|
||||||
|
|
||||||
// i.e. my-app/Update.exe
|
// i.e. my-app/Update.exe
|
||||||
const updateExe = path.resolve(appFolder, '..', 'Update.exe')
|
const updateExe = path.resolve(appFolder, '..', 'Update.exe')
|
||||||
|
|
||||||
const exeName = path.basename(process.execPath)
|
const exeName = path.basename(process.execPath)
|
||||||
|
var spawnedArgs = []
|
||||||
|
var spawnedProcess
|
||||||
|
|
||||||
|
var isSameArgs = function (args) {
|
||||||
|
return (args.length === spawnedArgs.length) && args.every(function (e, i) {
|
||||||
|
return e === spawnedArgs[i]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Spawn a command and invoke the callback when it completes with an error
|
// Spawn a command and invoke the callback when it completes with an error
|
||||||
// and the output from standard out.
|
// and the output from standard out.
|
||||||
var spawnUpdate = function (args, detached, callback) {
|
var spawnUpdate = function (args, detached, callback) {
|
||||||
var error, errorEmitted, spawnedProcess, stderr, stdout
|
var error, errorEmitted, stderr, stdout
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Ensure we don't spawn multiple squirrel processes
|
||||||
|
// Process spawned, same args: Attach events to alread running process
|
||||||
|
// Process spawned, different args: Return with error
|
||||||
|
// No process spawned: Spawn new process
|
||||||
|
if (spawnedProcess && !isSameArgs(args)) {
|
||||||
|
return callback('AutoUpdater process with arugments ' + args + ' is already running')
|
||||||
|
} else if (!spawnedProcess) {
|
||||||
spawnedProcess = spawn(updateExe, args, {
|
spawnedProcess = spawn(updateExe, args, {
|
||||||
detached: detached
|
detached: detached
|
||||||
})
|
})
|
||||||
|
spawnedArgs = args || []
|
||||||
|
}
|
||||||
} catch (error1) {
|
} catch (error1) {
|
||||||
error = error1
|
error = error1
|
||||||
|
|
||||||
|
@ -41,6 +58,9 @@ var spawnUpdate = function (args, detached, callback) {
|
||||||
return callback(error)
|
return callback(error)
|
||||||
})
|
})
|
||||||
return spawnedProcess.on('exit', function (code, signal) {
|
return spawnedProcess.on('exit', function (code, signal) {
|
||||||
|
spawnedProcess = undefined
|
||||||
|
spawnedArgs = []
|
||||||
|
|
||||||
// We may have already emitted an error.
|
// We may have already emitted an error.
|
||||||
if (errorEmitted) {
|
if (errorEmitted) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue