Fix: buildMeta now returns a promise

This commit is contained in:
eight 2018-09-25 21:11:09 +08:00
parent a004bc3c7d
commit 5d07a8cd4e

View File

@ -145,24 +145,27 @@ global API_METHODS
function maybeUpdateUsercss() { function maybeUpdateUsercss() {
// TODO: when sourceCode is > 100kB use http range request(s) for version check // TODO: when sourceCode is > 100kB use http range request(s) for version check
return download(style.updateUrl).then(text => { return download(style.updateUrl)
const json = usercss.buildMeta(text); .then(text =>
const {usercssData: {version}} = style; usercss.buildMeta(text)
const {usercssData: {version: newVersion}} = json; .then(json => {
switch (Math.sign(semverCompare(version, newVersion))) { const {usercssData: {version}} = style;
case 0: const {usercssData: {version: newVersion}} = json;
// re-install is invalid in a soft upgrade switch (Math.sign(semverCompare(version, newVersion))) {
if (!ignoreDigest) { case 0:
const sameCode = text === style.sourceCode; // re-install is invalid in a soft upgrade
return Promise.reject(sameCode ? STATES.SAME_CODE : STATES.SAME_VERSION); if (!ignoreDigest) {
} const sameCode = text === style.sourceCode;
break; return Promise.reject(sameCode ? STATES.SAME_CODE : STATES.SAME_VERSION);
case 1: }
// downgrade is always invalid break;
return Promise.reject(STATES.ERROR_VERSION); case 1:
} // downgrade is always invalid
return usercss.buildCode(json); return Promise.reject(STATES.ERROR_VERSION);
}); }
return usercss.buildCode(json);
})
);
} }
function maybeSave(json = {}) { function maybeSave(json = {}) {