💄 web api

This commit is contained in:
Benjamin Pasero
2019-11-06 11:03:26 +01:00
parent ef351d1559
commit a5d47335b4
2 changed files with 79 additions and 49 deletions

View File

@@ -277,13 +277,22 @@ class WorkspaceProvider implements IWorkspaceProvider {
(function () {
// Find config element in DOM
// Find config by checking for DOM
const configElement = document.getElementById('vscode-workbench-web-configuration');
const configElementAttribute = configElement ? configElement.getAttribute('data-settings') : undefined;
if (!configElement || !configElementAttribute) {
throw new Error('Missing web configuration element');
}
const config: IWorkbenchConstructionOptions & { folderUri?: UriComponents, workspaceUri?: UriComponents } = JSON.parse(configElementAttribute);
// Revive static extension locations
if (Array.isArray(config.staticExtensions)) {
config.staticExtensions.forEach(extension => {
extension.extensionLocation = URI.revive(extension.extensionLocation);
});
}
// Find workspace to open and payload
let foundWorkspace = false;
let workspace: IWorkspace;
@@ -319,27 +328,21 @@ class WorkspaceProvider implements IWorkspaceProvider {
});
// If no workspace is provided through the URL, check for config attribute from server
const options: IWorkbenchConstructionOptions & { folderUri?: UriComponents, workspaceUri?: UriComponents } = JSON.parse(configElementAttribute);
if (!foundWorkspace) {
if (options.folderUri) {
workspace = { folderUri: URI.revive(options.folderUri) };
} else if (options.workspaceUri) {
workspace = { workspaceUri: URI.revive(options.workspaceUri) };
if (config.folderUri) {
workspace = { folderUri: URI.revive(config.folderUri) };
} else if (config.workspaceUri) {
workspace = { workspaceUri: URI.revive(config.workspaceUri) };
} else {
workspace = undefined;
}
}
options.workspaceProvider = new WorkspaceProvider(workspace, payload);
options.urlCallbackProvider = new PollingURLCallbackProvider();
options.credentialsProvider = new LocalStorageCredentialsProvider();
if (Array.isArray(options.staticExtensions)) {
options.staticExtensions.forEach(extension => {
extension.extensionLocation = URI.revive(extension.extensionLocation);
});
}
// Finally create workbench
create(document.body, options);
create(document.body, {
...config,
workspaceProvider: new WorkspaceProvider(workspace, payload),
urlCallbackProvider: new PollingURLCallbackProvider(),
credentialsProvider: new LocalStorageCredentialsProvider()
});
})();