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

View File

@ -1,7 +1,24 @@
'use strict'; '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) { if (!a || !b) {
return undefined; return undefined;
} }

View File

@ -155,6 +155,16 @@ function reportUpdateState({updated, style, error, STATES}) {
$('.update-note', entry).textContent = message; $('.update-note', entry).textContent = message;
$('.check-update', entry).title = newUI.enabled ? message : ''; $('.check-update', entry).title = newUI.enabled ? message : '';
$('.update', entry).title = t(edited ? 'updateCheckManualUpdateForce' : 'installUpdate'); $('.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) { if (!isCheckAll) {
renderUpdatesOnlyFilter({show: $('.can-update, .update-problem')}); renderUpdatesOnlyFilter({show: $('.can-update, .update-problem')});
} }