web - change environment to payload API

This commit is contained in:
Benjamin Pasero
2019-10-21 14:57:58 +02:00
parent 98cd33b38a
commit 139dde2e07
4 changed files with 23 additions and 23 deletions

View File

@@ -208,11 +208,11 @@ class WorkspaceProvider implements IWorkspaceProvider {
constructor(
public readonly workspace: IWorkspace,
public readonly environment: ReadonlyMap<string, string>
public readonly payload: object
) { }
async open(workspace: IWorkspace, options?: { reuse?: boolean, environment?: Map<string, string> }): Promise<void> {
if (options && options.reuse && !options.environment && this.isSame(this.workspace, workspace)) {
async open(workspace: IWorkspace, options?: { reuse?: boolean, payload?: object }): Promise<void> {
if (options && options.reuse && !options.payload && this.isSame(this.workspace, workspace)) {
return; // return early if workspace and environment is not changing and we are reusing window
}
@@ -233,10 +233,8 @@ class WorkspaceProvider implements IWorkspaceProvider {
}
// Environment
if (options && options.environment) {
for (const [key, value] of options.environment) {
targetHref += `&${key}=${encodeURIComponent(value)}`;
}
if (options && options.payload) {
targetHref += `&payload=${encodeURIComponent(JSON.stringify(options.payload))}`;
}
if (targetHref) {
@@ -290,8 +288,8 @@ class WorkspaceProvider implements IWorkspaceProvider {
workspace = undefined;
}
// Find environmental properties
const environment = new Map<string, string>();
// Find payload
let payload = Object.create(null);
if (document && document.location && document.location.search) {
const query = document.location.search.substring(1);
const vars = query.split('&');
@@ -299,14 +297,15 @@ class WorkspaceProvider implements IWorkspaceProvider {
const pair = p.split('=');
if (pair.length === 2) {
const [key, value] = pair;
if (key !== WorkspaceProvider.QUERY_PARAM_EMPTY_WINDOW && key !== WorkspaceProvider.QUERY_PARAM_FOLDER && key !== WorkspaceProvider.QUERY_PARAM_WORKSPACE) {
environment.set(key, decodeURIComponent(value));
if (key === 'payload') {
payload = JSON.parse(decodeURIComponent(value));
break;
}
}
}
}
options.workspaceProvider = new WorkspaceProvider(workspace, environment);
options.workspaceProvider = new WorkspaceProvider(workspace, payload);
options.urlCallbackProvider = new PollingURLCallbackProvider();
options.credentialsProvider = new LocalStorageCredentialsProvider();