Skip to content

Commit

Permalink
BDE-233 fixing up unauthenticated reloading home page loop
Browse files Browse the repository at this point in the history
  • Loading branch information
nxmatic committed Jun 30, 2024
1 parent 1035089 commit bd5ecba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
27 changes: 16 additions & 11 deletions src/main/tab-navigation-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down
9 changes: 6 additions & 3 deletions src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ function loadPage(worker) {
function hideActionsAndToggles() {
$('.buttons').css('display', 'none');
$('.toggles').css('display', 'none');
$('.search').css('display', 'none');
}

pendingPromises.push(
Expand All @@ -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();
}));

Expand Down Expand Up @@ -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}\`...
<br/>Most probably your CLID is invalid or missing !
Expand Down Expand Up @@ -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(/\/$/, '');
Expand Down

0 comments on commit bd5ecba

Please sign in to comment.