Jelajahi Sumber

feat: add type and url in new window block

Ahmad Kholid 2 tahun lalu
induk
melakukan
d4a70a3c6d

+ 25 - 10
src/background/workflowEngine/blocksHandler/handlerNewWindow.js

@@ -1,23 +1,38 @@
 import browser from 'webextension-polyfill';
+import { attachDebugger } from '../helper';
 
-export async function newWindow(block) {
-  const { incognito, windowState } = block.data;
-  const windowOptions = { incognito, state: windowState };
+export async function newWindow({ data, id }) {
+  const windowOptions = {
+    state: data.windowState,
+    incognito: data.incognito,
+    type: data.type || 'normal',
+  };
 
-  if (windowState === 'normal') {
+  if (data.windowState === 'normal') {
     ['top', 'left', 'height', 'width'].forEach((key) => {
-      if (block.data[key] <= 0) return;
+      if (data[key] <= 0) return;
 
-      windowOptions[key] = block.data[key];
+      windowOptions[key] = data[key];
     });
   }
+  if (data.url) windowOptions.url = data.url;
+
+  const newWindowInstance = await browser.windows.create(windowOptions);
+  this.windowId = newWindowInstance.id;
+
+  if (data.url) {
+    const [tab] = newWindowInstance.tabs;
 
-  const { id } = await browser.windows.create(windowOptions);
-  this.windowId = id;
+    if (this.settings.debugMode)
+      await attachDebugger(tab.id, this.activeTab.id);
+
+    this.activeTab.id = tab.id;
+    this.activeTab.url = tab.url;
+  }
 
   return {
-    data: id,
-    nextBlockId: this.getBlockConnections(block.id),
+    data: newWindowInstance.id,
+    nextBlockId: this.getBlockConnections(id),
   };
 }
 

+ 20 - 2
src/components/newtab/workflow/edit/EditNewWindow.vue

@@ -6,10 +6,27 @@
       :placeholder="t('common.description')"
       @change="updateData({ description: $event })"
     />
+    <ui-select
+      :model-value="data.type"
+      class="mt-4 w-full"
+      label="Type"
+      @change="updateData({ type: $event })"
+    >
+      <option v-for="type in windowType" :key="type" :value="type">
+        {{ type }}
+      </option>
+    </ui-select>
+    <ui-input
+      :model-value="data.url"
+      class="mt-2 w-full"
+      label="URL (optional)"
+      placeholder="https://example.com"
+      @change="updateData({ url: $event })"
+    />
     <ui-select
       :model-value="data.windowState"
-      class="w-full mt-4"
-      :placeholder="t('workflow.blocks.new-window.windowState.placeholder')"
+      class="w-full mt-2"
+      :label="t('workflow.blocks.new-window.windowState.placeholder')"
       @change="updateData({ windowState: $event })"
     >
       <option v-for="state in windowStates" :key="state" :value="state">
@@ -79,6 +96,7 @@ const emit = defineEmits(['update:data']);
 
 const { t } = useI18n();
 
+const windowType = ['normal', 'popup', 'panel'];
 const windowStates = ['normal', 'minimized', 'maximized', 'fullscreen'];
 const allowInIncognito = ref(false);
 

+ 3 - 0
src/utils/shared.js

@@ -141,13 +141,16 @@ export const tasks = {
     outputs: 1,
     allowedInputs: true,
     maxConnection: 1,
+    refDataKeys: ['url'],
     data: {
       disableBlock: false,
       description: '',
       top: 0,
       left: 0,
       width: 0,
+      url: '',
       height: 0,
+      type: 'normal',
       incognito: false,
       windowState: 'normal',
     },