From 0fc73b5f8cd7a6084a5e5a0e5d8a7bd2b34f5987 Mon Sep 17 00:00:00 2001 From: eight Date: Wed, 26 Jun 2019 01:10:15 +0800 Subject: [PATCH] Add: styleManager.setMeta --- background/style-manager.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/background/style-manager.js b/background/style-manager.js index ce7e6149..6b53d883 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -79,7 +79,8 @@ const styleManager = (() => { addExclusion, removeExclusion, addInclusion, - removeInclusion + removeInclusion, + setMeta }); function handleColorScheme() { @@ -258,6 +259,18 @@ const styleManager = (() => { return removeIncludeExclude(id, rule, 'inclusions'); } + function setMeta(id, key, value) { + // FIXME: it is pretty danger to expose an API to modify *any* property on the data. + const oldData = styles.get(id).data; + if (oldData[key] === value) { + return; + } + const data = Object.assign({}, oldData); + data[key] = value; + return saveStyle(data) + .then(newData => handleSave(newData, 'styleSettings')); + } + function deleteStyle(id) { const style = styles.get(id); return db.exec('delete', id)