Skip to content

Commit

Permalink
BDE-226 reload extension when setings options
Browse files Browse the repository at this point in the history
  • Loading branch information
nxmatic committed Apr 8, 2024
1 parent 33e7681 commit 08bced8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
13 changes: 13 additions & 0 deletions src/main/browser-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ class BrowserStore extends ServiceWorkerComponent {
});
}

// eslint-disable-next-line class-methods-use-this
clear() {
return new Promise((resolve, reject) => {
chrome.storage.local.clear(() => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve();
}
});
});
}

list() {
return new Promise((resolve, reject) => {
chrome.storage.local.get(null, (items) => {
Expand Down
6 changes: 3 additions & 3 deletions src/main/connect-locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class ConnectLocator extends ServiceWorkerComponent {
return this.worker.serverConnector
.asRuntimeInfo()
.then((info) => ({ connectRegistration: { connectUrl: undefined }, ...info }))
.then(({ serverUrl: nuxeoUrl, connectRegistration: { connectUrl } }) => {
if (!connectUrl) {
.then(({ serverUrl: nuxeoUrl, connectRegistration: { connectUrl: connectLocation } }) => {
if (!connectLocation) {
return {
location: 'about:blank',
credentials: undefined
Expand All @@ -54,7 +54,7 @@ class ConnectLocator extends ServiceWorkerComponent {
.then(() => this.asRegistration());
}
return this.worker.browserStore
.get({ [nuxeoKey]: connectUrl })
.get({ [nuxeoKey]: connectLocation })
.then((store) => new URL(store[nuxeoKey]))
.then((location) => ({ location, credentialsKey: this.credentialsKeyOf(location) }))
.then(({ location, credentialsKey }) => this.worker.browserStore.get({ [credentialsKey]: undefined })
Expand Down
14 changes: 14 additions & 0 deletions src/main/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ class ServiceWorkerComponentInventory extends ServiceWorkerComponent {
const componentNames = this.componentNamesOf(this.worker, recursive);
return Promise.resolve(componentNames);
}

reset() {
return this
.worker
.browserStore
.clear()
.then(() => chrome.runtime.reload());
}

reload() {
return this
.asPromise()
.then(() => chrome.runtime.reload());
}
}

class ServiceWorker extends ServiceWorkerComponent {
Expand Down
22 changes: 3 additions & 19 deletions src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function loadPage(worker) {
? worker.connectLocator.asRegistration(value)
: worker.connectLocator.asRegistration();
return registration
.then(({ location }) => (field.val(location), location));
.then(({ location }) => (field.val(location), new URL(location)));
}));

// studio package name
Expand All @@ -300,12 +300,7 @@ function loadPage(worker) {

Promise
.all(savingPromises)
// eslint-disable-next-line no-unused-vars, no-shadow
.then(([{ connectUrl }, packageName, highlight]) => {
studioPackageFound(connectUrl, packageName);
checkDependencyMismatch();
})
.then(() => worker.tabNavigationHandler.reloadServerTab());
.then(() => worker.componentInventory.reload());
});

$('#reset').click(() => {
Expand All @@ -317,18 +312,7 @@ function loadPage(worker) {
cancelButtonText: 'Cancel',
}).then((result) => {
if (!result.isConfirmed) return;
Promise.all([
worker.connectLocator
.asRegistration('https://connect.nuxeo.com'),
worker.jsonHighlighter
.withHighlight(true)
])
.then(() => {
$('#connect-url-input').val('');
$('#connect-url').hide();
$('#studio-package-name-input').hide();
$('#highlight-input').prop('checked', true);
});
worker.componentInventory.reset();
});
});

Expand Down

0 comments on commit 08bced8

Please sign in to comment.