瀏覽代碼

feat: add tab group option to the new tab

Ahmad Kholid 3 年之前
父節點
當前提交
ae81903018
共有 2 個文件被更改,包括 20 次插入2 次删除
  1. 19 2
      src/background/workflow-engine/blocks-handler.js
  2. 1 0
      src/background/workflow-engine/index.js

+ 19 - 2
src/background/workflow-engine/blocks-handler.js

@@ -231,7 +231,7 @@ export async function newWindow(block) {
       incognito,
       state: windowState,
     });
-    console.log('windowId', id);
+
     this.windowId = id;
 
     return {
@@ -270,7 +270,7 @@ export async function newTab(block) {
   }
 
   try {
-    const { updatePrevTab, url, active } = block.data;
+    const { updatePrevTab, url, active, inGroup } = block.data;
 
     if (updatePrevTab && this.tabId) {
       await browser.tabs.update(this.tabId, { url, active });
@@ -285,6 +285,23 @@ export async function newTab(block) {
       this.windowId = tab.windowId;
     }
 
+    if (inGroup && !updatePrevTab) {
+      const options = {
+        groupId: this.tabGroupId,
+        tabIds: this.tabId,
+      };
+
+      if (!this.tabGroupId) {
+        options.createProperties = {
+          windowId: this.windowId,
+        };
+      }
+
+      chrome.tabs.group(options, (tabGroupId) => {
+        this.tabGroupId = tabGroupId;
+      });
+    }
+
     this.frameId = 0;
     this.frames = await tabUpdatedListener.call(this, { id: this.tabId });
 

+ 1 - 0
src/background/workflow-engine/index.js

@@ -77,6 +77,7 @@ class WorkflowEngine {
     this.isDestroyed = false;
     this.frameId = null;
     this.windowId = null;
+    this.tabGroupId = null;
     this.currentBlock = null;
     this.workflowTimeout = null;