Преглед изворни кода

fix: scheduled workflows not working after extension is updated

Ahmad Kholid пре 3 година
родитељ
комит
6d9bcf575b

+ 1 - 0
.eslintrc.js

@@ -35,6 +35,7 @@ module.exports = {
     'no-underscore-dangle': 'off',
     'func-names': 'off',
     'import/no-named-default': 'off',
+    'no-restricted-syntax': 'off',
     'import/extensions': [
       'error',
       'always',

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "automa",
-  "version": "1.5.4",
+  "version": "1.6.0",
   "description": "An extension for automating your browser by connecting blocks",
   "license": "MIT",
   "repository": {

+ 35 - 15
src/background/index.js

@@ -3,7 +3,10 @@ import { MessageListener } from '@/utils/message';
 import { parseJSON, findTriggerBlock } from '@/utils/helper';
 import getFile from '@/utils/get-file';
 import decryptFlow, { getWorkflowPass } from '@/utils/decrypt-flow';
-import { registerSpecificDay } from '../utils/workflow-trigger';
+import {
+  registerSpecificDay,
+  registerWorkflowTrigger,
+} from '../utils/workflow-trigger';
 import WorkflowState from './workflow-state';
 import CollectionEngine from './collection-engine';
 import WorkflowEngine from './workflow-engine/engine';
@@ -297,10 +300,10 @@ browser.alarms.onAlarm.addListener(async ({ name }) => {
   }
 });
 
-chrome.runtime.onInstalled.addListener((details) => {
-  if (details.reason === 'install') {
-    browser.storage.local
-      .set({
+chrome.runtime.onInstalled.addListener(async ({ reason }) => {
+  try {
+    if (reason === 'install') {
+      await browser.storage.local.set({
         logs: [],
         shortcuts: {},
         workflows: [],
@@ -308,17 +311,34 @@ chrome.runtime.onInstalled.addListener((details) => {
         workflowState: {},
         isFirstTime: true,
         visitWebTriggers: [],
-      })
-      .then(() => {
-        browser.tabs
-          .create({
-            active: true,
-            url: browser.runtime.getURL('newtab.html#/welcome'),
-          })
-          .catch((error) => {
-            console.error(error);
-          });
       });
+      await browser.tabs.create({
+        active: true,
+        url: browser.runtime.getURL('newtab.html#/welcome'),
+      });
+
+      return;
+    }
+
+    if (reason === 'update') {
+      const { workflows } = await browser.storage.local.get('workflows');
+      const alarmTypes = ['specific-day', 'date', 'interval'];
+
+      for (const { trigger, drawflow, id } of workflows) {
+        let workflowTrigger = trigger?.data || trigger;
+
+        if (!trigger) {
+          const flows = parseJSON(drawflow, drawflow);
+          workflowTrigger = findTriggerBlock(flows)?.data;
+        }
+
+        if (!alarmTypes.includes(workflowTrigger.type)) return;
+
+        registerWorkflowTrigger(id, { data: workflowTrigger });
+      }
+    }
+  } catch (error) {
+    console.error(error);
   }
 });
 chrome.runtime.onStartup.addListener(async () => {

+ 1 - 1
src/components/newtab/shared/SharedConditionBuilder/ConditionBuilderInputs.vue

@@ -6,7 +6,7 @@
   >
     <div
       v-if="item.category === 'value'"
-      class="space-y-1 flex items-end space-x-2 flex-wrap"
+      class="flex items-end space-x-2 flex-wrap"
     >
       <ui-select
         :model-value="item.type"

+ 0 - 37
src/components/newtab/shared/SharedConditionBuilder/index.vue

@@ -103,43 +103,6 @@ const { t } = useI18n();
 
 const conditions = ref(JSON.parse(JSON.stringify(props.modelValue)));
 
-// const conditions = ref([
-//   {
-//     id: nanoid(),
-//     conditions: [
-//       {
-//         id: nanoid(),
-//         items: [
-//           { id: nanoid(), type: 'value', category: 'value', data: { value: '' } },
-//           { id: nanoid(), category: 'compare', type: 'eq' },
-//           { id: nanoid(), type: 'value', category: 'value', data: { value: '' } },
-//         ],
-//       },
-//       {
-//         id: nanoid(),
-//         items: [
-//           { id: nanoid(), type: 'value', category: 'value', data: { value: '' } },
-//           { id: nanoid(), category: 'compare', type: 'lt' },
-//           { id: nanoid(), type: 'value', category: 'value', data: { value: '' } },
-//         ]
-//       }
-//     ],
-//   },
-//   {
-//     id: nanoid(),
-//     conditions: [
-//       {
-//         id: nanoid(),
-//         items: [
-//           { id: nanoid(), type: 'value', category: 'value', data: { value: '' } },
-//           { id: nanoid(), category: 'compare', type: 'eq' },
-//           { id: nanoid(), type: 'value', category: 'value', data: { value: '' } },
-//         ],
-//       }
-//     ]
-//   }
-// ]);
-
 function getDefaultValues(items = ['value', 'compare', 'value']) {
   const defaultValues = {
     value: {

+ 1 - 6
src/components/newtab/workflow/edit/EditConditions.vue

@@ -111,12 +111,7 @@ function addCondition() {
   conditions.value.push({
     id: nanoid(),
     name: `Path ${conditions.value.length + 1}`,
-    conditions: [
-      {
-        id: nanoid(),
-        conditions: [],
-      },
-    ],
+    conditions: [],
   });
 }
 function deleteCondition(index) {

+ 0 - 1
src/utils/test-conditions.js

@@ -1,4 +1,3 @@
-/* eslint-disable no-restricted-syntax */
 import mustacheReplacer from './reference-data/mustache-replacer';
 import { conditionBuilder } from './shared';