Browse Source

fix: active tab block

Ahmad Kholid 2 years ago
parent
commit
0591744973

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "automa",
-  "version": "1.22.1",
+  "version": "1.22.2",
   "description": "An extension for automating your browser by connecting blocks",
   "repository": {
     "type": "git",

+ 7 - 2
src/newtab/workflowEngine/blocksHandler/handlerActiveTab.js

@@ -15,11 +15,16 @@ async function activeTab(block) {
       return data;
     }
 
+    const currentWindow = await browser.windows.getCurrent();
+    if (currentWindow.focused)
+      await browser.windows.update(currentWindow.id, { focused: false });
+
+    await sleep(500);
+
     const [tab] = await browser.tabs.query({
       active: true,
-      url: '*://*/*',
+      lastFocusedWindow: true,
     });
-
     if (!tab?.url.startsWith('http')) {
       const error = new Error('invalid-active-tab');
       error.data = { url: tab.url };

+ 8 - 2
src/newtab/workflowEngine/blocksHandler/handlerSwitchTab.js

@@ -22,12 +22,18 @@ export default async function ({ data, id }) {
     throw new Error('no-tab');
   }
 
+  const currentWindow = await browser.windows.getCurrent();
+  if (currentWindow.focused)
+    await browser.windows.update(currentWindow.id, { focused: false });
+
   const isTabsQuery = ['match-patterns', 'tab-title'];
   const tabs =
-    findTabBy !== 'match-patterns' ? await browser.tabs.query({}) : [];
+    findTabBy !== 'match-patterns'
+      ? await browser.tabs.query({ lastFocusedWindow: true })
+      : [];
 
   if (isTabsQuery.includes(findTabBy)) {
-    const query = {};
+    const query = { lastFocusedWindow: true };
 
     if (data.findTabBy === 'match-patterns') query.url = data.matchPattern;
     else if (data.findTabBy === 'tab-title') query.title = data.tabTitle;

+ 1 - 1
webpack.config.js

@@ -14,7 +14,7 @@ const ASSET_PATH = process.env.ASSET_PATH || '/';
 const alias = {
   '@': path.resolve(__dirname, 'src/'),
   secrets: path.join(__dirname, 'secrets.blank.js'),
-  '@business': path.resolve(__dirname, 'business/dev'),
+  '@business': path.resolve(__dirname, 'business/prod'),
 };
 
 // load the secrets