Fix: no need to access db

This commit is contained in:
eight 2018-10-12 03:46:51 +08:00
parent a8131fc9c5
commit 1b2c88f926
2 changed files with 3 additions and 5 deletions

View File

@ -17,14 +17,12 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, {
installStyle: styleManager.installStyle, installStyle: styleManager.installStyle,
editSave: styleManager.editSave, editSave: styleManager.editSave,
styleExists: styleManager.styleExists, styleExists: styleManager.styleExists,
getStyle: styleManager.get,
getTabUrlPrefix() { getTabUrlPrefix() {
return this.sender.tab.url.match(/^([\w-]+:\/+[^/#]+)/)[1]; return this.sender.tab.url.match(/^([\w-]+:\/+[^/#]+)/)[1];
}, },
getStyleFromDB: id =>
db.exec('get', id).then(event => event.target.result),
download(msg) { download(msg) {
delete msg.method; delete msg.method;
return download(msg.url, msg); return download(msg.url, msg);

View File

@ -328,7 +328,7 @@ function onRuntimeMessage(request) {
// code-less style from notifyAllTabs // code-less style from notifyAllTabs
const {sections, id} = request.style; const {sections, id} = request.style;
((sections && sections[0] || {}).code === null ((sections && sections[0] || {}).code === null
? API.getStyleFromDB(id) ? API.getStyle(id)
: Promise.resolve([request.style]) : Promise.resolve([request.style])
).then(([style]) => { ).then(([style]) => {
editor.replaceStyle(style, request.codeIsUpdated); editor.replaceStyle(style, request.codeIsUpdated);
@ -418,7 +418,7 @@ function initStyleData() {
function fetchStyle() { function fetchStyle() {
if (id) { if (id) {
return API.getStyleFromDB(id); return API.getStyle(id);
} }
return Promise.resolve(createEmptyStyle()); return Promise.resolve(createEmptyStyle());
} }