From 3acdf8fea7fcff1b662c2559806fd5eec87dc7f9 Mon Sep 17 00:00:00 2001 From: eight Date: Tue, 16 Oct 2018 23:47:42 +0800 Subject: [PATCH] Fix: popup doesn't use getStyle/getStylesByUrl correctly --- background/style-manager.js | 7 +++++-- popup/popup.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index 13355b83..6542ebbd 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -138,20 +138,23 @@ const styleManager = (() => { .then(newData => handleSave(newData, 'import')); } - function installStyle(data) { + function installStyle(data, reason = null) { const style = styles.get(data.id); if (!style) { data = Object.assign(createNewStyle(), data); } else { data = Object.assign({}, style.data, data); } + if (!reason) { + reason = style ? 'update' : 'install'; + } // FIXME: update updateDate? what about usercss config? return calcStyleDigest(data) .then(digest => { data.originalDigest = digest; return saveStyle(data); }) - .then(newData => handleSave(newData, style ? 'update' : 'install')); + .then(newData => handleSave(newData, reason)); } function editSave(data) { diff --git a/popup/popup.js b/popup/popup.js index 30616831..610b7d4e 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -490,7 +490,7 @@ function handleUpdate({style, reason}) { return Promise.resolve(style); } return API.getStylesByUrl(tabURL, style.id) - .then(([style]) => style); + .then(([result]) => result && Object.assign(result.data, result)); } }