Skip to content

Commit

Permalink
v1.28.23
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 authored Dec 1, 2023
2 parents 2010e7a + be64c92 commit e15f381
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 20 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automa",
"version": "1.28.22",
"version": "1.28.23",
"description": "An extension for automating your browser by connecting blocks",
"repository": {
"type": "git",
Expand Down Expand Up @@ -65,6 +65,7 @@
"dexie": "^3.2.3",
"html2canvas": "^1.4.1",
"idb": "^7.0.2",
"js-base64": "^3.7.5",
"json5": "^2.2.3",
"jsonpath": "^1.1.1",
"jspdf": "^2.5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/background/BackgroundEventsListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function handleScheduleBackup() {
payload.storageVariables = JSON.stringify(variables);
}

const base64 = btoa(JSON.stringify(payload));
const base64 = btoa(encodeURIComponent(JSON.stringify(payload)));
const filename = `${
localBackupSettings.folderName ? `${localBackupSettings.folderName}/` : ''
}${dayjs().format('DD-MMM-YYYY--HH-mm')}.json`;
Expand Down
8 changes: 8 additions & 0 deletions src/components/newtab/workflow/edit/EditPressKey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
placeholder="keys"
@change="updateData({ keysToPress: $event })"
/>
<ui-input
:model-value="Math.min(data.pressTime || 0, 0)"
:label="t('workflow.blocks.press-key.press-time')"
type="number"
class="w-full mt-2"
:placeholder="t('common.millisecond')"
@change="updateData({ pressTime: +$event })"
/>
</div>
</template>
<script setup>
Expand Down
31 changes: 23 additions & 8 deletions src/content/blocksHandler/handlerPressKey.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isXPath, objectHasKey } from '@/utils/helper';
import { isXPath, objectHasKey, sleep } from '@/utils/helper';
import { sendMessage } from '@/utils/message';
import { keyDefinitions } from '@/utils/USKeyboardLayout';
import { queryElements } from '../handleSelector';
Expand All @@ -11,7 +11,7 @@ const modifierKeys = [
{ name: 'Control', id: 2 },
];

function pressKeyWithJs(element, keys) {
async function pressKeyWithJs({ element, keys, pressTime }) {
const details = {
key: '',
code: '',
Expand All @@ -24,8 +24,8 @@ function pressKeyWithJs(element, keys) {
cancelable: true,
};

['keydown', 'keyup'].forEach((event) => {
keys.forEach((key) => {
for (const event of ['keydown', 'keyup']) {
for (const key of keys) {
const isLetter = /^[a-zA-Z]$/.test(key);

const isModKey = modifierKeys.some(({ name }) => name === key);
Expand Down Expand Up @@ -84,10 +84,17 @@ function pressKeyWithJs(element, keys) {
element[contentKey] += '\r\n';
}
}
});
});

if (event === 'keyDown' && pressTime > 0) await sleep(pressTime);
}
}
}
async function pressKeyWithCommand(_, keys, activeTabId, actionType) {
async function pressKeyWithCommand({
keys,
pressTime,
actionType,
activeTabId,
}) {
const commands = [];
const events =
actionType === 'multiple-keys' ? ['keyDown'] : ['keyDown', 'keyUp'];
Expand Down Expand Up @@ -130,6 +137,8 @@ async function pressKeyWithCommand(_, keys, activeTabId, actionType) {

commands.push(command.params, secondEvent);
}

if (event === 'keyDown' && pressTime > 0) await sleep(pressTime);
}
}

Expand Down Expand Up @@ -160,7 +169,13 @@ async function pressKey({ data, debugMode, activeTabId }) {
: data.keysToPress.split('');
const pressKeyFunction = debugMode ? pressKeyWithCommand : pressKeyWithJs;

await pressKeyFunction(element, keys, activeTabId, data.action);
await pressKeyFunction({
keys,
element,
activeTabId,
actionType: data.action,
pressTime: Number.isNaN(+data.pressTime) ? 0 : +data.pressTime,
});

return '';
}
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@
"actions": {
"press-key": "Press a key",
"multiple-keys": "Press multiple keys"
}
},
"press-time": "Press time (milliseconds)"
},
"save-assets": {
"name": "Save assets",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"password": "Password",
"category": "Category",
"optional": "Optional",
"0disable": "0 to disable"
"0disable": "0 to disable",
"millisecond": "millisecond | milliseconds"
},
"message": {
"noBlock": "No block",
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"background": {
"scripts": ["background.bundle.js"],
"persistent": false
"persistent": true
},
"browser_action": {
"default_popup": "popup.html",
Expand Down
2 changes: 1 addition & 1 deletion src/newtab/pages/settings/SettingsBackup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ async function restoreWorkflows() {
};
reader.onload = ({ target }) => {
const payload = parseJSON(target.result, null);
const payload = parseJSON(window.decodeURIComponent(target.result), null);
if (!payload) return;
const storageTables = parseJSON(payload.storageTables, null);
Expand Down
1 change: 1 addition & 0 deletions src/utils/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ export const tasks = {
disableBlock: false,
keys: '',
selector: '',
pressTime: 0,
description: '',
keysToPress: '',
action: 'press-key',
Expand Down
4 changes: 1 addition & 3 deletions src/workflowEngine/WorkflowEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ class WorkflowEngine {

addRefDataSnapshot(key) {
this.refDataSnapshotsKeys[key].index += 1;
this.refDataSnapshotsKeys[
key
].key = `##${key}${this.refDataSnapshotsKeys[key].index}`;
this.refDataSnapshotsKeys[key].key = key;

const keyName = this.refDataSnapshotsKeys[key].key;
this.refDataSnapshots[keyName] = cloneDeep(this.referenceData[key]);
Expand Down
2 changes: 1 addition & 1 deletion src/workflowEngine/blocksHandler/handlerDelay.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function delay(block) {
return new Promise((resolve) => {
const delayTime = +block.data.time || 500;

console.log(delayTime, 'huh', block);
setTimeout(() => {
resolve({
data: '',
Expand Down
5 changes: 3 additions & 2 deletions src/workflowEngine/blocksHandler/handlerJavascriptCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ export async function javascriptCode({ outputs, data, ...block }, { refData }) {

if (inputNextBlockId) {
let customNextBlockId = this.getBlockConnections(inputNextBlockId);
if (!customNextBlockId)
throw new Error(`Can't find block with "${inputNextBlockId}" id`);

const nextBlock = this.engine.blocks[inputNextBlockId];
if (!customNextBlockId && nextBlock) {
Expand All @@ -239,6 +237,9 @@ export async function javascriptCode({ outputs, data, ...block }, { refData }) {
];
}

if (!customNextBlockId)
throw new Error(`Can't find block with "${inputNextBlockId}" id`);

nextBlockId = customNextBlockId;
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4714,6 +4714,11 @@ jiti@^1.18.2:
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.19.3.tgz#ef554f76465b3c2b222dc077834a71f0d4a37569"
integrity sha512-5eEbBDQT/jF1xg6l36P+mWGGoH9Spuy0PCdSr2dtWRDGC6ph/w9ZCL4lmESW8f8F7MwT3XKescfP0wnZWAKL9w==

js-base64@^3.7.5:
version "3.7.5"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.5.tgz#21e24cf6b886f76d6f5f165bfcd69cc55b9e3fca"
integrity sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA==

js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down

0 comments on commit e15f381

Please sign in to comment.