Skip to content

Commit

Permalink
v1.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 authored Sep 24, 2022
2 parents 82a1451 + 00f4c40 commit 1c881ed
Show file tree
Hide file tree
Showing 41 changed files with 1,799 additions and 991 deletions.
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automa",
"version": "1.20.0",
"version": "1.21.0",
"description": "An extension for automating your browser by connecting blocks",
"repository": {
"type": "git",
Expand Down Expand Up @@ -28,7 +28,7 @@
"*.{js,ts,vue}": "eslint --fix"
},
"dependencies": {
"@braks/vue-flow": "0.4.30",
"@braks/vue-flow": "^0.4.40",
"@codemirror/autocomplete": "^6.1.0",
"@codemirror/lang-css": "^6.0.0",
"@codemirror/lang-html": "^6.1.0",
Expand All @@ -41,13 +41,15 @@
"@tiptap/extension-image": "^2.0.0-beta.30",
"@tiptap/extension-link": "^2.0.0-beta.43",
"@tiptap/extension-placeholder": "^2.0.0-beta.53",
"@tiptap/starter-kit": "^2.0.0-beta.191",
"@tiptap/starter-kit": "^2.0.0-beta.195",
"@tiptap/vue-3": "^2.0.0-beta.96",
"@viselect/vanilla": "^3.0.0-beta.13",
"@viselect/vanilla": "^3.1.0",
"@vueuse/rxjs": "^9.1.1",
"@vuex-orm/core": "^0.36.4",
"codemirror": "^6.0.1",
"compare-versions": "^4.1.2",
"cron-parser": "^4.6.0",
"cronstrue": "^2.11.0",
"crypto-js": "^4.1.1",
"css-selector-generator": "^3.6.4",
"dagre": "^0.8.5",
Expand All @@ -65,7 +67,7 @@
"nanoid": "^4.0.0",
"object-path": "^0.11.8",
"papaparse": "^5.3.1",
"pinia": "^2.0.18",
"pinia": "^2.0.22",
"rxjs": "^7.5.5",
"tippy.js": "^6.3.1",
"v-remixicon": "^0.1.1",
Expand All @@ -85,7 +87,7 @@
"@babel/preset-env": "^7.18.2",
"@intlify/vue-i18n-loader": "^4.2.0",
"@tailwindcss/typography": "^0.5.1",
"@vue/compiler-sfc": "^3.2.37",
"@vue/compiler-sfc": "^3.2.39",
"archiver": "^5.3.1",
"autoprefixer": "^10.4.7",
"babel-loader": "^8.2.2",
Expand Down
91 changes: 57 additions & 34 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import convertWorkflowData from '@/utils/convertWorkflowData';
import getBlockMessage from '@/utils/getBlockMessage';
import automa from '@business';
import {
registerCronJob,
registerSpecificDay,
registerContextMenu,
registerWorkflowTrigger,
Expand Down Expand Up @@ -233,21 +234,28 @@ async function openDashboard(url) {
}
}
async function checkVisitWebTriggers(tabId, tabUrl) {
const visitWebTriggers = await browserStorage.get('visitWebTriggers');
if (!visitWebTriggers || visitWebTriggers.length === 0) return;

const workflowState = await workflow.states.get(({ state }) =>
state.tabIds.includes(tabId)
);
const visitWebTriggers = await browserStorage.get('visitWebTriggers');
const triggeredWorkflow = visitWebTriggers?.find(({ url, isRegex, id }) => {
if (url.trim() === '') return false;

const matchUrl = tabUrl.match(isRegex ? new RegExp(url, 'g') : url);

return matchUrl && id !== workflowState?.workflowId;
return matchUrl && !id.includes(workflowState?.workflowId);
});

if (triggeredWorkflow) {
const workflowData = await workflow.get(triggeredWorkflow.id);
let workflowId = triggeredWorkflow.id;
if (triggeredWorkflow.id.startsWith('trigger')) {
const { 1: triggerWorkflowId } = triggeredWorkflow.id.split(':');
workflowId = triggerWorkflowId;
}

const workflowData = await workflow.get(workflowId);
if (workflowData) workflow.execute(workflowData, { tabId });
}
}
Expand Down Expand Up @@ -359,25 +367,44 @@ browser.tabs.onCreated.addListener(async (tab) => {
await browser.storage.local.set({ recording });
});
browser.alarms.onAlarm.addListener(async ({ name }) => {
const currentWorkflow = await workflow.get(name);
let workflowId = name;
let triggerId = null;

if (name.startsWith('trigger')) {
const { 1: triggerWorkflowId, 2: triggerItemId } = name.split(':');
triggerId = triggerItemId;
workflowId = triggerWorkflowId;
}

const currentWorkflow = await workflow.get(workflowId);
if (!currentWorkflow) return;

const drawflow =
typeof currentWorkflow.drawflow === 'string'
? parseJSON(currentWorkflow.drawflow, {})
: currentWorkflow.drawflow;
const { data } = findTriggerBlock(drawflow) || {};
let data = currentWorkflow.trigger;
if (!data) {
const drawflow =
typeof currentWorkflow.drawflow === 'string'
? parseJSON(currentWorkflow.drawflow, {})
: currentWorkflow.drawflow;
const { data: triggerBlockData } = findTriggerBlock(drawflow) || {};
data = triggerBlockData;
}

if (triggerId) {
data = data.triggers.find((trigger) => trigger.id === triggerId);
if (data) data = { ...data, ...data.data };
}

if (data && data.type === 'interval' && data.fixedDelay) {
const workflowState = await workflow.states.get(
({ workflowId }) => name === workflowId
(item) => item.workflowId === workflowId
);

if (workflowState) {
let { workflowQueue } = await browser.storage.local.get('workflowQueue');
workflowQueue = workflowQueue || [];

if (!workflowQueue.includes(name)) {
(workflowQueue = workflowQueue || []).push(name);
if (!workflowQueue.includes(workflowId)) {
(workflowQueue = workflowQueue || []).push(workflowId);
await browser.storage.local.set({ workflowQueue });
}

Expand All @@ -396,8 +423,14 @@ browser.alarms.onAlarm.addListener(async ({ name }) => {

workflow.execute(currentWorkflow);

if (data && data.type === 'specific-day') {
registerSpecificDay(currentWorkflow.id, data);
if (!data) return;

if (['specific-day', 'cron-job'].includes(data.type)) {
if (data.type === 'specific-day') {
registerSpecificDay(name, data);
} else {
registerCronJob(name, data);
}
}
});

Expand All @@ -413,7 +446,13 @@ if (contextMenu && contextMenu.onClicked) {
frameId: 0,
type: 'context-element',
});
const workflowData = await workflow.get(menuItemId);
let workflowId = menuItemId;
if (menuItemId.startsWith('trigger')) {
const { 1: triggerWorkflowId } = menuItemId.split(':');
workflowId = triggerWorkflowId;
}

const workflowData = await workflow.get(workflowId);

workflow.execute(workflowData, {
data: {
Expand Down Expand Up @@ -516,26 +555,10 @@ browser.runtime.onStartup.addListener(async () => {
}

if (triggerBlock) {
if (triggerBlock.type === 'specific-day') {
const alarm = await browser.alarms.get(currWorkflow.id);

if (!alarm) await registerSpecificDay(currWorkflow.id, triggerBlock);
} else if (triggerBlock.type === 'date' && triggerBlock.date) {
const [hour, minute] = triggerBlock.time.split(':');
const date = dayjs(triggerBlock.date)
.hour(hour)
.minute(minute)
.second(0);

const isBefore = dayjs().isBefore(date);

if (isBefore) {
await browser.alarms.create(currWorkflow.id, {
when: date.valueOf(),
});
}
} else if (triggerBlock.type === 'on-startup') {
if (triggerBlock.type === 'on-startup') {
workflow.execute(currWorkflow);
} else {
await registerWorkflowTrigger(currWorkflow.id, { data: triggerBlock });
}
}
}
Expand Down
28 changes: 17 additions & 11 deletions src/background/workflowEngine/blocksHandler/handlerBlockPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default async function (
const pkgCache = this.engine.packagesCache[id];

const { 1: targetId } = prevTarget.split('input-');
const addBlockPrefix = (itemId) => `${id}__${itemId}`;
const hasCache = pkgCache.nodes[targetId];
if (hasCache)
return {
Expand All @@ -21,16 +22,19 @@ export default async function (
throw new Error('Input not found');
}
const block = data.data.nodes.find((node) => node.id === input.blockId);
pkgCache.nodes[targetId] = block.id;
pkgCache.nodes[targetId] = addBlockPrefix(block.id);

const connections = {};

if (!pkgCache.extracted) {
const outputsMap = new Set();

data.inputs.forEach((item) => {
connections[item.id] = [
{ id: item.blockId, targetId: `${block.id}-input-1` },
connections[addBlockPrefix(item.id)] = [
{
id: addBlockPrefix(item.blockId),
targetId: `${addBlockPrefix(block.id)}-input-1`,
},
];
});
data.outputs.forEach((output) => {
Expand All @@ -40,11 +44,12 @@ export default async function (
this.engine.connectionsMap[`${id}-output-${output.id}`];
if (!connection) return;

connections[output.handleId] = [...connection];
connections[addBlockPrefix(output.handleId)] = [...connection];
});

data.data.nodes.forEach((node) => {
this.engine.blocks[node.id] = { ...node };
const newNodeId = addBlockPrefix(node.id);
this.engine.blocks[newNodeId] = { ...node, id: newNodeId };
});

if (!block) {
Expand All @@ -54,11 +59,12 @@ export default async function (
data.data.edges.forEach(({ sourceHandle, target, targetHandle }) => {
if (outputsMap.has(sourceHandle)) return;

if (!connections[sourceHandle]) connections[sourceHandle] = [];
connections[sourceHandle].push({
id: target,
targetHandle,
sourceHandle,
const nodeSourceHandle = addBlockPrefix(sourceHandle);
if (!connections[nodeSourceHandle]) connections[nodeSourceHandle] = [];
connections[nodeSourceHandle].push({
id: addBlockPrefix(target),
sourceHandle: nodeSourceHandle,
targetHandle: addBlockPrefix(targetHandle),
});
});

Expand All @@ -69,6 +75,6 @@ export default async function (

return {
data: prevBlockData,
nextBlockId: [{ id: block.id }],
nextBlockId: [{ id: addBlockPrefix(block.id) }],
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export async function webhook({ data, id }, { refData }) {

try {
if (isWhitespace(data.url)) throw new Error('url-empty');
if (!data.url.startsWith('http')) throw new Error('invalid-url');
if (!data.url.startsWith('http')) {
const error = new Error('invalid-active-tab');
error.data = { url: data.url };

throw error;
}

const newHeaders = [];
data.headers.forEach(({ value, name }) => {
Expand Down
12 changes: 8 additions & 4 deletions src/background/workflowEngine/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class WorkflowEngine {
};
this.rowData = {};

this.logsLimit = 1001;
this.logHistoryId = 0;

let variables = {};
let { globalData } = workflow;

if (options && options?.data) {
globalData = options.data.globalData || globalData;
variables = isObject(options.data.variables)
Expand Down Expand Up @@ -196,8 +196,7 @@ class WorkflowEngine {

if (BROWSER_TYPE !== 'chrome') {
this.workflow.settings.debugMode = false;
}
if (this.workflow.settings.debugMode) {
} else if (this.workflow.settings.debugMode) {
chrome.debugger.onEvent.addListener(this.onDebugEvent);
}
if (
Expand All @@ -214,6 +213,11 @@ class WorkflowEngine {
}
}

const { settings: userSettings } = await browser.storage.local.get(
'settings'
);
this.logsLimit = userSettings?.logsLimit || 1001;

this.workflow.table = columns;
this.startedTimestamp = Date.now();

Expand Down Expand Up @@ -255,7 +259,7 @@ class WorkflowEngine {
addLogHistory(detail) {
if (detail.name === 'blocks-group') return;

const isLimit = this.history.length >= 1001;
const isLimit = this.history.length >= this.logsLimit;
const notErrorLog = detail.type !== 'error';

if ((isLimit || !this.saveLog) && notErrorLog) return;
Expand Down
Loading

0 comments on commit 1c881ed

Please sign in to comment.