mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
web - change environment to payload API
This commit is contained in:
parent
98cd33b38a
commit
139dde2e07
|
@ -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();
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService'
|
|||
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { mapToSerializable } from 'vs/base/common/map';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
import { IWorkspaceProvider, IWorkspace } from 'vs/workbench/services/host/browser/browserHostService';
|
||||
|
||||
|
@ -64,7 +65,7 @@ class BrowserExtensionHostDebugService extends ExtensionHostDebugChannelClient i
|
|||
}
|
||||
|
||||
async openExtensionDevelopmentHostWindow(args: string[]): Promise<void> {
|
||||
if (!this.workspaceProvider.environment) {
|
||||
if (!this.workspaceProvider.payload) {
|
||||
// TODO@Ben remove me once environment is adopted
|
||||
return this.openExtensionDevelopmentHostWindowLegacy(args);
|
||||
}
|
||||
|
@ -96,8 +97,8 @@ class BrowserExtensionHostDebugService extends ExtensionHostDebugChannelClient i
|
|||
|
||||
// Open debug window as new window. Pass ParsedArgs over.
|
||||
this.workspaceProvider.open(debugWorkspace, {
|
||||
reuse: false, // debugging always requires a new window
|
||||
environment // mandatory properties to enable debugging
|
||||
reuse: false, // debugging always requires a new window
|
||||
payload: mapToSerializable(environment) // mandatory properties to enable debugging
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platf
|
|||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
import { IWorkbenchConstructionOptions } from 'vs/workbench/workbench.web.api';
|
||||
import product from 'vs/platform/product/common/product';
|
||||
import { serializableToMap } from 'vs/base/common/map';
|
||||
|
||||
export class BrowserWindowConfiguration implements IWindowConfiguration {
|
||||
|
||||
|
@ -101,8 +102,8 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
|
|||
this.untitledWorkspacesHome = URI.from({ scheme: Schemas.untitled, path: 'Workspaces' });
|
||||
|
||||
// Fill in selected extra environmental properties
|
||||
if (options.workspaceProvider && options.workspaceProvider.environment) {
|
||||
const environment = options.workspaceProvider.environment;
|
||||
if (options.workspaceProvider && Array.isArray(options.workspaceProvider.payload)) {
|
||||
const environment = serializableToMap(options.workspaceProvider.payload);
|
||||
for (const [key, value] of environment) {
|
||||
switch (key) {
|
||||
case 'extensionDevelopmentPath':
|
||||
|
|
|
@ -34,10 +34,9 @@ export interface IWorkspaceProvider {
|
|||
readonly workspace: IWorkspace;
|
||||
|
||||
/**
|
||||
* Optionally a set of environmental properties to be used
|
||||
* as environment for the workspace to open.
|
||||
* Arbitrary payload from the `IWorkspaceProvider.open` call.
|
||||
*/
|
||||
readonly environment?: ReadonlyMap<string, string>;
|
||||
readonly payload?: object;
|
||||
|
||||
/**
|
||||
* Asks to open a workspace in the current or a new window.
|
||||
|
@ -45,10 +44,10 @@ export interface IWorkspaceProvider {
|
|||
* @param workspace the workspace to open.
|
||||
* @param options optional options for the workspace to open.
|
||||
* - `reuse`: wether to open inside the current window or a new window
|
||||
* - `environment`: a map of environmental properties that should be
|
||||
* filled into the environment of the workspace to open.
|
||||
* - `payload`: arbitrary payload that should be made available
|
||||
* to the opening window via the `IWorkspaceProvider.payload` property.
|
||||
*/
|
||||
open(workspace: IWorkspace, options?: { reuse?: boolean, environment?: Map<string, string> }): Promise<void>;
|
||||
open(workspace: IWorkspace, options?: { reuse?: boolean, payload?: object }): Promise<void>;
|
||||
}
|
||||
|
||||
export class BrowserHostService extends Disposable implements IHostService {
|
||||
|
|
Loading…
Reference in a new issue