move prerelease check to appstore

This commit is contained in:
Girish Ramakrishnan
2017-10-25 20:52:05 -07:00
parent 9c02785d49
commit b30def3620
8 changed files with 40 additions and 133 deletions

View File

@@ -19,7 +19,6 @@ var apps = require('./apps.js'),
mailer = require('./mailer.js'),
paths = require('./paths.js'),
safe = require('safetydance'),
semver = require('semver'),
settings = require('./settings.js');
var gAppUpdateInfo = { }, // id -> update info { creationDate, manifest }
@@ -149,48 +148,37 @@ function checkBoxUpdates(callback) {
appstore.getBoxUpdate(function (error, updateInfo) {
if (error || !updateInfo) return callback(error);
settings.getUpdateConfig(function (error, updateConfig) {
gBoxUpdateInfo = updateInfo;
// decide whether to send email
var state = loadState();
if (state.box === gBoxUpdateInfo.version) {
debug('Skipping notification of box update as user was already notified');
return callback();
}
appstore.getSubscription(function (error, result) {
if (error) return callback(error);
var isPrerelease = semver.parse(updateInfo.version).prerelease.length !== 0;
if (isPrerelease && !updateConfig.prerelease) {
debug('Skipping update %s since this box does not want prereleases', updateInfo.version);
return callback();
function done() {
state.box = updateInfo.version;
saveState(state);
callback();
}
gBoxUpdateInfo = updateInfo;
// decide whether to send email
var state = loadState();
if (state.box === gBoxUpdateInfo.version) {
debug('Skipping notification of box update as user was already notified');
return callback();
// always send notifications if user is on the free plan
if (result.plan.id === 'free' || result.plan.id === 'undecided') {
mailer.boxUpdateAvailable(updateInfo.version, updateInfo.changelog);
return done();
}
appstore.getSubscription(function (error, result) {
if (error) return callback(error);
// only send notifications if update pattern is 'never'
settings.getAutoupdatePattern(function (error, result) {
if (error) debug(error);
else if (result === constants.AUTOUPDATE_PATTERN_NEVER) mailer.boxUpdateAvailable(updateInfo.version, updateInfo.changelog);
function done() {
state.box = updateInfo.version;
saveState(state);
callback();
}
// always send notifications if user is on the free plan
if (result.plan.id === 'free' || result.plan.id === 'undecided') {
mailer.boxUpdateAvailable(updateInfo.version, updateInfo.changelog);
return done();
}
// only send notifications if update pattern is 'never'
settings.getAutoupdatePattern(function (error, result) {
if (error) debug(error);
else if (result === constants.AUTOUPDATE_PATTERN_NEVER) mailer.boxUpdateAvailable(updateInfo.version, updateInfo.changelog);
done();
});
done();
});
});
});