hadron-auto-update-manager
Advanced tools
Comparing version 0.0.4 to 0.0.5
144
index.js
@@ -23,3 +23,3 @@ 'use strict'; | ||
function AutoUpdateManager(endpointURL) { | ||
function AutoUpdateManager(endpointURL, iconURL) { | ||
if (!endpointURL) { | ||
@@ -29,2 +29,3 @@ throw new TypeError('endpointURL is required!'); | ||
this.endpointURL = endpointURL; | ||
this.iconURL = iconURL; | ||
this.version = app.getVersion(); | ||
@@ -35,2 +36,3 @@ this.onUpdateError = _.bind(this.onUpdateError, this); | ||
this.feedURL = `${endpointURL}/updates?version=${this.version}`; | ||
debug('auto updater ready and waiting.', { | ||
@@ -41,3 +43,5 @@ version: this.version, | ||
process.nextTick( () => this.setupAutoUpdater()); | ||
process.nextTick(() => { | ||
this.setupAutoUpdater(); | ||
}); | ||
} | ||
@@ -76,25 +80,92 @@ _.extend(AutoUpdateManager.prototype, EventEmitter.prototype); | ||
}); | ||
}; | ||
this.check({ | ||
/** | ||
* @api private | ||
* @return {Boolean} Check scheduled? | ||
*/ | ||
AutoUpdateManager.prototype.scheduleUpdateCheck = function() { | ||
if (this.checkForUpdatesIntervalID) { | ||
debug('Update check already scheduled'); | ||
return false; | ||
} | ||
var fourHours = 1000 * 60 * 60 * 4; | ||
var checkForUpdates = this.checkForUpdates.bind(this, { | ||
hidePopups: true | ||
}); | ||
setInterval((function(_this) { | ||
return function() { | ||
var ref; | ||
if ((ref = _this.state) === UpdateAvailableState || ref === UnsupportedState) { | ||
console.log('Skipping update check... update ready to install, or updater unavailable.'); | ||
return; | ||
} | ||
return _this.check({ | ||
hidePopups: true | ||
}); | ||
}; | ||
})(this), 1000 * 60 * 30); | ||
if (autoUpdater.supportsUpdates != null) { | ||
if (!autoUpdater.supportsUpdates()) { | ||
return this.setState(UnsupportedState); | ||
} | ||
this.checkForUpdatesIntervalID = setInterval(checkForUpdates, fourHours); | ||
checkForUpdates(); | ||
return true; | ||
}, | ||
/** | ||
* @api private | ||
* @return {Boolean} Scheduled check cancelled? | ||
*/ | ||
AutoUpdateManager.prototype.cancelScheduledUpdateCheck = function() { | ||
if (this.checkForUpdatesIntervalID) { | ||
clearInterval(this.checkForUpdatesIntervalID); | ||
this.checkForUpdatesIntervalID = null; | ||
debug('cancelled scheduled update check'); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
AutoUpdateManager.prototype.checkForUpdates = function(opts) { | ||
opts = opts || {}; | ||
if (!opts.hidePopups) { | ||
autoUpdater.once('update-not-available', this.onUpdateNotAvailable); | ||
autoUpdater.once('error', this.onUpdateError); | ||
} | ||
debug('checking for updates...'); | ||
autoUpdater.checkForUpdates(); | ||
return true; | ||
}; | ||
/** | ||
* @api public | ||
* @return {Boolean} Auto updates enabled? | ||
*/ | ||
AutoUpdateManager.prototype.enable = function() { | ||
if (this.state === 'unsupported') { | ||
debug('Not scheduling because updates are not supported.'); | ||
return false; | ||
} | ||
return this.scheduleUpdateCheck(); | ||
}; | ||
/** | ||
* @api public | ||
*/ | ||
AutoUpdateManager.prototype.disable = function() { | ||
this.cancelScheduledUpdateCheck(); | ||
}; | ||
/** | ||
* @api public | ||
* @return {Boolean} Quit and install update? | ||
*/ | ||
AutoUpdateManager.prototype.install = function() { | ||
if (this.state !== 'update-available') { | ||
debug('No update to install'); | ||
return false; | ||
} | ||
debug('installing via autoUpdater.quitAndInstall()'); | ||
autoUpdater.quitAndInstall(); | ||
return true; | ||
}; | ||
/** | ||
* Check for updates now bypassing scheduled check. | ||
* @api public | ||
* @return {Boolean} Update check requested? | ||
*/ | ||
AutoUpdateManager.prototype.check = function() { | ||
if (this.state === 'unsupported') { | ||
debug('Updates are not supported.'); | ||
return false; | ||
} | ||
return this.checkForUpdates(); | ||
}; | ||
AutoUpdateManager.prototype.emitUpdateAvailableEvent = function() { | ||
@@ -127,33 +198,2 @@ if (!this.releaseVersion) { | ||
AutoUpdateManager.prototype.check = function(arg) { | ||
var hidePopups; | ||
hidePopups = (arg != null ? arg : {}).hidePopups; | ||
if (!hidePopups) { | ||
autoUpdater.once('update-not-available', this.onUpdateNotAvailable); | ||
autoUpdater.once('error', this.onUpdateError); | ||
} | ||
if (process.platform === 'win32') { | ||
return autoUpdater.downloadAndInstallUpdate(); | ||
} else { | ||
return autoUpdater.checkForUpdates(); | ||
} | ||
}; | ||
AutoUpdateManager.prototype.install = function() { | ||
if (process.platform === 'win32') { | ||
return autoUpdater.restartN1(); | ||
} else { | ||
return autoUpdater.quitAndInstall(); | ||
} | ||
}; | ||
AutoUpdateManager.prototype.iconURL = function() { | ||
var url; | ||
url = path.join(process.resourcesPath, 'app', 'nylas.png'); | ||
if (!fs.existsSync(url)) { | ||
return void 0; | ||
} | ||
return url; | ||
}; | ||
AutoUpdateManager.prototype.onUpdateNotAvailable = function() { | ||
@@ -164,3 +204,3 @@ autoUpdater.removeListener('error', this.onUpdateError); | ||
buttons: ['OK'], | ||
icon: this.iconURL(), | ||
icon: this.iconURL, | ||
message: 'No update available.', | ||
@@ -177,3 +217,3 @@ title: 'No Update Available', | ||
buttons: ['OK'], | ||
icon: this.iconURL(), | ||
icon: this.iconURL, | ||
message: 'There was an error checking for updates.', | ||
@@ -180,0 +220,0 @@ title: 'Update Error', |
{ | ||
"name": "hadron-auto-update-manager", | ||
"description": "Atoms AutoUpdateManager class as a standalone module.", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"scripts": { | ||
@@ -6,0 +6,0 @@ "fmt": "mongodb-js-fmt", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20421
233
0