web - introduce workspace provider

This commit is contained in:
Benjamin Pasero
2019-09-27 14:10:32 +02:00
parent 1f80e3954c
commit ad5e5815ab
8 changed files with 116 additions and 53 deletions

View File

@@ -3,12 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IWorkbenchConstructionOptions, create, URI, Event, Emitter, UriComponents, ICredentialsProvider, IURLCallbackProvider } from 'vs/workbench/workbench.web.api';
import { IWorkbenchConstructionOptions, create, URI, Event, Emitter, UriComponents, ICredentialsProvider, IURLCallbackProvider, IWorkspaceProvider, IWorkspace } from 'vs/workbench/workbench.web.api';
import { generateUuid } from 'vs/base/common/uuid';
import { CancellationToken } from 'vs/base/common/cancellation';
import { streamToBuffer } from 'vs/base/common/buffer';
import { Disposable } from 'vs/base/common/lifecycle';
import { request } from 'vs/base/parts/request/browser/request';
import { isFolderToOpen, isWorkspaceToOpen } from 'vs/platform/windows/common/windows';
interface ICredential {
service: string;
@@ -197,18 +198,43 @@ class PollingURLCallbackProvider extends Disposable implements IURLCallbackProvi
}
}
const options: IWorkbenchConstructionOptions = JSON.parse(document.getElementById('vscode-workbench-web-configuration')!.getAttribute('data-settings')!);
class WorkspaceProvider implements IWorkspaceProvider {
constructor(public readonly workspace: IWorkspace) { }
async open(workspace: IWorkspace, options?: { reuse?: boolean }): Promise<void> {
let targetHref: string | undefined = undefined;
// Empty
if (!workspace) {
targetHref = `${document.location.origin}${document.location.pathname}?ew=true`;
}
// Folder
else if (isFolderToOpen(workspace)) {
targetHref = `${document.location.origin}${document.location.pathname}?folder=${workspace.folderUri.path}`;
}
// Workspace
else if (isWorkspaceToOpen(workspace)) {
targetHref = `${document.location.origin}${document.location.pathname}?workspace=${workspace.workspaceUri.path}`;
}
if (targetHref) {
if (options && options.reuse) {
window.location.href = targetHref;
} else {
window.open(targetHref);
}
}
}
}
const options: IWorkbenchConstructionOptions & { folderUri?: UriComponents, workspaceUri?: UriComponents } = JSON.parse(document.getElementById('vscode-workbench-web-configuration')!.getAttribute('data-settings')!);
options.workspaceProvider = new WorkspaceProvider(options.folderUri ? { folderUri: URI.revive(options.folderUri) } : options.workspaceUri ? { workspaceUri: URI.revive(options.workspaceUri) } : undefined);
options.urlCallbackProvider = new PollingURLCallbackProvider();
options.credentialsProvider = new LocalStorageCredentialsProvider();
if (options.folderUri) {
options.folderUri = URI.revive(options.folderUri);
}
if (options.workspaceUri) {
options.workspaceUri = URI.revive(options.workspaceUri);
}
if (Array.isArray(options.staticExtensions)) {
options.staticExtensions.forEach(extension => {
extension.extensionLocation = URI.revive(extension.extensionLocation);