first pass at standardizing; suite still passing!
This commit is contained in:
parent
f25c3d33b6
commit
4794385fac
30 changed files with 1454 additions and 1462 deletions
|
@ -1,6 +1,6 @@
|
|||
const EventEmitter = require('events').EventEmitter;
|
||||
const autoUpdater = process.atomBinding('auto_updater').autoUpdater;
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
const autoUpdater = process.atomBinding('auto_updater').autoUpdater
|
||||
|
||||
autoUpdater.__proto__ = EventEmitter.prototype;
|
||||
autoUpdater.__proto__ = EventEmitter.prototype
|
||||
|
||||
module.exports = autoUpdater;
|
||||
module.exports = autoUpdater
|
||||
|
|
|
@ -1,61 +1,62 @@
|
|||
'use strict';
|
||||
'use strict'
|
||||
|
||||
const app = require('electron').app;
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const squirrelUpdate = require('./squirrel-update-win');
|
||||
const util = require('util');
|
||||
const app = require('electron').app
|
||||
const EventEmitter = require('events').EventEmitter
|
||||
const squirrelUpdate = require('./squirrel-update-win')
|
||||
const util = require('util')
|
||||
|
||||
function AutoUpdater() {
|
||||
EventEmitter.call(this);
|
||||
function AutoUpdater () {
|
||||
EventEmitter.call(this)
|
||||
}
|
||||
|
||||
util.inherits(AutoUpdater, EventEmitter);
|
||||
util.inherits(AutoUpdater, EventEmitter)
|
||||
|
||||
AutoUpdater.prototype.quitAndInstall = function() {
|
||||
squirrelUpdate.processStart();
|
||||
return app.quit();
|
||||
};
|
||||
AutoUpdater.prototype.quitAndInstall = function () {
|
||||
squirrelUpdate.processStart()
|
||||
return app.quit()
|
||||
}
|
||||
|
||||
AutoUpdater.prototype.setFeedURL = function(updateURL) {
|
||||
return this.updateURL = updateURL;
|
||||
};
|
||||
AutoUpdater.prototype.setFeedURL = function (updateURL) {
|
||||
this.updateURL = updateURL
|
||||
}
|
||||
|
||||
AutoUpdater.prototype.checkForUpdates = function() {
|
||||
AutoUpdater.prototype.checkForUpdates = function () {
|
||||
if (!this.updateURL) {
|
||||
return this.emitError('Update URL is not set');
|
||||
return this.emitError('Update URL is not set')
|
||||
}
|
||||
if (!squirrelUpdate.supported()) {
|
||||
return this.emitError('Can not find Squirrel');
|
||||
return this.emitError('Can not find Squirrel')
|
||||
}
|
||||
this.emit('checking-for-update');
|
||||
this.emit('checking-for-update')
|
||||
squirrelUpdate.download(this.updateURL, (error, update) => {
|
||||
if (error != null) {
|
||||
return this.emitError(error);
|
||||
return this.emitError(error)
|
||||
}
|
||||
if (update == null) {
|
||||
return this.emit('update-not-available');
|
||||
return this.emit('update-not-available')
|
||||
}
|
||||
this.emit('update-available');
|
||||
this.emit('update-available')
|
||||
squirrelUpdate.update(this.updateURL, (error) => {
|
||||
var date, releaseNotes, version;
|
||||
var date, releaseNotes, version
|
||||
if (error != null) {
|
||||
return this.emitError(error);
|
||||
return this.emitError(error)
|
||||
}
|
||||
releaseNotes = update.releaseNotes, version = update.version;
|
||||
releaseNotes = update.releaseNotes
|
||||
version = update.version
|
||||
|
||||
// Following information is not available on Windows, so fake them.
|
||||
date = new Date;
|
||||
date = new Date()
|
||||
this.emit('update-downloaded', {}, releaseNotes, version, date, this.updateURL, () => {
|
||||
this.quitAndInstall();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
this.quitAndInstall()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// Private: Emit both error object and message, this is to keep compatibility
|
||||
// with Old APIs.
|
||||
AutoUpdater.prototype.emitError = function(message) {
|
||||
return this.emit('error', new Error(message), message);
|
||||
};
|
||||
AutoUpdater.prototype.emitError = function (message) {
|
||||
return this.emit('error', new Error(message), message)
|
||||
}
|
||||
|
||||
module.exports = new AutoUpdater;
|
||||
module.exports = new AutoUpdater()
|
||||
|
|
|
@ -1,98 +1,95 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const spawn = require('child_process').spawn;
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const spawn = require('child_process').spawn
|
||||
|
||||
// i.e. my-app/app-0.1.13/
|
||||
const appFolder = path.dirname(process.execPath);
|
||||
const appFolder = path.dirname(process.execPath)
|
||||
|
||||
// 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)
|
||||
|
||||
// Spawn a command and invoke the callback when it completes with an error
|
||||
// and the output from standard out.
|
||||
var spawnUpdate = function(args, detached, callback) {
|
||||
var error, errorEmitted, spawnedProcess, stderr, stdout;
|
||||
var spawnUpdate = function (args, detached, callback) {
|
||||
var error, errorEmitted, spawnedProcess, stderr, stdout
|
||||
try {
|
||||
spawnedProcess = spawn(updateExe, args, {
|
||||
detached: detached
|
||||
});
|
||||
})
|
||||
} catch (error1) {
|
||||
error = error1;
|
||||
error = error1
|
||||
|
||||
// Shouldn't happen, but still guard it.
|
||||
process.nextTick(function() {
|
||||
return callback(error);
|
||||
});
|
||||
return;
|
||||
process.nextTick(function () {
|
||||
return callback(error)
|
||||
})
|
||||
return
|
||||
}
|
||||
stdout = '';
|
||||
stderr = '';
|
||||
spawnedProcess.stdout.on('data', function(data) {
|
||||
return stdout += data;
|
||||
});
|
||||
spawnedProcess.stderr.on('data', function(data) {
|
||||
return stderr += data;
|
||||
});
|
||||
errorEmitted = false;
|
||||
spawnedProcess.on('error', function(error) {
|
||||
errorEmitted = true;
|
||||
return callback(error);
|
||||
});
|
||||
return spawnedProcess.on('exit', function(code, signal) {
|
||||
|
||||
stdout = ''
|
||||
stderr = ''
|
||||
spawnedProcess.stdout.on('data', function (data) {
|
||||
return stdout += data
|
||||
})
|
||||
spawnedProcess.stderr.on('data', function (data) {
|
||||
return stderr += data
|
||||
})
|
||||
errorEmitted = false
|
||||
spawnedProcess.on('error', function (error) {
|
||||
errorEmitted = true
|
||||
return callback(error)
|
||||
})
|
||||
return spawnedProcess.on('exit', function (code, signal) {
|
||||
// We may have already emitted an error.
|
||||
if (errorEmitted) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
// Process terminated with error.
|
||||
if (code !== 0) {
|
||||
return callback("Command failed: " + (signal != null ? signal : code) + "\n" + stderr);
|
||||
return callback('Command failed: ' + (signal != null ? signal : code) + '\n' + stderr)
|
||||
}
|
||||
|
||||
// Success.
|
||||
return callback(null, stdout);
|
||||
});
|
||||
};
|
||||
return callback(null, stdout)
|
||||
})
|
||||
}
|
||||
|
||||
// Start an instance of the installed app.
|
||||
exports.processStart = function() {
|
||||
return spawnUpdate(['--processStart', exeName], true, function() {});
|
||||
};
|
||||
exports.processStart = function () {
|
||||
return spawnUpdate(['--processStart', exeName], true, function () {})
|
||||
}
|
||||
|
||||
// Download the releases specified by the URL and write new results to stdout.
|
||||
exports.download = function(updateURL, callback) {
|
||||
return spawnUpdate(['--download', updateURL], false, function(error, stdout) {
|
||||
var json, ref, ref1, update;
|
||||
exports.download = function (updateURL, callback) {
|
||||
return spawnUpdate(['--download', updateURL], false, function (error, stdout) {
|
||||
var json, ref, ref1, update
|
||||
if (error != null) {
|
||||
return callback(error);
|
||||
return callback(error)
|
||||
}
|
||||
try {
|
||||
// Last line of output is the JSON details about the releases
|
||||
json = stdout.trim().split('\n').pop();
|
||||
update = (ref = JSON.parse(json)) != null ? (ref1 = ref.releasesToApply) != null ? typeof ref1.pop === "function" ? ref1.pop() : void 0 : void 0 : void 0;
|
||||
json = stdout.trim().split('\n').pop()
|
||||
update = (ref = JSON.parse(json)) != null ? (ref1 = ref.releasesToApply) != null ? typeof ref1.pop === 'function' ? ref1.pop() : void 0 : void 0 : void 0
|
||||
} catch (jsonError) {
|
||||
return callback("Invalid result:\n" + stdout);
|
||||
return callback('Invalid result:\n' + stdout)
|
||||
}
|
||||
return callback(null, update);
|
||||
});
|
||||
};
|
||||
|
||||
return callback(null, update)
|
||||
})
|
||||
}
|
||||
|
||||
// Update the application to the latest remote version specified by URL.
|
||||
exports.update = function(updateURL, callback) {
|
||||
return spawnUpdate(['--update', updateURL], false, callback);
|
||||
};
|
||||
|
||||
exports.update = function (updateURL, callback) {
|
||||
return spawnUpdate(['--update', updateURL], false, callback)
|
||||
}
|
||||
|
||||
// Is the Update.exe installed with the current application?
|
||||
exports.supported = function() {
|
||||
exports.supported = function () {
|
||||
try {
|
||||
fs.accessSync(updateExe, fs.R_OK);
|
||||
return true;
|
||||
fs.accessSync(updateExe, fs.R_OK)
|
||||
return true
|
||||
} catch (error) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue