Browse Source

feat: add tab group option to the new tab

Ahmad Kholid 3 years ago
parent
commit
ae81903018

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

@@ -231,7 +231,7 @@ export async function newWindow(block) {
       incognito,
       incognito,
       state: windowState,
       state: windowState,
     });
     });
-    console.log('windowId', id);
+
     this.windowId = id;
     this.windowId = id;
 
 
     return {
     return {
@@ -270,7 +270,7 @@ export async function newTab(block) {
   }
   }
 
 
   try {
   try {
-    const { updatePrevTab, url, active } = block.data;
+    const { updatePrevTab, url, active, inGroup } = block.data;
 
 
     if (updatePrevTab && this.tabId) {
     if (updatePrevTab && this.tabId) {
       await browser.tabs.update(this.tabId, { url, active });
       await browser.tabs.update(this.tabId, { url, active });
@@ -285,6 +285,23 @@ export async function newTab(block) {
       this.windowId = tab.windowId;
       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.frameId = 0;
     this.frames = await tabUpdatedListener.call(this, { id: this.tabId });
     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.isDestroyed = false;
     this.frameId = null;
     this.frameId = null;
     this.windowId = null;
     this.windowId = null;
+    this.tabGroupId = null;
     this.currentBlock = null;
     this.currentBlock = null;
     this.workflowTimeout = null;
     this.workflowTimeout = null;