Browse Source

refactor: send message on script parsed

Gerald 7 years ago
parent
commit
6e84aec3a3

+ 0 - 1
src/background/app.js

@@ -148,7 +148,6 @@ const commands = {
   Vacuum: vacuum,
   ParseScript(data) {
     return parseScript(data).then(res => {
-      sendMessageOrIgnore(res);
       sync.sync();
       return res.data;
     });

+ 1 - 2
src/background/sync/base.js

@@ -434,8 +434,7 @@ export const BaseService = serviceFactory({
             if (!getOption('syncScriptStatus') && data.config) {
               delete data.config.enabled;
             }
-            return parseScript(data)
-            .then(res => { sendMessageOrIgnore(res); });
+            return parseScript(data);
           });
         }),
         ...putRemote.map(({ local, remote }) => {

+ 3 - 2
src/background/utils/db.js

@@ -467,7 +467,7 @@ export function getExportData(ids, withValues) {
 
 export function parseScript(data) {
   const {
-    id, code, message, isNew, config, custom, props,
+    id, code, message, isNew, config, custom, props, update,
   } = data;
   const meta = parseMeta(code);
   if (!meta.name) return Promise.reject(i18n('msgInvalidScript'));
@@ -510,8 +510,9 @@ export function parseScript(data) {
   })
   .then(script => {
     fetchScriptResources(script, data);
-    Object.assign(result.data.update, script);
+    Object.assign(result.data.update, script, update);
     result.data.where = { id: script.props.id };
+    sendMessageOrIgnore(result);
     return result;
   });
 }

+ 3 - 2
src/background/utils/update.js

@@ -76,11 +76,12 @@ export default function checkUpdate(script) {
     .then(code => parseScript({
       id,
       code,
+      update: {
+        checking: false,
+      },
     }))
     .then(res => {
       const { data: { update } } = res;
-      update.checking = false;
-      sendMessageOrIgnore(res);
       updated = true;
       if (getOption('notifyUpdates')) {
         notify({