Ver código fonte

feat: multiple keys option in press key block

Ahmad Kholid 2 anos atrás
pai
commit
e423bcb5fc

+ 25 - 1
src/components/newtab/workflow/edit/EditPressKey.vue

@@ -16,7 +16,24 @@
         @change="updateData({ selector: $event })"
       />
     </edit-autocomplete>
-    <div class="flex items-end">
+    <ui-select
+      :model-value="data.action || 'press-key'"
+      :label="t('workflow.blocks.base.action')"
+      class="w-full mt-2"
+      @change="updateData({ action: $event })"
+    >
+      <option
+        v-for="action in ['press-key', 'multiple-keys']"
+        :key="action"
+        :value="action"
+      >
+        {{ t(`workflow.blocks.press-key.actions.${action}`) }}
+      </option>
+    </ui-select>
+    <div
+      v-if="!data.action || data.action === 'press-key'"
+      class="flex items-end"
+    >
       <ui-autocomplete
         :items="keysList"
         :model-value="dataKeys"
@@ -47,6 +64,13 @@
         <v-remixicon :name="isRecordingKey ? 'riCloseLine' : 'riFocus3Line'" />
       </ui-button>
     </div>
+    <ui-textarea
+      v-else
+      :model-value="data.keysToPress"
+      class="w-full mt-2"
+      placeholder="keys"
+      @change="updateData({ keysToPress: $event })"
+    />
   </div>
 </template>
 <script setup>

+ 30 - 6
src/content/blocksHandler/handlerPressKey.js

@@ -1,4 +1,4 @@
-import { isXPath } from '@/utils/helper';
+import { isXPath, objectHasKey } from '@/utils/helper';
 import { sendMessage } from '@/utils/message';
 import { keyDefinitions } from '@/utils/USKeyboardLayout';
 import { queryElements } from '../handleSelector';
@@ -87,8 +87,12 @@ function pressKeyWithJs(element, keys) {
     });
   });
 }
-async function pressKeyWithCommand(_, keys, activeTabId) {
-  for (const event of ['keyDown', 'keyUp']) {
+async function pressKeyWithCommand(_, keys, activeTabId, actionType) {
+  const commands = [];
+  const events =
+    actionType === 'multiple-keys' ? ['keyDown'] : ['keyDown', 'keyUp'];
+
+  for (const event of events) {
     let modifierKey = 0;
 
     for (const key of keys) {
@@ -116,9 +120,26 @@ async function pressKeyWithCommand(_, keys, activeTabId) {
         else command.params.modifiers = modifierKey;
       }
 
-      await sendMessage('debugger:send-command', command, 'background');
+      if (!actionType || actionType === 'press-key') {
+        await sendMessage('debugger:send-command', command, 'background');
+      } else {
+        const secondEvent = { ...command.params };
+        if (!objectHasKey(command, 'text')) {
+          secondEvent.text = key;
+        }
+
+        commands.push(command.params, secondEvent);
+      }
     }
   }
+
+  if (actionType === 'multiple-keys') {
+    await sendMessage(
+      'debugger:type',
+      { commands, tabId: activeTabId },
+      'background'
+    );
+  }
 }
 
 async function pressKey({ data, debugMode, activeTabId }) {
@@ -133,10 +154,13 @@ async function pressKey({ data, debugMode, activeTabId }) {
     element = customElement || element;
   }
 
-  const keys = data.keys.split('+');
+  const keys =
+    !data.action || data.action === 'press-key'
+      ? data.keys.split('+')
+      : data.keysToPress.split('');
   const pressKeyFunction = debugMode ? pressKeyWithCommand : pressKeyWithJs;
 
-  await pressKeyFunction(element, keys, activeTabId);
+  await pressKeyFunction(element, keys, activeTabId, data.action);
 
   return '';
 }

+ 6 - 1
src/locales/en/blocks.json

@@ -17,6 +17,7 @@
         "timeout": "Timeout (milliseconds)",
         "noPermission": "Automa don't have enough permission to do this action",
         "grantPermission": "Grant permission",
+        "action": "Action",
         "settings": {
           "title": "Block settings",
           "line": {
@@ -187,7 +188,11 @@
         "description": "Press a key or a combination",
         "target": "Target element (optional)",
         "key": "Key",
-        "detect": "Detect key"
+        "detect": "Detect key",
+        "actions": {
+          "press-key": "Press a key",
+          "multiple-keys": "Press multiple keys"
+        }
       },
       "save-assets": {
         "name": "Save assets",

+ 3 - 1
src/utils/shared.js

@@ -920,12 +920,14 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
-    refDataKeys: ['selector', 'keys'],
+    refDataKeys: ['selector', 'keys', 'keysToPress'],
     data: {
       disableBlock: false,
       keys: '',
       selector: '',
       description: '',
+      keysToPress: '',
+      action: 'press-key',
     },
   },
   'handle-dialog': {