Recording - minor fix to popup.js ('0' is a valid tabId), plus whitespace fixes

This commit is contained in:
Francis McKenzie 2020-01-24 09:52:26 +01:00
parent 30a2601d35
commit 46fe530f62
4 changed files with 40 additions and 36 deletions

View file

@ -80,7 +80,6 @@ const messageHandler = {
response = backgroundLogic.asPromise(backgroundLogic.invokeBrowserMethod(m.name, m.args)); response = backgroundLogic.asPromise(backgroundLogic.invokeBrowserMethod(m.name, m.args));
break; break;
} }
return response; return response;
}); });
@ -264,32 +263,36 @@ const messageHandler = {
} while (!succeeded); } while (!succeeded);
} }
handleTabChangedStatus(status) { handleTabStatusLoading() {
if (status === "loading") { if (!this.tabLoading) {
if (!this.tabLoading) { this.tabLoading = {};
this.tabLoading = {}; this.tabLoading.promise = new Promise((resolve) => {
this.tabLoading.promise = new Promise((resolve) => { this.tabLoading.resolve = resolve;
this.tabLoading.resolve = resolve; });
}); }
} }
} else {
if (this.tabLoading) { handleTabStatusComplete() {
this.tabLoading.resolve(); if (this.tabLoading) {
this.tabLoading = null; this.tabLoading.resolve();
} this.tabLoading = null;
} }
} }
handleTabRemoved() { handleTabRemoved() {
this.tabRemoved = true; this.tabRemoved = true;
this.removeTabListeners(); this.removeTabListeners();
this.handleTabChangedStatus("complete"); this.handleTabStatusComplete();
} }
addTabListeners() { addTabListeners() {
this.onTabsUpdated = (eventTabId, info) => { this.onTabsUpdated = (eventTabId, info) => {
if (this.tabId === eventTabId) { if (this.tabId === eventTabId) {
this.handleTabChangedStatus(info.status); if (info.status === "loading") {
this.handleTabStatusLoading();
} else {
this.handleTabStatusComplete();
}
} }
}; };

View file

@ -81,7 +81,7 @@ const Env = {
this.tabId = parseInt(tabId, 10); this.tabId = parseInt(tabId, 10);
this.isBrowserActionPopup = false; this.isBrowserActionPopup = false;
} else { } else {
this.tabId = null; this.tabId = -1;
this.isBrowserActionPopup = this.hasFullBrowserAPI; this.isBrowserActionPopup = this.hasFullBrowserAPI;
} }
} }
@ -109,6 +109,7 @@ const Logic = {
// Retrieve the list of identities. // Retrieve the list of identities.
const identitiesPromise = this.refreshIdentities(); const identitiesPromise = this.refreshIdentities();
try { try {
await identitiesPromise; await identitiesPromise;
} catch (e) { } catch (e) {
@ -257,7 +258,7 @@ const Logic = {
}, },
async currentTab() { async currentTab() {
if (Env.tabId) { if (Env.tabId >= 0) {
return await browser.tabs.get(Env.tabId); return await browser.tabs.get(Env.tabId);
} else { } else {
const activeTabs = await browser.tabs.query({ active: true, windowId: browser.windows.WINDOW_ID_CURRENT }); const activeTabs = await browser.tabs.query({ active: true, windowId: browser.windows.WINDOW_ID_CURRENT });