Skip to content

Commit

Permalink
v1.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 authored Apr 27, 2022
2 parents efa9184 + a3aa8a9 commit 5545ab2
Show file tree
Hide file tree
Showing 72 changed files with 1,570 additions and 833 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automa",
"version": "1.8.0",
"version": "1.9.1",
"description": "An extension for automating your browser by connecting blocks",
"license": "MIT",
"repository": {
Expand Down
5 changes: 3 additions & 2 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ checkWorkflowStates();
async function checkVisitWebTriggers(changeInfo, tab) {
if (!changeInfo.status || changeInfo.status !== 'complete') return;

const tabIsUsed = await workflow.states.get(
({ state }) => state.activeTab.id === tab.id
const tabIsUsed = await workflow.states.get(({ state }) =>
state.tabIds.includes(tab.id)
);

if (tabIsUsed) return;

const visitWebTriggers = await storage.get('visitWebTriggers');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function blocksGroup({ data, outputs }, { prevBlockData }) {
}

const blocks = data.blocks.reduce((acc, block, index) => {
let nextBlock = data.blocks[index + 1]?.itemId;
let nextBlock = {
connections: [{ node: data.blocks[index + 1]?.itemId }],
};

if (index === data.blocks.length - 1) {
nextBlock = nextBlockId;
Expand All @@ -25,20 +27,20 @@ function blocksGroup({ data, outputs }, { prevBlockData }) {
id: block.itemId,
name: block.id,
outputs: {
output_1: {
connections: [{ node: nextBlock }],
},
output_1: nextBlock,
},
};

return acc;
}, {});

Object.assign(this.blocks, blocks);
Object.assign(this.engine.blocks, blocks);

resolve({
data: prevBlockData,
nextBlockId: data.blocks[0].itemId,
nextBlockId: {
connections: [{ node: data.blocks[0].itemId }],
},
});
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getBlockConnection } from '../helper';

function deleteData({ data, outputs }) {
return new Promise((resolve) => {
data.deleteList.forEach((item) => {
if (item.type === 'table') {
if (item.columnId === '[all]') {
this.engine.referenceData.table = [];
this.engine.columns = {
column: { index: 0, name: 'column', type: 'any' },
};
} else {
const columnName = this.engine.columns[item.columnId].name;

this.engine.referenceData.table.forEach((_, index) => {
const row = this.engine.referenceData.table[index];
delete row[columnName];

if (!row || Object.keys(row).length === 0) {
this.engine.referenceData.table[index] = {};
}
});

this.engine.columns[item.columnId].index = 0;
}
} else if (item.variableName) {
delete this.engine.referenceData.variables[item.variableName];
}
});

resolve({
data: '',
nextBlockId: getBlockConnection({ outputs }),
});
});
}

export default deleteData;
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ async function executeWorkflow({ outputs, data }) {
globalData: isWhitespace(data.globalData) ? null : data.globalData,
},
parentWorkflow: {
id: this.id,
name: this.workflow.name,
id: this.engine.id,
name: this.engine.workflow.name,
},
},
events: {
Expand All @@ -70,7 +70,7 @@ async function executeWorkflow({ outputs, data }) {
const { dataColumns, globalData, googleSheets, table } =
engine.referenceData;

this.referenceData.workflow[data.executeId] = {
this.engine.referenceData.workflow[data.executeId] = {
globalData,
dataColumns,
googleSheets,
Expand All @@ -79,12 +79,12 @@ async function executeWorkflow({ outputs, data }) {
}
},
},
states: this.states,
logger: this.logger,
blocksHandler: this.blocksHandler,
states: this.engine.states,
logger: this.engine.logger,
blocksHandler: this.engine.blocksHandler,
};

if (workflow.drawflow.includes(this.workflow.id)) {
if (workflow.drawflow.includes(this.engine.workflow.id)) {
throw new Error('workflow-infinite-loop');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import browser from 'webextension-polyfill';
import { default as dataExporter, files } from '@/utils/data-exporter';
import { getBlockConnection } from '../helper';

async function exportData({ data, outputs }) {
async function exportData({ data, outputs }, { refData }) {
const nextBlockId = getBlockConnection({ outputs });

try {
const dataToExport = data.dataToExport || 'data-columns';
let payload = this.referenceData.table;
let payload = refData.table;

if (dataToExport === 'google-sheets') {
payload = this.referenceData.googleSheets[data.refKey] || [];
payload = refData.googleSheets[data.refKey] || [];
} else if (dataToExport === 'variable') {
payload = this.referenceData.variables[data.variableName] || [];
payload = refData.variables[data.variableName] || [];

if (!Array.isArray(payload)) {
payload = [payload];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function updateSpreadsheetValues(
}
}

export default async function ({ data, outputs }) {
export default async function ({ data, outputs }, { refData }) {
const nextBlockId = getBlockConnection({ outputs });

try {
Expand All @@ -76,10 +76,10 @@ export default async function ({ data, outputs }) {
result = spreadsheetValues;

if (data.refKey && !isWhitespace(data.refKey)) {
this.referenceData.googleSheets[data.refKey] = spreadsheetValues;
refData.googleSheets[data.refKey] = spreadsheetValues;
}
} else if (data.type === 'update') {
result = await updateSpreadsheetValues(data, this.referenceData.table);
result = await updateSpreadsheetValues(data, refData.table);
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function handleDialog({ data, outputs }) {
const nextBlockId = getBlockConnection({ outputs });

return new Promise((resolve, reject) => {
if (!this.workflow.settings.debugMode) {
if (!this.settings.debugMode) {
const error = new Error('not-debug-mode');
error.nextBlockId = nextBlockId;

Expand All @@ -18,8 +18,8 @@ function handleDialog({ data, outputs }) {
};

const methodName = 'Page.javascriptDialogOpening';
if (!this.eventListeners[methodName]) {
this.on(methodName, () => {
if (!this.engine.eventListeners[methodName]) {
this.engine.on(methodName, () => {
sendDebugCommand(
this.activeTab.id,
'Page.handleJavaScriptDialog',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function handleDownload({ data, outputs }) {
};

const handleChanged = ({ state, id, filename }) => {
if (this.isDestroyed || isResolved) {
if (this.engine.isDestroyed || isResolved) {
browser.downloads.onChanged.removeListener(handleChanged);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function hoverElement(block) {
try {
if (!this.activeTab.id) throw new Error('no-tab');

const { debugMode, executedBlockOnWeb } = this.workflow.settings;
const { debugMode, executedBlockOnWeb } = this.settings;

if (!debugMode) {
await attachDebugger(this.activeTab.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function interactionHandler(block) {
(block.data.getValue && block.data.saveData)
) {
const currentColumnType =
this.columns[block.data.dataColumn]?.type || 'any';
this.engine.columns[block.data.dataColumn]?.type || 'any';
const insertDataToColumn = (value) => {
this.addDataToColumn(block.data.dataColumn, value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function loopBreakpoint(block, { prevBlockData }) {
});
} else {
delete this.loopList[block.data.loopId];
delete this.referenceData.loopData[block.data.loopId];
delete this.engine.referenceData.loopData[block.data.loopId];

resolve({
data: prevBlockData,
Expand Down
19 changes: 9 additions & 10 deletions src/background/workflow-engine/blocks-handler/handler-loop-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseJSON } from '@/utils/helper';
import { getBlockConnection } from '../helper';

async function loopData({ data, id, outputs }) {
async function loopData({ data, id, outputs }, { refData }) {
const nextBlockId = getBlockConnection({ outputs });

try {
Expand All @@ -13,25 +13,24 @@ async function loopData({ data, id, outputs }) {
let currentLoopData;

if (data.loopThrough === 'numbers') {
currentLoopData = this.referenceData.loopData[data.loopId].data + 1;
currentLoopData = refData.loopData[data.loopId].data + 1;
} else {
currentLoopData = this.loopList[data.loopId].data[index];
}

this.referenceData.loopData[data.loopId] = {
refData.loopData[data.loopId] = {
data: currentLoopData,
$index: index,
};
} else {
const getLoopData = {
numbers: () => data.fromNumber,
table: () => this.referenceData.table,
table: () => refData.table,
'custom-data': () => JSON.parse(data.loopData),
'data-columns': () => this.referenceData.table,
'google-sheets': () =>
this.referenceData.googleSheets[data.referenceKey],
'data-columns': () => refData.table,
'google-sheets': () => refData.googleSheets[data.referenceKey],
variable: () => {
const variableVal = this.referenceData.variables[data.variableName];
const variableVal = refData.variables[data.variableName];

return parseJSON(variableVal, variableVal);
},
Expand Down Expand Up @@ -75,7 +74,7 @@ async function loopData({ data, id, outputs }) {
: data.maxLoop || currLoopData.length,
};
/* eslint-disable-next-line */
this.referenceData.loopData[data.loopId] = {
refData.loopData[data.loopId] = {
data:
data.loopThrough === 'numbers'
? data.fromNumber
Expand All @@ -88,7 +87,7 @@ async function loopData({ data, id, outputs }) {

return {
nextBlockId,
data: this.referenceData.loopData[data.loopId],
data: refData.loopData[data.loopId],
};
} catch (error) {
error.nextBlockId = nextBlockId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function newTab(block) {

this.activeTab.url = url;
if (tab) {
if (this.workflow.settings.debugMode || customUserAgent) {
if (this.settings.debugMode || customUserAgent) {
await attachDebugger(tab.id, this.activeTab.id);

if (customUserAgent) {
Expand Down Expand Up @@ -80,7 +80,7 @@ async function newTab(block) {

this.activeTab.frameId = 0;

if (!this.workflow.settings.debugMode && customUserAgent) {
if (!this.settings.debugMode && customUserAgent) {
chrome.debugger.detach({ tabId: tab.id });
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import browser from 'webextension-polyfill';
import { getBlockConnection } from '../helper';

export async function reloadTab({ outputs }) {
const nextBlockId = getBlockConnection({ outputs });

try {
if (!this.activeTab.id) throw new Error('no-tab');

await browser.tabs.reload(this.activeTab.id);

return {
data: '',
nextBlockId,
};
} catch (error) {
error.nextBlockId = nextBlockId;

throw error;
}
}

export default reloadTab;
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async function ({ data, outputs }) {
await browser.tabs.update(tab.id, { active: true });
}

if (this.workflow.settings.debugMode) {
if (this.settings.debugMode) {
await attachDebugger(tab.id, this.activeTab.id);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import browser from 'webextension-polyfill';
import { fileSaver } from '@/utils/helper';
import { getBlockConnection } from '../helper';
import { getBlockConnection, waitTabLoaded } from '../helper';

async function saveImage({ filename, uri, ext }) {
const hasDownloadAccess = await browser.permissions.contains({
Expand Down Expand Up @@ -65,16 +65,20 @@ async function takeScreenshot({ data, outputs, name }) {
currentWindow: true,
});

if (this.windowId)
if (this.windowId) {
await browser.windows.update(this.windowId, { focused: true });
await browser.tabs.update(this.activeTab.id, { active: true });
}

await new Promise((resolve) => setTimeout(resolve, 500));
await browser.tabs.update(this.activeTab.id, { active: true });
await waitTabLoaded(this.activeTab.id);

screenshot = await (data.fullPage
screenshot = await (data.fullPage ||
['element', 'fullpage'].includes(data.type)
? this._sendMessageToTab({
name,
options,
type: data.type,
selector: data.selector,
tabId: this.activeTab.id,
})
: browser.tabs.captureVisibleTab(options));
Expand All @@ -95,6 +99,8 @@ async function takeScreenshot({ data, outputs, name }) {
} catch (error) {
error.nextBlockId = nextBlockId;

if (data.type === 'element') error.data = { selector: data.selector };

throw error;
}
}
Expand Down
Loading

0 comments on commit 5545ab2

Please sign in to comment.