From 7d005f3eaa35ea5328ecf608429de85b77dab34d Mon Sep 17 00:00:00 2001 From: eight Date: Sun, 14 Oct 2018 01:09:22 +0800 Subject: [PATCH] Change: kill style.reason --- background/update.js | 2 -- background/usercss-helper.js | 11 +++-------- edit/edit.js | 14 ++++++++------ install-usercss/install-usercss.js | 1 - manage/config-dialog.js | 1 - manage/manage.js | 6 +----- popup/popup.js | 2 +- 7 files changed, 13 insertions(+), 24 deletions(-) diff --git a/background/update.js b/background/update.js index c2ba9e5c..9daad4b5 100644 --- a/background/update.js +++ b/background/update.js @@ -182,7 +182,6 @@ json.id = style.id; json.updateDate = Date.now(); - // json.reason = 'update'; // keep current state delete json.enabled; @@ -197,7 +196,6 @@ const newStyle = Object.assign({}, style, json); if (styleSectionsEqual(json, style, {checkSource: true})) { // update digest even if save === false as there might be just a space added etc. - // json.reason = 'update-digest'; return styleManager.installStyle(newStyle) .then(saved => { style.originalDigest = saved.originalDigest; diff --git a/background/usercss-helper.js b/background/usercss-helper.js index e32c9f34..8f045317 100644 --- a/background/usercss-helper.js +++ b/background/usercss-helper.js @@ -52,18 +52,13 @@ } function assignVars(style) { - if (style.reason === 'config' && style.id) { - return style; - } return find(style) .then(dup => { if (dup) { style.id = dup.id; - if (style.reason !== 'config') { - // preserve style.vars during update - return usercss.assignVars(style, dup) - .then(() => style); - } + // preserve style.vars during update + return usercss.assignVars(style, dup) + .then(() => style); } return style; }); diff --git a/edit/edit.js b/edit/edit.js index 6c861a2c..40778825 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -321,12 +321,14 @@ function preinit() { function onRuntimeMessage(request) { switch (request.method) { case 'styleUpdated': - if (editor.getStyleId() === request.style.id && - request.reason !== 'editPreview' && - request.reason !== 'editSave' && - request.reason !== 'config') { - Promise.resolve(request.codeIsUpdated === false ? - request.style : API.getStyle(request.style.id) + if ( + editor.getStyleId() === request.style.id && + !['editPreview', 'editPreviewEnd', 'editSave', 'config'] + .includes(request.reason) + ) { + Promise.resolve( + request.codeIsUpdated === false ? + request.style : API.getStyle(request.style.id) ) .then(newStyle => { editor.replaceStyle(newStyle, request.codeIsUpdated); diff --git a/install-usercss/install-usercss.js b/install-usercss/install-usercss.js index 3d2df039..211e4e2f 100644 --- a/install-usercss/install-usercss.js +++ b/install-usercss/install-usercss.js @@ -88,7 +88,6 @@ API.installUsercss({ id: (installed || installedDup).id, - reason: 'update', sourceCode }).then(style => { updateMeta(style); diff --git a/manage/config-dialog.js b/manage/config-dialog.js index dc1b2477..73da97f0 100644 --- a/manage/config-dialog.js +++ b/manage/config-dialog.js @@ -125,7 +125,6 @@ function configDialog(style) { } style = style.sections ? Object.assign({}, style) : style; style.enabled = true; - style.reason = 'config'; style.sourceCode = null; style.sections = null; const styleVars = style.usercssData.vars; diff --git a/manage/manage.js b/manage/manage.js index 619bd9b0..c1680ced 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -419,7 +419,6 @@ Object.assign(handleEvent, { event.preventDefault(); const json = entry.updatedCode; json.id = entry.styleId; - // json.reason = 'update'; API[json.usercssData ? 'installUsercss' : 'installStyle'](json); }, @@ -519,10 +518,7 @@ Object.assign(handleEvent, { function handleUpdate(style, {reason, method} = {}) { - if (reason === 'editPreview') return; - // the style was toggled and refreshAllTabs() sent a mini-notification, - // but we've already processed 'styleUpdated' sent directly from notifyAllTabs() - // if (!style.sections) return; + if (reason === 'editPreview' || reason === 'editPreviewEnd') return; let entry; let oldEntry = $(ENTRY_ID_PREFIX + style.id); if (oldEntry && method === 'styleUpdated') { diff --git a/popup/popup.js b/popup/popup.js index 4d253e63..da8c0ccc 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -52,7 +52,7 @@ function onRuntimeMessage(msg) { case 'styleAdded': case 'styleUpdated': case 'exclusionsUpdated': - if (msg.reason === 'editPreview') return; + if (msg.reason === 'editPreview' || msg.reason === 'editPreviewEnd') return; handleUpdate(msg.style); break; case 'styleDeleted':