Browse Source

fix: open new dashboard tab if showing editor

fixes #1687
tophf 3 years ago
parent
commit
6a768e8c8e
3 changed files with 9 additions and 6 deletions
  1. 7 4
      src/background/utils/tabs.js
  2. 1 1
      src/background/utils/update.js
  3. 1 1
      src/popup/views/app.vue

+ 7 - 4
src/background/utils/tabs.js

@@ -11,10 +11,11 @@ addOwnCommands({
   /**
    * @param {string} [pathId] - path or id to add to #scripts route in dashboard,
      if absent a new script will be created for active tab's URL
+     if '' the script list is opened, TODO: move to a new command for clarity?
    * @returns {Promise<chrome.tabs.Tab>}
    */
   async OpenEditor(pathId, src) {
-    if (!pathId) {
+    if (pathId == null) {
       const { tab, domain } = await commands.GetTabDomain();
       const id = domain && commands.CacheNewScript({
         url: (tab.pendingUrl || tab.url).split(/[#?]/)[0],
@@ -22,16 +23,18 @@ addOwnCommands({
       });
       pathId = `_new${id ? `/${id}` : ''}`;
     }
-    const url = `${extensionRoot}options/index.html#scripts/${pathId}`;
+    let url = extensionOptionsPage;
+    if (pathId) url += `${ROUTE_SCRIPTS}/${pathId}`;
     // Firefox until v56 doesn't support moz-extension:// pattern in browser.tabs.query()
     for (const view of browser.extension.getViews()) {
-      if (view.location.href === url) {
+      const viewUrl = view.location.href;
+      if (viewUrl === url || !pathId && viewUrl === url + ROUTE_SCRIPTS) {
         const { id: tabId, windowId } = await view.browser.tabs.getCurrent();
         browser.windows.update(windowId, { focused: true });
         return browser.tabs.update(tabId, { active: true });
       }
     }
-    return commands.TabOpen({ url, maybeInWindow: true }, src);
+    return commands.TabOpen({ url, maybeInWindow: !!pathId }, src);
   },
 });
 

+ 1 - 1
src/background/utils/update.js

@@ -32,7 +32,7 @@ function displayNotes(notes) {
     notify({
       // FF doesn't show notifications of type:'list' so we'll use `text` everywhere
       text: notes.map(n => n.text).join('\n'),
-      onClick: browser.runtime.openOptionsPage,
+      onClick: commands.OpenEditor(''),
     });
   }
 }

+ 1 - 1
src/popup/views/app.vue

@@ -366,7 +366,7 @@ export default {
       this.checkReload();
     },
     onManage() {
-      browser.runtime.openOptionsPage();
+      sendCmdDirectly('OpenEditor', '');
       window.close();
     },
     onOpenUrl(e) {