From 631a28c1fd8870d6bbcf600d9274a89e41ee8ec9 Mon Sep 17 00:00:00 2001 From: "Stephane Lacoin (aka nxmatic)" Date: Thu, 29 Feb 2024 10:11:57 +0100 Subject: [PATCH] WIP loading in firefox --- app/scripts/bkg/common.js | 37 +++++++++++++++++------- app/scripts/bkg/designer-live-preview.js | 3 +- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app/scripts/bkg/common.js b/app/scripts/bkg/common.js index 333a9665..bac820ab 100644 --- a/app/scripts/bkg/common.js +++ b/app/scripts/bkg/common.js @@ -31,20 +31,37 @@ let dependencies; let CONNECT_URL = new URL('https://connect.nuxeo.com'); // Use the new Promise-based functions -getFromStorage('org.nuxeo.connect.url').then((value) => { - if (!value || value.length === 0) { - return; - } - CONNECT_URL = new URL(value); -}).catch((error) => { - console.error(error); -}); +getFromStorage('org.nuxeo.connect.url') + .then((entry) => { + if (entry === undefined || (typeof entry === 'object' && !Array.isArray(entry) && Object.keys(entry).length === 0)) { + // entry is undefined or an empty object, return null + return null; + } + if (typeof entry === 'string') { + // entry is a string, use it directly + return entry; + } else if (typeof entry === 'object' && !Array.isArray(entry) && entry.hasOwnProperty('org.nuxeo.connect.url')) { + // entry is a non-empty object (JSON map), retrieve the value + return entry['org.nuxeo.connect.url']; + } else { + throw new Error('Unexpected storage entry: ' + entry); + } + }) + .then((value) => { + if (!value) { + return + } + CONNECT_URL = new URL(value); + }) + .catch((error) => { + console.error(error); + }); const setConnectUrl = window.setConnectUrl = (url) => setToStorage({ - 'org.nuxeo.connect.url': url.toString() + 'org.nuxeo.connect.url': url.toString(), }).then(() => { - CONNECT_URL = url; + window.CONNECT_URL = CONNECT_URL = url; }).catch((error) => { console.error(error); }); diff --git a/app/scripts/bkg/designer-live-preview.js b/app/scripts/bkg/designer-live-preview.js index e35ecbb2..730e25dc 100644 --- a/app/scripts/bkg/designer-live-preview.js +++ b/app/scripts/bkg/designer-live-preview.js @@ -122,7 +122,7 @@ const enable = (projectName, nuxeoInstanceBaseUrl) => { nuxeoBaseUrl = nuxeoInstanceBaseUrl; const urlPattern = `${nuxeoInstanceBaseUrl.replace(/:\d+/, '')}*`; const connectLocation = CONNECT_URL.toString(); - const workspaceLocation = new URL('/nuxeo/site/studio/v2/project/${projectName}/workspace/ws.resources', CONNECT_URL).toString(); + const workspaceLocation = new URL(`/nuxeo/site/studio/v2/project/${projectName}/workspace/ws.resources`, CONNECT_URL).toString(); browser.cookies .getAll({ domain: CONNECT_URL.hostname }) @@ -184,7 +184,6 @@ const isEnabled = () => { return Object.keys(redirectedUrls).length !== 0; } -window.CONNECT_URL = CONNECT_URL; window.designerLivePreview = { enable, disable,