Skip to content

Commit

Permalink
v1.28.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 authored Feb 16, 2023
2 parents 8536a94 + df5158f commit b2e20a7
Show file tree
Hide file tree
Showing 33 changed files with 642 additions and 85 deletions.
10 changes: 10 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
"@business": ["business/dev/*"]
}
},
"include": ["src/**/*", "utils/**/*"]
}
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.27.2",
"version": "1.28.0",
"description": "An extension for automating your browser by connecting blocks",
"repository": {
"type": "git",
Expand Down
8 changes: 7 additions & 1 deletion src/background/BackgroundWorkflowUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ class BackgroundWorkflowUtils {
static async executeWorkflow(workflowData, options) {
if (workflowData.isDisabled) return;

startWorkflowExec(workflowData, options, false);
/**
* Under v2, the background runtime environment is a real browser window. It has DOM, URL...
But these don't exist under v3. v3 uses service_worker (https://developer.mozilla.org/zh-CN/docs/Web/API/Service_Worker_API), so a dashboard page is created to run the workflow
So v2 and isPopup are actually the same
*/
const isMV2 = browser.runtime.getManifest().manifest_version === 2;
startWorkflowExec(workflowData, options, isMV2);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ message.on('recording:stop', async () => {
console.error(error);
}
});
message.on('workflow:resume', ({ id, nextBlock }) => {
if (!id) return;
workflowState.resume(id, nextBlock);
});
message.on('workflow:breakpoint', (id) => {
if (!id) return;
workflowState.update(id, { status: 'breakpoint' });
});

automa('background', message);

Expand Down
16 changes: 15 additions & 1 deletion src/components/block/BlockBase.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<div class="block-base relative w-48" @dblclick.stop="$emit('edit')">
<div
class="block-base relative w-48"
:data-block-id="blockId"
@dblclick.stop="$emit('edit')"
>
<div
class="block-menu-container absolute top-0 hidden w-full"
style="transform: translateY(-100%)"
Expand Down Expand Up @@ -65,6 +69,15 @@
</div>
<slot name="prepend" />
<ui-card :class="contentClass" class="block-base__content relative z-10">
<v-remixicon
v-if="workflow?.data?.value.testingMode"
:class="{ 'text-red-500 dark:text-red-400': data.$breakpoint }"
class="absolute left-0 top-0"
name="riRecordCircleFill"
title="Set as breakpoint"
size="20"
@click="$emit('update', { $breakpoint: !data.$breakpoint })"
/>
<slot></slot>
</ui-card>
<slot name="append" />
Expand Down Expand Up @@ -95,6 +108,7 @@ const props = defineProps({
defineEmits(['delete', 'edit', 'update', 'settings']);
const isCopied = ref(false);
const workflow = inject('workflow', null);
const workflowUtils = inject('workflow-utils', null);
function insertToClipboard() {
Expand Down
21 changes: 21 additions & 0 deletions src/components/block/BlockGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<div
class="bg-input group flex items-center space-x-2 rounded-lg p-2"
style="cursor: grab"
:data-block-id="element.id"
@dragstart="onDragStart(element, $event)"
@dragend="onDragEnd(element.itemId)"
>
Expand All @@ -75,6 +76,17 @@
</p>
</div>
<div class="invisible group-hover:visible">
<v-remixicon
v-if="workflow?.data?.value.testingMode"
:class="{
'text-red-500 dark:text-red-400': element.data.$breakpoint,
}"
title="Set as breakpoint"
name="riRecordCircleLine"
size="18"
class="mr-2 inline-block cursor-pointer"
@click="toggleBreakpoint(element, index)"
/>
<v-remixicon
name="riPencilLine"
size="18"
Expand Down Expand Up @@ -233,4 +245,13 @@ function handleDrop(event) {
];
emit('update', { blocks: copyBlocks });
}
function toggleBreakpoint(item, index) {
const copyBlocks = [...props.data.blocks];
copyBlocks[index].data = {
...copyBlocks[index].data,
$breakpoint: !item.data.$breakpoint,
};
emit('update', { blocks: copyBlocks });
}
</script>
6 changes: 4 additions & 2 deletions src/components/content/shared/SharedElementSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ function onKeydown(event) {
);
}
function onMousedown(event) {
event.preventDefault();
event.stopPropagation();
if (event.target.id === 'automa-selector-overlay') {
event.preventDefault();
event.stopPropagation();
}
retrieveElementsRect(event, 'selected');
}
function onMessage({ data }) {
Expand Down
5 changes: 4 additions & 1 deletion src/components/newtab/app/AppLogsItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ function clearLogs() {
okVariant: 'danger',
body: t('log.clearLogs.description'),
onConfirm: () => {
dbLogs.delete();
dbLogs.items.clear();
dbLogs.ctxData.clear();
dbLogs.logsData.clear();
dbLogs.histories.clear();
},
});
}
Expand Down
9 changes: 1 addition & 8 deletions src/components/newtab/logs/LogsHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ import Papa from 'papaparse';
import objectPath from 'object-path';
import { countDuration, fileSaver } from '@/utils/helper';
import { getBlocks } from '@/utils/getSharedData';
import { dataExportTypes } from '@/utils/shared';
import { dataExportTypes, messageHasReferences } from '@/utils/shared';
import dayjs from '@/lib/dayjs';
const SharedCodemirror = defineAsyncComponent(() =>
Expand Down Expand Up @@ -363,13 +363,6 @@ const tabs = [
{ id: 'referenceData.prevBlockData', name: 'Previous block data' },
{ id: 'replacedValue', name: 'Replaced value' },
];
const messageHasReferences = [
'no-tab',
'invalid-active-tab',
'no-match-tab',
'invalid-body',
'element-not-found',
];
const { t, te } = useI18n();
Expand Down
198 changes: 198 additions & 0 deletions src/components/newtab/workflow/editor/EditorDebugging.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<template>
<ui-card
v-if="workflowState?.state"
class="shadow-xl flex items-start fixed bottom-8 z-50 left-1/2 -translate-x-1/2"
>
<div class="mr-4 w-52">
<div class="flex items-center gap-2">
<ui-button
:disabled="workflowState.state.nextBlockBreakpoint"
variant="accent"
class="flex-1"
@click="toggleExecution"
>
<v-remixicon
:name="
workflowState.status === 'breakpoint'
? 'riPlayLine'
: 'riPauseLine'
"
class="mr-2 -ml-1"
/>
<span>
{{
t(
`common.${
workflowState.status === 'breakpoint' ? 'resume' : 'pause'
}`
)
}}
</span>
</ui-button>
<ui-button
v-tooltip="t('workflow.testing.nextBlock')"
:disabled="workflowState.status !== 'breakpoint'"
icon
@click="nextBlock"
>
<v-remixicon name="riArrowLeftSLine" rotate="180" />
</ui-button>
<ui-button
v-tooltip="t('common.stop')"
icon
class="text-red-500 dark:text-red-600"
@click="stopWorkflow"
>
<v-remixicon name="riStopLine" />
</ui-button>
</div>
<ui-list
v-if="workflowState.state"
class="mt-4 overflow-auto h-[105px] scroll"
>
<ui-list-item
v-for="block in workflowState.state.currentBlock"
:key="block.id"
small
>
<div class="text-overflow text-sm w-full">
<div class="flex items-center">
<p class="flex-1 text-overflow">
{{ getBlockName(block.name) }}
</p>
<v-remixicon
title="Go to block"
name="riEyeLine"
size="18"
class="text-gray-600 dark:text-gray-200 cursor-pointer"
@click="$emit('goToBlock', block.id)"
/>
</div>
<p
class="leading-tight text-overflow text-gray-600 dark:text-gray-200"
>
{{ t('workflow.testing.startRun') }}:
{{ dayjs(block.startedAt).format('HH:mm:ss, SSS') }}
</p>
</div>
</ui-list-item>
</ui-list>
</div>
<shared-codemirror
:model-value="JSON.stringify(workflowData, null, 2)"
:line-numbers="false"
hide-lang
readonly
lang="json"
class="h-40 w-64 scroll breakpoint-data"
/>
</ui-card>
</template>
<script setup>
import { defineAsyncComponent, computed, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import dayjs from '@/lib/dayjs';
import { tasks } from '@/utils/shared';
import { debounce } from '@/utils/helper';
import { sendMessage } from '@/utils/message';
const SharedCodemirror = defineAsyncComponent(() =>
import('@/components/newtab/shared/SharedCodemirror.vue')
);
const props = defineProps({
states: {
type: Array,
default: () => [],
},
editor: {
type: Object,
default: () => ({}),
},
});
defineEmits(['goToBlock']);
let currentRunningEls = [];
const { t, te } = useI18n();
const workflowState = computed(() => props.states[0]);
const workflowData = computed(() => {
if (!workflowState.value?.state?.ctxData) return {};
const { ctxData, dataSnapshot } = workflowState.value.state.ctxData;
const latestData = Object.values(ctxData).at(-1);
if (!latestData) return {};
return {
...latestData,
referenceData: {
...latestData.referenceData,
loopData: dataSnapshot[latestData.referenceData.loopData] ?? {},
variables: dataSnapshot[latestData.referenceData.variables] ?? {},
},
};
});
function getBlockName(blockId) {
const key = `workflow.blocks.${blockId}.name`;
return te(key) ? t(key) : tasks[blockId].name;
}
function toggleExecution() {
if (!workflowState.value) return;
if (workflowState.value.status === 'running') {
sendMessage('workflow:breakpoint', workflowState.value.id, 'background');
} else {
sendMessage(
'workflow:resume',
{ id: workflowState.value.id },
'background'
);
}
}
function stopWorkflow() {
if (!workflowState.value) return;
sendMessage('workflow:stop', workflowState.value.id, 'background');
}
function nextBlock() {
sendMessage(
'workflow:resume',
{ id: workflowState.value.id, nextBlock: true },
'background'
);
}
watch(
workflowState,
debounce(() => {
currentRunningEls.forEach((element) => {
element.classList.remove('current-running');
});
if (!workflowState.value?.state?.currentBlock) return;
const selectors = workflowState.value.state.currentBlock
.map((block) => `.vue-flow [data-block-id="${block.id}"]`)
.join(',');
const elements = document.querySelectorAll(selectors);
currentRunningEls = elements;
elements.forEach((el) => {
el.classList.add('current-running');
});
}, 200),
{ immediate: true }
);
</script>
<style>
.breakpoint-data .cm-editor {
font-size: 13px;
padding-bottom: 0;
}
.current-running {
@apply ring;
}
</style>
Loading

0 comments on commit b2e20a7

Please sign in to comment.