Skip to content

Commit

Permalink
BDE-226 loading up studio project subscription and disabled shading w…
Browse files Browse the repository at this point in the history
…hen not found
  • Loading branch information
nxmatic committed Apr 8, 2024
1 parent bea9edf commit d7f9358
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 69 deletions.
14 changes: 12 additions & 2 deletions src/main/connect-locator.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ class ConnectLocator extends ServiceWorkerComponent {
asRegistration(url) {
return this.worker.serverConnector
.asRuntimeInfo()
.then(({ serverUrl: nuxeoUrl, connectUrl }) => {
.then((info) => ({ connectRegistration: { connectUrl: undefined }, ...info }))
.then(({ serverUrl: nuxeoUrl, connectRegistration: { connectUrl } }) => {
if (!connectUrl) {
return {
location: 'about:blank',
credentials: undefined
};
}
const nuxeoKey = this.nuxeoKeyOf(new URL(nuxeoUrl));
if (url) {
const { location, credentials } = this.extractCredentialsAndCleanUrl(url);
Expand All @@ -51,7 +58,10 @@ class ConnectLocator extends ServiceWorkerComponent {
.then((store) => new URL(store[nuxeoKey]))
.then((location) => ({ location, credentialsKey: this.credentialsKeyOf(location) }))
.then(({ location, credentialsKey }) => this.worker.browserStore.get({ [credentialsKey]: undefined })
.then((credentialsStore) => ({ location, credentials: credentialsStore[credentialsKey] })));
.then((credentialsStore) => ({
location,
credentials: credentialsStore[credentialsKey]
})));
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
export default function registedStudioProject() {
export default function connectRegistration() {
return `
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import groovy.json.JsonOutput
import org.nuxeo.connect.client.we.StudioSnapshotHelper
import org.nuxeo.connect.connector.CanNotReachConnectServer
import org.nuxeo.connect.connector.http.ConnectUrlConfig
import org.nuxeo.connect.data.SubscriptionStatus
import org.nuxeo.connect.data.SubscriptionStatusType
import org.nuxeo.connect.identity.LogicalInstanceIdentifier
import org.nuxeo.connect.packages.PackageManager
import org.nuxeo.connect.packages.dependencies.TargetPlatformFilterHelper
Expand Down Expand Up @@ -35,9 +38,21 @@ export default function registedStudioProject() {
return snapshotPackage.targetPlatforms.any { it == nxInstance.asString() }
}
ConnectRegistrationService registrations = Framework.getService(ConnectRegistrationService.class)
def connectSubscriptionOf(gateway) {
try {
return gateway.getConnector().getConnectStatus()
} catch (Exception cause) {
SubscriptionStatus errorStatus = new SubscriptionStatus()
errorStatus.setErrorMessage(JsonOutput.toJson([message: cause.message, type: cause.getClass().getName()]))
errorStatus.setContractStatus(SubscriptionStatusType.UNKNOWN.getValue())
return errorStatus;
}
}
ConnectRegistrationService gateway = Framework.getService(ConnectRegistrationService.class)
String connectUrl = ConnectUrlConfig.getBaseUrl()
LogicalInstanceIdentifier clid = registrations.getCLID()
LogicalInstanceIdentifier clid = gateway.getCLID()
SubscriptionStatus connectSubscription = connectSubscriptionOf(gateway)
PackageManager packages = Framework.getService(PackageManager.class)
Package snapshotPackage = StudioSnapshotHelper.getSnapshot(packages.listRemoteAssociatedStudioPackages())
Expand All @@ -47,6 +62,7 @@ export default function registedStudioProject() {
nx: nxInstance.asString(),
clid: clid,
connectUrl: connectUrl,
connectSubscription: connectSubscription,
developmentMode: Framework.isDevModeSet(),
match: isMatching(snapshotPackage, nxInstance),
package: studioPackage,
Expand Down
4 changes: 2 additions & 2 deletions src/main/groovy/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import connectLocation from './connect-location';
import connectRegistration from './connect-registration';
import developedStudioProjects from './developed-studio-projects';
import installedAddons from './installed-addons';
import registedStudioProject from './registered-studio-project';
import registerDevelopedStudioProject from './register-developed-studio-project';

export default {
'connect-location': connectLocation,
'connect-registration': connectRegistration,
'developed-studio-projects': developedStudioProjects,
'installed-addons': installedAddons,
'registered-studio-project': registedStudioProject,
'register-developed-studio-project': registerDevelopedStudioProject,
// Add more scripts here as needed
};
13 changes: 6 additions & 7 deletions src/main/server-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,31 @@ class ServerConnector extends ServiceWorkerComponent {
throw cause;
});
}

isConnected() {
return Promise.resolve(this.disconnect != null);
}

asRuntimeInfo() {
return Promise.all([
this.asConnectLocation(),
this.asInstalledAddons(),
this.asRegisteredStudioProject()
this.asConnectRegistration(),
])
.then(([connectLocation, installedAddons, registredStudioProject]) => ({
.then(([installedAddons, connectRegistration]) => ({
nuxeo: this.nuxeo,
serverUrl: this.serverUrl,
connectUrl: connectLocation,
installedAddons,
registredStudioProject,
connectRegistration,
}));
}

asConnectLocation() {
return this.executeScript('connect-location');
}

asRegisteredStudioProject() {
asConnectRegistration() {
return this
.executeScript('registered-studio-project')
.executeScript('connect-registration')
.then((result) => ({ ...result, serverUrl: this.serverUrl }));
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/studio-hot-reloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class StudioHotReloader extends ServiceWorkerComponent {
handleLegacyErrors(error) {
return this.worker.serverConnector
.asRuntimeInfo()
.then(({ nuxeo, registeredStudioProject }) => {
if (!registeredStudioProject) {
.then(({ nuxeo, connectRegistration }) => {
if (!connectRegistration) {
const notification = {
id: 'studio-not-registered',
options: {
Expand All @@ -123,14 +123,14 @@ class StudioHotReloader extends ServiceWorkerComponent {
};
return this.worker.serverConnector.handleErrors(error, notification);
}
const { package: registeredStudioPackage } = registeredStudioProject || { package: 'unknown' };
const { package: registeredStudioPackage } = connectRegistration || { package: 'unknown' };
const nuxeoServerVersion = NuxeoServerVersion.create(nuxeo.version);
const nuxeoLegacyVersion = NuxeoServerVersion.create('9.2');
if (!nuxeoServerVersion.lte(nuxeoLegacyVersion)) throw error;
// Error handling for Nuxeo 9.2 and older

let dependencyErrorNotification = null;
if (registeredStudioProject.nx !== registeredStudioPackage.studioDistrib[0]) {
if (connectRegistration.nx !== registeredStudioPackage.studioDistrib[0]) {
const message = `${registeredStudioPackage.name} - ${registeredStudioPackage.studioDistrib[0]} cannot be installed on Nuxeo ${nuxeo.version}.`;
dependencyErrorNotification = {
id: 'dependencies-ismatch',
Expand All @@ -142,7 +142,7 @@ class StudioHotReloader extends ServiceWorkerComponent {
}
};
}
if (!registeredStudioProject.match && registeredStudioPackage.deps.length > 0) {
if (!connectRegistration.match && registeredStudioPackage.deps.length > 0) {
const deps = registeredStudioPackage.deps;
const items = [];
deps.forEach((dep) => {
Expand Down
102 changes: 52 additions & 50 deletions src/popup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ function loadPage(worker) {
};

const noStudioPackageFound = () => {
$('#no-studio-buttons').css('display', 'block');
$('div.nuxeoctl-command').append('nuxeoctl register');
$('div.shade').show();
$('#no-studio-package-registered').show();
$('#no-studio-buttons').hide();
// $('div.nuxeoctl-command').append('nuxeoctl register');
// $('div.shade').show();
// $('#no-studio-package-registered').show();
worker.desktopNotifier.notify(
'no_studio_project',
{
Expand Down Expand Up @@ -412,7 +412,7 @@ function loadPage(worker) {
.then((selectBox) => {
if (!selectBox) {
return worker.serverConnector
.asRegisteredStudioProject()
.asConnectRegistration()
.then((registration) => {
const { package: studioPackage } = registration;
if (!studioPackage) return registration;
Expand Down Expand Up @@ -452,14 +452,35 @@ function loadPage(worker) {
});
})
// eslint-disable-next-line no-shadow
.then(({ serverUrl, developmentMode, package: registeredPackage }) => {
.then((registration) => {
const {
// eslint-disable-next-line no-shadow
serverUrl: serverLocation,
connectUrl: connectLocation,
connectSubscription,
developmentMode,
package: registeredPackage
} = registration;
if (!developmentMode) {
$('div.shade').show();
$('#development-mode-disabled').show();
$('#development-mode-disabled #serverUrl').text(serverUrl);
$('#development-mode-disabled #serverUrl').text(serverLocation);
}
if (connectSubscription.errorMessage) {
const error = JSON.parse(connectSubscription.errorMessage);
const alertText = `
Cannot retrieve your server connect registration from \`${connectUrl}\`...
${JSON.stringify(error, null, 2)}
`.replace(/\n/g, '<br>');

Swal.fire({
title: 'Warning',
html: alertText,
icon: 'warning',
});
}
if (registeredPackage) {
studioPackageFound(connectUrl, registeredPackage);
studioPackageFound(new URL(connectLocation), registeredPackage);
} else {
noStudioPackageFound();
}
Expand All @@ -473,54 +494,35 @@ function loadPage(worker) {
$('#traces-button').toggleClass('enabled', isEnabled);
}));

pendingPromises.push(worker.serverConnector
pendingPromises.push(worker
.serverConnector
.asRuntimeInfo()
.then((info) => {
$('#platform-version').text(` ${info.nuxeo.serverVersion.version}`);
return info;
})
.then((info) => {
const nuxeoServerVersion = NuxeoServerVersion.create(info.nuxeo.serverVersion.version);
const lts2019 = NuxeoServerVersion.create('10.10');
if (nuxeoServerVersion.lt(lts2019)) {
worker.browserStore
.set({ highlight: true })
.then(() => adjustStorageButtons());
}
return info;
})
.then((info) => {
serverUrl = info.serverUrl.replace(/\/$/, '');
return serverUrl;
})
// eslint-disable-next-line no-shadow
.then((serverUrl) => {
const serverString = DOMPurify.sanitize(serverUrl);
$('div.server-name-url').text(serverString);
return serverUrl;
})
// eslint-disable-next-line no-shadow
.then((serverUrl) => {
registerLink(
'#automation-doc',
serverUrl.concat('/site/automation/doc/')
);
return serverUrl;
})
// eslint-disable-next-line no-shadow
.then((serverUrl) => {
worker.serverConnector
.asInstalledAddons()
.then((addons) => {
if (!addons.includes('nuxeo-web-ui')) {
$('#designer-livepreview').hide();
}
const playgroundUrl = addons.includes('nuxeo-api-playground')
? `${serverUrl}/playground/#/${serverUrl}`
: `http://nuxeo.github.io/api-playground/#/${serverUrl}`;
return registerLink('#api-playground', playgroundUrl);
});
return serverUrl;

const promises = [
Promise.resolve($('#platform-version').text(` ${info.nuxeo.serverVersion.version}`)),
nuxeoServerVersion.lt(lts2019)
? worker.browserStore.set({ highlight: true }).then(() => adjustStorageButtons())
: Promise.resolve(),
Promise.resolve($('div.server-name-url').text(serverString)),
Promise.resolve(registerLink('#automation-doc', serverUrl.concat('/site/automation/doc/'))),
Promise.resolve(info.installedAddons)
.then((addons) => {
if (!addons.includes('nuxeo-web-ui')) {
$('#designer-livepreview').hide();
}
const playgroundUrl = addons.includes('nuxeo-api-playground')
? `${serverUrl}/playground/#/${serverUrl}`
: `http://nuxeo.github.io/api-playground/#/${serverUrl}`;
return registerLink('#api-playground', playgroundUrl);
})
];

return Promise.all(promises);
}));

pendingPromises.push(worker.tabNavigationHandler
Expand Down

0 comments on commit d7f9358

Please sign in to comment.