瀏覽代碼

feat: add shortcut to open dashboard

Ahmad Kholid 3 年之前
父節點
當前提交
3a4bfab4ae
共有 3 個文件被更改,包括 38 次插入21 次删除
  1. 27 20
      src/background/index.js
  2. 9 1
      src/manifest.json
  3. 2 0
      src/utils/shared.js

+ 27 - 20
src/background/index.js

@@ -78,7 +78,29 @@ async function updateRecording(callback) {
 
   await browser.storage.local.set({ recording });
 }
+async function openDashboard(url) {
+  const tabOptions = {
+    active: true,
+    url: browser.runtime.getURL(
+      `/newtab.html#${typeof url === 'string' ? url : ''}`
+    ),
+  };
+
+  try {
+    const [tab] = await browser.tabs.query({
+      url: browser.runtime.getURL('/newtab.html'),
+    });
 
+    if (tab) {
+      await browser.tabs.update(tab.id, tabOptions);
+      await browser.tabs.reload(tab.id);
+    } else {
+      browser.tabs.create(tabOptions);
+    }
+  } catch (error) {
+    console.error(error);
+  }
+}
 async function checkWorkflowStates() {
   const states = await workflow.states.get();
   // const sessionStates = parseJSON(sessionStorage.getItem('workflowState'), {});
@@ -134,6 +156,9 @@ browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
   checkRecordingWorkflow(changeInfo, tab);
   checkVisitWebTriggers(changeInfo, tab);
 });
+browser.commands.onCommand.addListener((name) => {
+  if (name === 'open-dashboard') openDashboard();
+});
 browser.webNavigation.onCommitted.addListener(
   ({ frameId, tabId, url, transitionType }) => {
     const allowedType = ['link', 'typed', 'form_submit'];
@@ -285,27 +310,9 @@ message.on('fetch:text', (url) => {
   return fetch(url).then((response) => response.text());
 });
 message.on('open:dashboard', async (url) => {
-  const tabOptions = {
-    active: true,
-    url: browser.runtime.getURL(
-      `/newtab.html#${typeof url === 'string' ? url : ''}`
-    ),
-  };
+  await openDashboard(url);
 
-  try {
-    const [tab] = await browser.tabs.query({
-      url: browser.runtime.getURL('/newtab.html'),
-    });
-
-    if (tab) {
-      await browser.tabs.update(tab.id, tabOptions);
-      await browser.tabs.reload(tab.id);
-    } else {
-      browser.tabs.create(tabOptions);
-    }
-  } catch (error) {
-    console.error(error);
-  }
+  return Promise.resolve(true);
 });
 message.on('set:active-tab', (tabId) => {
   return browser.tabs.update(tabId, { active: true });

+ 9 - 1
src/manifest.json

@@ -14,6 +14,15 @@
   "icons": {
     "128": "icon-128.png"
   },
+  "commands": {
+    "open-dashboard": {
+      "suggested_key": {
+        "default": "Ctrl+Shift+A",
+        "mac": "MacCtrl+Shift+A"
+      },
+      "description": "Open the Automa dashboard"
+    }
+  },
   "content_scripts": [
     {
       "matches": [
@@ -41,7 +50,6 @@
     "proxy",
     "alarms",
     "storage",
-    "debugger",
     "webNavigation",
     "unlimitedStorage",
     "<all_urls>"

+ 2 - 0
src/utils/shared.js

@@ -202,9 +202,11 @@ export const tasks = {
       ext: 'png',
       quality: 100,
       dataColumn: '',
+      variableName: '',
       fullPage: false,
       saveToColumn: false,
       saveToComputer: true,
+      assignVariable: false,
       captureActiveTab: true,
     },
   },