use the new originalDigest in update UI

...when force-updating a locally edited style that turned out to be equal to the remote one

fixes #482
This commit is contained in:
tophf 2018-08-27 20:17:36 +03:00
parent 95524df6f4
commit 2fdfd96699
3 changed files with 37 additions and 7 deletions

View File

@ -153,9 +153,8 @@ global API_METHODS
case 0:
// re-install is invalid in a soft upgrade
if (!ignoreDigest) {
return Promise.reject(STATES.SAME_VERSION);
} else if (text === style.sourceCode) {
return Promise.reject(STATES.SAME_CODE);
const sameCode = text === style.sourceCode;
return Promise.reject(sameCode ? STATES.SAME_CODE : STATES.SAME_VERSION);
}
break;
case 1:
@ -188,8 +187,12 @@ global API_METHODS
if (styleSectionsEqual(json, style)) {
// update digest even if save === false as there might be just a space added etc.
saveStyle(Object.assign(json, {reason: 'update-digest'}));
return Promise.reject(STATES.SAME_CODE);
json.reason = 'update-digest';
return saveStyle(json)
.then(saved => {
style.originalDigest = saved.originalDigest;
return Promise.reject(STATES.SAME_CODE);
});
}
if (!style.originalDigest && !ignoreDigest) {

View File

@ -1,7 +1,24 @@
'use strict';
// ignoreCode=true is used by invalidateCache to determine if cached filters should be cleared
function styleSectionsEqual({sections: a}, {sections: b}, {ignoreCode = false} = {}) {
/**
* @param {Style} a - first style object
* @param {Style} b - second style object
* @param {Object} options
* @param {Boolean=} options.ignoreCode -
* true used by invalidateCache to determine if cached filters should be cleared
* @param {Boolean=} options.checkSource -
* true used by update check to compare the server response
* instead of sections that depend on @preprocessor
* @returns {Boolean|undefined}
*/
function styleSectionsEqual(a, b, {ignoreCode, checkSource} = {}) {
if (!checkSource &&
typeof a.sourceCode === 'string' &&
typeof b.sourceCode === 'string') {
return a.sourceCode === b.sourceCode;
}
a = a.sections;
b = b.sections;
if (!a || !b) {
return undefined;
}

View File

@ -155,6 +155,16 @@ function reportUpdateState({updated, style, error, STATES}) {
$('.update-note', entry).textContent = message;
$('.check-update', entry).title = newUI.enabled ? message : '';
$('.update', entry).title = t(edited ? 'updateCheckManualUpdateForce' : 'installUpdate');
// digest may change silently when forcing an update of a locally edited style
// so we need to update it in entry's styleMeta in all open manager tabs
if (error === STATES.SAME_CODE) {
for (const view of chrome.extension.getViews({type: 'tab'})) {
if (view.location.pathname === location.pathname) {
const entry = view.$(ENTRY_ID_PREFIX + style.id);
if (entry) entry.styleMeta.originalDigest = style.originalDigest;
}
}
}
if (!isCheckAll) {
renderUpdatesOnlyFilter({show: $('.can-update, .update-problem')});
}