Ver código fonte

fix: sync after real removement

Gerald 8 anos atrás
pai
commit
ad9e67ec0b
2 arquivos alterados com 17 adições e 8 exclusões
  1. 7 2
      src/background/app.js
  2. 10 6
      src/background/utils/db.js

+ 7 - 2
src/background/app.js

@@ -11,7 +11,7 @@ import {
   initialize,
 } from './utils';
 import {
-  getScripts, removeScript, getData, getScriptsByURL,
+  getScripts, removeScript, getData, checkRemove, getScriptsByURL,
   updateScriptInfo, setValues, getExportData, getScriptCode,
   getScriptByIds, moveScript, vacuum, parseScript, getScript,
   normalizePosition,
@@ -71,7 +71,12 @@ const commands = {
     .then(() => { sync.sync(); });
   },
   GetData() {
-    return getData().then(data => {
+    return checkRemove()
+    .then(changed => {
+      if (changed) sync.sync();
+      return getData();
+    })
+    .then(data => {
       data.sync = sync.getStates();
       data.version = VM_VER;
       return data;

+ 10 - 6
src/background/utils/db.js

@@ -386,12 +386,6 @@ export function getScriptsByURL(url) {
  */
 export function getData() {
   const cacheKeys = {};
-  const toRemove = store.scripts.filter(script => script.config.removed);
-  if (toRemove.length) {
-    store.scripts = store.scripts.filter(script => !script.config.removed);
-    storage.script.removeMulti(toRemove);
-    storage.code.removeMulti(toRemove);
-  }
   const { scripts } = store;
   scripts.forEach(script => {
     const icon = object.get(script, 'meta.icon');
@@ -407,6 +401,16 @@ export function getData() {
   .then(cache => ({ scripts, cache }));
 }
 
+export function checkRemove() {
+  const toRemove = store.scripts.filter(script => script.config.removed);
+  if (toRemove.length) {
+    store.scripts = store.scripts.filter(script => !script.config.removed);
+    storage.script.removeMulti(toRemove);
+    storage.code.removeMulti(toRemove);
+  }
+  return Promise.resolve(toRemove.length);
+}
+
 export function removeScript(id) {
   const i = store.scripts.findIndex(item => id === object.get(item, 'props.id'));
   if (i >= 0) {