From bd5ecba3f08f6fd9de1e66b16faf5248071fe3ba Mon Sep 17 00:00:00 2001 From: "Stephane Lacoin (aka nxmatic)" Date: Sun, 30 Jun 2024 00:05:30 +0200 Subject: [PATCH] BDE-233 fixing up unauthenticated reloading home page loop --- src/main/tab-navigation-handler.js | 27 ++++++++++++++++----------- src/popup/index.js | 9 ++++++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/tab-navigation-handler.js b/src/main/tab-navigation-handler.js index fb7724c9..a7e0f56f 100644 --- a/src/main/tab-navigation-handler.js +++ b/src/main/tab-navigation-handler.js @@ -134,11 +134,12 @@ class TabNavigationHandler extends ServiceWorkerComponent { .then(() => serverUrl); }) .catch((cause) => { - if (cause.isForbidden) { - return; + if (!cause.isForbidden) { + console.error('Handled tab activation <- caught error', tabInfo, cause); } - console.error('Handled tab activation <- caught error', tabInfo, cause); - })); + return Promise.reject(cause); + }) + .finally(() => console.log('Handled tab activation <- done', tabInfo))); } asServerUrl(tabInfo) { @@ -180,30 +181,34 @@ class TabNavigationHandler extends ServiceWorkerComponent { reloadServerTab(context = { rootUrl: this.worker.serverConnector.serverUrl, tabInfo: this.tabInfo - }, maxAttempts = 1, waitingTime = 4000) { + }, maxAttempts = 1, waitingTime = 4000, hasReloaded = false) { return Promise.resolve(context) .then(({ rootUrl, tabInfo }) => { if (!tabInfo) { throw new Error('No nuxeo server tab info selected'); } return { rootUrl, tabInfo }; - }).then(({ rootUrl, tabInfo }) => { - const runnningstatusUrl = `${rootUrl}/runningstatus`; + }).then(({ rootUrl }) => { + const runningStatusUrl = `${rootUrl}/runningstatus`; let attempts = 0; const checkStatus = () => { attempts += 1; if (attempts > maxAttempts) { throw new Error(`Maximum number of attempts reached on ${rootUrl}...`); } - return fetch(runnningstatusUrl) + return fetch(runningStatusUrl) .then((response) => { if (!response.ok) { - // If the status page is not available, check again after a delay + // If the status page is not available, check again after a delay return new Promise((resolve) => setTimeout(resolve, waitingTime)) .then(checkStatus); } - chrome.tabs.reload(tabInfo.id); - return tabInfo; + // Reload the tab only if it has not been reloaded yet + if (!hasReloaded) { + // chrome.tabs.reload(tabInfo.id); + hasReloaded = true; // Update the flag to prevent further reloads + } + return response; }) .catch(() => new Promise((resolve) => setTimeout(resolve, waitingTime)) .then(checkStatus)); diff --git a/src/popup/index.js b/src/popup/index.js index 69785ae0..fc9f9428 100644 --- a/src/popup/index.js +++ b/src/popup/index.js @@ -370,6 +370,7 @@ function loadPage(worker) { function hideActionsAndToggles() { $('.buttons').css('display', 'none'); $('.toggles').css('display', 'none'); + $('.search').css('display', 'none'); } pendingPromises.push( @@ -386,8 +387,7 @@ function loadPage(worker) { hideActionsAndToggles(); }) .catch((error) => { - worker.developmentMode.asConsole() - .then((console) => console.warn('Not connected, cannot check user role', error)); + console.warn('Not connected, cannot check user role', error); hideActionsAndToggles(); })); @@ -450,7 +450,7 @@ function loadPage(worker) { $('#development-mode-disabled').show(); $('#development-mode-disabled #serverUrl').text(serverLocation); } - if (connectSubscription.errorMessage) { + if (connectSubscription && connectSubscription.errorMessage) { const alertText = ` Cannot retrieve your server registration from \`${connectUrl}\`...
Most probably your CLID is invalid or missing ! @@ -481,6 +481,9 @@ function loadPage(worker) { .serverConnector .asRuntimeInfo() .then((info) => { + if (!info.nuxeo.connected) { + return Promise.resolve(); + } const nuxeoServerVersion = NuxeoServerVersion.create(info.nuxeo.serverVersion.version); const lts2019 = NuxeoServerVersion.create('10.10'); serverUrl = info.serverUrl.replace(/\/$/, '');