diff --git a/src/vs/base/parts/ipc/common/ipc.ts b/src/vs/base/parts/ipc/common/ipc.ts index 535502f3efd..0757b52ab81 100644 --- a/src/vs/base/parts/ipc/common/ipc.ts +++ b/src/vs/base/parts/ipc/common/ipc.ts @@ -1023,146 +1023,141 @@ export class StaticRouter implements IClientRouter } } - -//#region createChannelReceiver / createChannelSender - /** - * Use both `createChannelReceiver` and `createChannelSender` - * for automated process <=> process communication over methods - * and events. You do not need to spell out each method on both - * sides, a proxy will take care of this. + * Use ProxyChannels to automatically wrapping and unwrapping + * services to/from IPC channels, instead of manually wrapping + * each service method and event. * - * Rules: - * - if marshalling is enabled, only `URI` and `RegExp` is converted + * Restrictions: + * - If marshalling is enabled, only `URI` and `RegExp` is converted * automatically for you - * - events must follow the naming convention `onUppercase` + * - Events must follow the naming convention `onUpperCase` * - `CancellationToken` is currently not supported - * - if a context is provided, you can use `AddFirstParameterToFunctions` + * - If a context is provided, you can use `AddFirstParameterToFunctions` * utility to signal this in the receiving side type */ +export namespace ProxyChannel { -export interface IBaseChannelOptions { + export interface IProxyOptions { - /** - * Disables automatic marshalling of `URI`. - * If marshalling is disabled, `UriComponents` - * must be used instead. - */ - disableMarshalling?: boolean; -} - -export interface IChannelReceiverOptions extends IBaseChannelOptions { } - -export function createChannelReceiver(service: unknown, options?: IChannelReceiverOptions): IServerChannel { - const handler = service as { [key: string]: unknown }; - const disableMarshalling = options && options.disableMarshalling; - - // Buffer any event that should be supported by - // iterating over all property keys and finding them - const mapEventNameToEvent = new Map>(); - for (const key in handler) { - if (propertyIsEvent(key)) { - mapEventNameToEvent.set(key, Event.buffer(handler[key] as Event, true)); - } + /** + * Disables automatic marshalling of `URI`. + * If marshalling is disabled, `UriComponents` + * must be used instead. + */ + disableMarshalling?: boolean; } - return new class implements IServerChannel { + export interface ICreateServiceChannelOptions extends IProxyOptions { } - listen(_: unknown, event: string): Event { - const eventImpl = mapEventNameToEvent.get(event); - if (eventImpl) { - return eventImpl as Event; + export function fromService(service: unknown, options?: ICreateServiceChannelOptions): IServerChannel { + const handler = service as { [key: string]: unknown }; + const disableMarshalling = options && options.disableMarshalling; + + // Buffer any event that should be supported by + // iterating over all property keys and finding them + const mapEventNameToEvent = new Map>(); + for (const key in handler) { + if (propertyIsEvent(key)) { + mapEventNameToEvent.set(key, Event.buffer(handler[key] as Event, true)); } - - throw new Error(`Event not found: ${event}`); } - call(_: unknown, command: string, args?: any[]): Promise { - const target = handler[command]; - if (typeof target === 'function') { + return new class implements IServerChannel { - // Revive unless marshalling disabled - if (!disableMarshalling && Array.isArray(args)) { - for (let i = 0; i < args.length; i++) { - args[i] = revive(args[i]); - } + listen(_: unknown, event: string): Event { + const eventImpl = mapEventNameToEvent.get(event); + if (eventImpl) { + return eventImpl as Event; } - return target.apply(handler, args); + throw new Error(`Event not found: ${event}`); } - throw new Error(`Method not found: ${command}`); - } - }; -} - -export interface IChannelSenderOptions extends IBaseChannelOptions { - - /** - * If provided, will add the value of `context` - * to each method call to the target. - */ - context?: unknown; - - /** - * If provided, will not proxy any of the properties - * that are part of the Map but rather return that value. - */ - properties?: Map; -} - -export function createChannelSender(channel: IChannel, options?: IChannelSenderOptions): T { - const disableMarshalling = options && options.disableMarshalling; - - return new Proxy({}, { - get(_target: T, propKey: PropertyKey) { - if (typeof propKey === 'string') { - - // Check for predefined values - if (options?.properties?.has(propKey)) { - return options.properties.get(propKey); - } - - // Event - if (propertyIsEvent(propKey)) { - return channel.listen(propKey); - } - - // Function - return async function (...args: any[]) { - - // Add context if any - let methodArgs: any[]; - if (options && !isUndefinedOrNull(options.context)) { - methodArgs = [options.context, ...args]; - } else { - methodArgs = args; - } - - const result = await channel.call(propKey, methodArgs); + call(_: unknown, command: string, args?: any[]): Promise { + const target = handler[command]; + if (typeof target === 'function') { // Revive unless marshalling disabled - if (!disableMarshalling) { - return revive(result); + if (!disableMarshalling && Array.isArray(args)) { + for (let i = 0; i < args.length; i++) { + args[i] = revive(args[i]); + } } - return result; - }; + return target.apply(handler, args); + } + + throw new Error(`Method not found: ${command}`); } + }; + } - throw new Error(`Property not found: ${String(propKey)}`); - } - }) as T; + export interface ICreateProxyServiceOptions extends IProxyOptions { + + /** + * If provided, will add the value of `context` + * to each method call to the target. + */ + context?: unknown; + + /** + * If provided, will not proxy any of the properties + * that are part of the Map but rather return that value. + */ + properties?: Map; + } + + export function toService(channel: IChannel, options?: ICreateProxyServiceOptions): T { + const disableMarshalling = options && options.disableMarshalling; + + return new Proxy({}, { + get(_target: T, propKey: PropertyKey) { + if (typeof propKey === 'string') { + + // Check for predefined values + if (options?.properties?.has(propKey)) { + return options.properties.get(propKey); + } + + // Event + if (propertyIsEvent(propKey)) { + return channel.listen(propKey); + } + + // Function + return async function (...args: any[]) { + + // Add context if any + let methodArgs: any[]; + if (options && !isUndefinedOrNull(options.context)) { + methodArgs = [options.context, ...args]; + } else { + methodArgs = args; + } + + const result = await channel.call(propKey, methodArgs); + + // Revive unless marshalling disabled + if (!disableMarshalling) { + return revive(result); + } + + return result; + }; + } + + throw new Error(`Property not found: ${String(propKey)}`); + } + }) as T; + } + + function propertyIsEvent(name: string): boolean { + // Assume a property is an event if it has a form of "onSomething" + return name[0] === 'o' && name[1] === 'n' && strings.isUpperAsciiLetter(name.charCodeAt(2)); + } } -function propertyIsEvent(name: string): boolean { - // Assume a property is an event if it has a form of "onSomething" - return name[0] === 'o' && name[1] === 'n' && strings.isUpperAsciiLetter(name.charCodeAt(2)); -} - -//#endregion - - const colorTables = [ ['#2977B1', '#FC802D', '#34A13A', '#D3282F', '#9366BA'], ['#8B564C', '#E177C0', '#7F7F7F', '#BBBE3D', '#2EBECD'] diff --git a/src/vs/base/parts/ipc/test/common/ipc.test.ts b/src/vs/base/parts/ipc/test/common/ipc.test.ts index 8ed0f3797f1..6e3dd39a5e1 100644 --- a/src/vs/base/parts/ipc/test/common/ipc.test.ts +++ b/src/vs/base/parts/ipc/test/common/ipc.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { IChannel, IServerChannel, IMessagePassingProtocol, IPCServer, ClientConnectionEvent, IPCClient, createChannelReceiver, createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { IChannel, IServerChannel, IMessagePassingProtocol, IPCServer, ClientConnectionEvent, IPCClient, ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { Emitter, Event } from 'vs/base/common/event'; import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation'; import { canceled } from 'vs/base/common/errors'; @@ -332,10 +332,10 @@ suite('Base IPC', function () { const testServer = new TestIPCServer(); server = testServer; - server.registerChannel(TestChannelId, createChannelReceiver(service)); + server.registerChannel(TestChannelId, ProxyChannel.fromService(service)); client = testServer.createConnection('client1'); - ipcService = createChannelSender(client.getChannel(TestChannelId)); + ipcService = ProxyChannel.toService(client.getChannel(TestChannelId)); }); teardown(function () { @@ -398,10 +398,10 @@ suite('Base IPC', function () { const testServer = new TestIPCServer(); server = testServer; - server.registerChannel(TestChannelId, createChannelReceiver(service)); + server.registerChannel(TestChannelId, ProxyChannel.fromService(service)); client = testServer.createConnection('client1'); - ipcService = createChannelSender(client.getChannel(TestChannelId), { context: 'Super Context' }); + ipcService = ProxyChannel.toService(client.getChannel(TestChannelId), { context: 'Super Context' }); }); teardown(function () { diff --git a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts index e8639c8ea31..50b7e18bc89 100644 --- a/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts +++ b/src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts @@ -8,7 +8,7 @@ import * as fs from 'fs'; import { release } from 'os'; import { gracefulify } from 'graceful-fs'; import { Server as MessagePortServer } from 'vs/base/parts/ipc/electron-sandbox/ipc.mp'; -import { StaticRouter, createChannelSender, createChannelReceiver } from 'vs/base/parts/ipc/common/ipc'; +import { StaticRouter, ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; @@ -184,7 +184,7 @@ class SharedProcessMain extends Disposable { services.set(IRequestService, new SyncDescriptor(RequestService)); // Native Host - const nativeHostService = createChannelSender(mainProcessService.getChannel('nativeHost'), { context: this.configuration.windowId }); + const nativeHostService = ProxyChannel.toService(mainProcessService.getChannel('nativeHost'), { context: this.configuration.windowId }); services.set(INativeHostService, nativeHostService); // Download @@ -270,12 +270,12 @@ class SharedProcessMain extends Disposable { // Localizations const localizationsService = accessor.get(ILocalizationsService); - const localizationsChannel = createChannelReceiver(localizationsService); + const localizationsChannel = ProxyChannel.fromService(localizationsService); this.server.registerChannel('localizations', localizationsChannel); // Diagnostics const diagnosticsService = accessor.get(IDiagnosticsService); - const diagnosticsChannel = createChannelReceiver(diagnosticsService); + const diagnosticsChannel = ProxyChannel.fromService(diagnosticsService); this.server.registerChannel('diagnostics', diagnosticsChannel); // Extension Tips diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index a35b3904442..ff58b3f5664 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -13,7 +13,7 @@ import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle import { resolveShellEnv } from 'vs/platform/environment/node/shellEnv'; import { IUpdateService } from 'vs/platform/update/common/update'; import { UpdateChannel } from 'vs/platform/update/electron-main/updateIpc'; -import { getDelayedChannel, StaticRouter, createChannelReceiver, createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { getDelayedChannel, StaticRouter, ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { Server as ElectronIPCServer } from 'vs/base/parts/ipc/electron-main/ipc.electron'; import { Server as NodeIPCServer } from 'vs/base/parts/ipc/node/ipc.net'; import { Client as MessagePortClient } from 'vs/base/parts/ipc/electron-main/ipc.mp'; @@ -525,7 +525,7 @@ export class CodeApplication extends Disposable { services.set(IWindowsMainService, new SyncDescriptor(WindowsMainService, [machineId, this.userEnv])); services.set(IDialogMainService, new SyncDescriptor(DialogMainService)); services.set(ILaunchMainService, new SyncDescriptor(LaunchMainService)); - services.set(IDiagnosticsService, createChannelSender(getDelayedChannel(sharedProcessReady.then(client => client.getChannel('diagnostics'))))); + services.set(IDiagnosticsService, ProxyChannel.toService(getDelayedChannel(sharedProcessReady.then(client => client.getChannel('diagnostics'))))); services.set(IIssueMainService, new SyncDescriptor(IssueMainService, [machineId, this.userEnv])); services.set(IEncryptionMainService, new SyncDescriptor(EncryptionMainService, [machineId])); @@ -606,7 +606,7 @@ export class CodeApplication extends Disposable { // Register more Main IPC services const launchMainService = accessor.get(ILaunchMainService); - const launchChannel = createChannelReceiver(launchMainService, { disableMarshalling: true }); + const launchChannel = ProxyChannel.fromService(launchMainService, { disableMarshalling: true }); this.mainIpcServer.registerChannel('launch', launchChannel); // Register more Electron IPC services @@ -615,44 +615,44 @@ export class CodeApplication extends Disposable { electronIpcServer.registerChannel('update', updateChannel); const issueMainService = accessor.get(IIssueMainService); - const issueChannel = createChannelReceiver(issueMainService); + const issueChannel = ProxyChannel.fromService(issueMainService); electronIpcServer.registerChannel('issue', issueChannel); const encryptionMainService = accessor.get(IEncryptionMainService); - const encryptionChannel = createChannelReceiver(encryptionMainService); + const encryptionChannel = ProxyChannel.fromService(encryptionMainService); electronIpcServer.registerChannel('encryption', encryptionChannel); const keyboardLayoutMainService = accessor.get(IKeyboardLayoutMainService); - const keyboardLayoutChannel = createChannelReceiver(keyboardLayoutMainService); + const keyboardLayoutChannel = ProxyChannel.fromService(keyboardLayoutMainService); electronIpcServer.registerChannel('keyboardLayout', keyboardLayoutChannel); const displayMainService = accessor.get(IDisplayMainService); - const displayChannel = createChannelReceiver(displayMainService); + const displayChannel = ProxyChannel.fromService(displayMainService); electronIpcServer.registerChannel('display', displayChannel); const nativeHostMainService = this.nativeHostMainService = accessor.get(INativeHostMainService); - const nativeHostChannel = createChannelReceiver(this.nativeHostMainService); + const nativeHostChannel = ProxyChannel.fromService(this.nativeHostMainService); electronIpcServer.registerChannel('nativeHost', nativeHostChannel); sharedProcessClient.then(client => client.registerChannel('nativeHost', nativeHostChannel)); const workspacesService = accessor.get(IWorkspacesService); - const workspacesChannel = createChannelReceiver(workspacesService); + const workspacesChannel = ProxyChannel.fromService(workspacesService); electronIpcServer.registerChannel('workspaces', workspacesChannel); const menubarMainService = accessor.get(IMenubarMainService); - const menubarChannel = createChannelReceiver(menubarMainService); + const menubarChannel = ProxyChannel.fromService(menubarMainService); electronIpcServer.registerChannel('menubar', menubarChannel); const urlService = accessor.get(IURLService); - const urlChannel = createChannelReceiver(urlService); + const urlChannel = ProxyChannel.fromService(urlService); electronIpcServer.registerChannel('url', urlChannel); const extensionUrlTrustService = accessor.get(IExtensionUrlTrustService); - const extensionUrlTrustChannel = createChannelReceiver(extensionUrlTrustService); + const extensionUrlTrustChannel = ProxyChannel.fromService(extensionUrlTrustService); electronIpcServer.registerChannel('extensionUrlTrust', extensionUrlTrustChannel); const webviewManagerService = accessor.get(IWebviewManagerService); - const webviewChannel = createChannelReceiver(webviewManagerService); + const webviewChannel = ProxyChannel.fromService(webviewManagerService); electronIpcServer.registerChannel('webview', webviewChannel); const storageMainService = accessor.get(IStorageMainService); diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 5194253b49a..f9de03dfc32 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -12,7 +12,7 @@ import product from 'vs/platform/product/common/product'; import { parseMainProcessArgv, addArg } from 'vs/platform/environment/node/argvHelper'; import { createWaitMarkerFile } from 'vs/platform/environment/node/waitMarkerFile'; import { LifecycleMainService, ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { Server as NodeIPCServer, serve as nodeIPCServe, connect as nodeIPCConnect, XDG_RUNTIME_DIR } from 'vs/base/parts/ipc/node/ipc.net'; import { Client as NodeIPCClient } from 'vs/base/parts/ipc/common/ipc.net'; import { ILaunchMainService } from 'vs/platform/launch/electron-main/launchMainService'; @@ -292,7 +292,7 @@ class CodeMain { }, 10000); } - const launchService = createChannelSender(client.getChannel('launch'), { disableMarshalling: true }); + const launchService = ProxyChannel.toService(client.getChannel('launch'), { disableMarshalling: true }); // Process Info if (args.status) { diff --git a/src/vs/platform/files/node/watcher/nsfw/watcherApp.ts b/src/vs/platform/files/node/watcher/nsfw/watcherApp.ts index d7fa2831572..0cc6da3b19f 100644 --- a/src/vs/platform/files/node/watcher/nsfw/watcherApp.ts +++ b/src/vs/platform/files/node/watcher/nsfw/watcherApp.ts @@ -5,8 +5,8 @@ import { Server } from 'vs/base/parts/ipc/node/ipc.cp'; import { NsfwWatcherService } from 'vs/platform/files/node/watcher/nsfw/nsfwWatcherService'; -import { createChannelReceiver } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; const server = new Server('watcher'); const service = new NsfwWatcherService(); -server.registerChannel('watcher', createChannelReceiver(service)); +server.registerChannel('watcher', ProxyChannel.fromService(service)); diff --git a/src/vs/platform/files/node/watcher/nsfw/watcherService.ts b/src/vs/platform/files/node/watcher/nsfw/watcherService.ts index 3b0cd433fce..32dead9e7fd 100644 --- a/src/vs/platform/files/node/watcher/nsfw/watcherService.ts +++ b/src/vs/platform/files/node/watcher/nsfw/watcherService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { createChannelSender, getNextTickChannel } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel, getNextTickChannel } from 'vs/base/parts/ipc/common/ipc'; import { Client } from 'vs/base/parts/ipc/node/ipc.cp'; import { IDiskFileChange, ILogMessage } from 'vs/platform/files/node/watcher/watcher'; import { Disposable } from 'vs/base/common/lifecycle'; @@ -61,7 +61,7 @@ export class FileWatcher extends Disposable { })); // Initialize watcher - this.service = createChannelSender(getNextTickChannel(client.getChannel('watcher'))); + this.service = ProxyChannel.toService(getNextTickChannel(client.getChannel('watcher'))); this.service.setVerboseLogging(this.verboseLogging); diff --git a/src/vs/platform/files/node/watcher/unix/watcherApp.ts b/src/vs/platform/files/node/watcher/unix/watcherApp.ts index 471e9c9af3e..d7ecdda29b4 100644 --- a/src/vs/platform/files/node/watcher/unix/watcherApp.ts +++ b/src/vs/platform/files/node/watcher/unix/watcherApp.ts @@ -5,8 +5,8 @@ import { Server } from 'vs/base/parts/ipc/node/ipc.cp'; import { ChokidarWatcherService } from 'vs/platform/files/node/watcher/unix/chokidarWatcherService'; -import { createChannelReceiver } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; const server = new Server('watcher'); const service = new ChokidarWatcherService(); -server.registerChannel('watcher', createChannelReceiver(service)); +server.registerChannel('watcher', ProxyChannel.fromService(service)); diff --git a/src/vs/platform/files/node/watcher/unix/watcherService.ts b/src/vs/platform/files/node/watcher/unix/watcherService.ts index 75f1bcf90b4..1ee26f965ee 100644 --- a/src/vs/platform/files/node/watcher/unix/watcherService.ts +++ b/src/vs/platform/files/node/watcher/unix/watcherService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { createChannelSender, getNextTickChannel } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel, getNextTickChannel } from 'vs/base/parts/ipc/common/ipc'; import { Client } from 'vs/base/parts/ipc/node/ipc.cp'; import { IDiskFileChange, ILogMessage } from 'vs/platform/files/node/watcher/watcher'; import { Disposable } from 'vs/base/common/lifecycle'; @@ -62,7 +62,7 @@ export class FileWatcher extends Disposable { })); // Initialize watcher - this.service = createChannelSender(getNextTickChannel(client.getChannel('watcher'))); + this.service = ProxyChannel.toService(getNextTickChannel(client.getChannel('watcher'))); this.service.init({ ...this.watcherOptions, verboseLogging: this.verboseLogging }); this._register(this.service.onDidChangeFile(e => !this.isDisposed && this.onDidFilesChange(e))); diff --git a/src/vs/platform/native/electron-sandbox/nativeHostService.ts b/src/vs/platform/native/electron-sandbox/nativeHostService.ts index 2175c479423..cc52246b294 100644 --- a/src/vs/platform/native/electron-sandbox/nativeHostService.ts +++ b/src/vs/platform/native/electron-sandbox/nativeHostService.ts @@ -5,7 +5,7 @@ import { INativeHostService } from 'vs/platform/native/electron-sandbox/native'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; // @ts-ignore: interface is implemented via proxy export class NativeHostService implements INativeHostService { @@ -16,7 +16,7 @@ export class NativeHostService implements INativeHostService { readonly windowId: number, @IMainProcessService mainProcessService: IMainProcessService ) { - return createChannelSender(mainProcessService.getChannel('nativeHost'), { + return ProxyChannel.toService(mainProcessService.getChannel('nativeHost'), { context: windowId, properties: (() => { const properties = new Map(); diff --git a/src/vs/workbench/contrib/codeEditor/electron-sandbox/displayChangeRemeasureFonts.ts b/src/vs/workbench/contrib/codeEditor/electron-sandbox/displayChangeRemeasureFonts.ts index efcdd8981df..8c4bd5e0a68 100644 --- a/src/vs/workbench/contrib/codeEditor/electron-sandbox/displayChangeRemeasureFonts.ts +++ b/src/vs/workbench/contrib/codeEditor/electron-sandbox/displayChangeRemeasureFonts.ts @@ -9,7 +9,7 @@ import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchCo import { Disposable } from 'vs/base/common/lifecycle'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; import { IDisplayMainService } from 'vs/platform/display/common/displayMainService'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { clearAllFontInfos } from 'vs/editor/browser/config/configuration'; class DisplayChangeRemeasureFonts extends Disposable implements IWorkbenchContribution { @@ -18,7 +18,7 @@ class DisplayChangeRemeasureFonts extends Disposable implements IWorkbenchContri @IMainProcessService mainProcessService: IMainProcessService ) { super(); - const displayMainService = createChannelSender(mainProcessService.getChannel('display')); + const displayMainService = ProxyChannel.toService(mainProcessService.getChannel('display')); displayMainService.onDidDisplayChanged(() => { clearAllFontInfos(); }); diff --git a/src/vs/workbench/contrib/webview/electron-browser/webviewIgnoreMenuShortcutsManager.ts b/src/vs/workbench/contrib/webview/electron-browser/webviewIgnoreMenuShortcutsManager.ts index 5b5e4dd75ac..e44124e7a22 100644 --- a/src/vs/workbench/contrib/webview/electron-browser/webviewIgnoreMenuShortcutsManager.ts +++ b/src/vs/workbench/contrib/webview/electron-browser/webviewIgnoreMenuShortcutsManager.ts @@ -7,7 +7,7 @@ import { WebviewTag } from 'electron'; import { addDisposableListener } from 'vs/base/browser/dom'; import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { isMacintosh } from 'vs/base/common/platform'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; import { IWebviewManagerService } from 'vs/platform/webview/common/webviewManagerService'; @@ -26,7 +26,7 @@ export class WebviewIgnoreMenuShortcutsManager { ) { this._isUsingNativeTitleBars = configurationService.getValue('window.titleBarStyle') === 'native'; - this.webviewMainService = createChannelSender(mainProcessService.getChannel('webview')); + this.webviewMainService = ProxyChannel.toService(mainProcessService.getChannel('webview')); } public add(webview: WebviewTag): IDisposable { diff --git a/src/vs/workbench/contrib/webview/electron-sandbox/resourceLoading.ts b/src/vs/workbench/contrib/webview/electron-sandbox/resourceLoading.ts index cae03c79bdb..1f46cf1bddb 100644 --- a/src/vs/workbench/contrib/webview/electron-sandbox/resourceLoading.ts +++ b/src/vs/workbench/contrib/webview/electron-sandbox/resourceLoading.ts @@ -9,7 +9,7 @@ import { CancellationToken } from 'vs/base/common/cancellation'; import { Disposable, toDisposable } from 'vs/base/common/lifecycle'; import { Schemas } from 'vs/base/common/network'; import { URI, UriComponents } from 'vs/base/common/uri'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { ipcRenderer } from 'vs/base/parts/sandbox/electron-sandbox/globals'; import * as modes from 'vs/editor/common/modes'; import { IFileService } from 'vs/platform/files/common/files'; @@ -71,7 +71,7 @@ export class WebviewResourceRequestManager extends Disposable { this._logService.debug(`WebviewResourceRequestManager(${this.id}): init`); - this._webviewManagerService = createChannelSender(mainProcessService.getChannel('webview')); + this._webviewManagerService = ProxyChannel.toService(mainProcessService.getChannel('webview')); this._localResourceRoots = initialContentOptions.localResourceRoots || []; this._portMappings = initialContentOptions.portMapping || []; diff --git a/src/vs/workbench/contrib/webview/electron-sandbox/windowIgnoreMenuShortcutsManager.ts b/src/vs/workbench/contrib/webview/electron-sandbox/windowIgnoreMenuShortcutsManager.ts index 00da271c3e8..7a4d3d20f51 100644 --- a/src/vs/workbench/contrib/webview/electron-sandbox/windowIgnoreMenuShortcutsManager.ts +++ b/src/vs/workbench/contrib/webview/electron-sandbox/windowIgnoreMenuShortcutsManager.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { isMacintosh } from 'vs/base/common/platform'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; import { INativeHostService } from 'vs/platform/native/electron-sandbox/native'; @@ -23,7 +23,7 @@ export class WindowIgnoreMenuShortcutsManager { ) { this._isUsingNativeTitleBars = configurationService.getValue('window.titleBarStyle') === 'native'; - this.webviewMainService = createChannelSender(mainProcessService.getChannel('webview')); + this.webviewMainService = ProxyChannel.toService(mainProcessService.getChannel('webview')); } public didFocus(): void { diff --git a/src/vs/workbench/services/diagnostics/electron-sandbox/diagnosticsService.ts b/src/vs/workbench/services/diagnostics/electron-sandbox/diagnosticsService.ts index 82d879f79df..75eae982425 100644 --- a/src/vs/workbench/services/diagnostics/electron-sandbox/diagnosticsService.ts +++ b/src/vs/workbench/services/diagnostics/electron-sandbox/diagnosticsService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { ISharedProcessService } from 'vs/platform/ipc/electron-sandbox/sharedProcessService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IDiagnosticsService } from 'vs/platform/diagnostics/common/diagnostics'; @@ -16,7 +16,7 @@ export class DiagnosticsService implements IDiagnosticsService { constructor( @ISharedProcessService sharedProcessService: ISharedProcessService ) { - return createChannelSender(sharedProcessService.getChannel('diagnostics')); + return ProxyChannel.toService(sharedProcessService.getChannel('diagnostics')); } } diff --git a/src/vs/workbench/services/encryption/electron-sandbox/encryptionService.ts b/src/vs/workbench/services/encryption/electron-sandbox/encryptionService.ts index 336eee9e9a1..198bf51ee01 100644 --- a/src/vs/workbench/services/encryption/electron-sandbox/encryptionService.ts +++ b/src/vs/workbench/services/encryption/electron-sandbox/encryptionService.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IEncryptionService } from 'vs/workbench/services/encryption/common/encryptionService'; @@ -13,7 +13,7 @@ export class EncryptionService { declare readonly _serviceBrand: undefined; constructor(@IMainProcessService mainProcessService: IMainProcessService) { - return createChannelSender(mainProcessService.getChannel('encryption')); + return ProxyChannel.toService(mainProcessService.getChannel('encryption')); } } diff --git a/src/vs/workbench/services/extensionManagement/electron-sandbox/extensionUrlTrustService.ts b/src/vs/workbench/services/extensionManagement/electron-sandbox/extensionUrlTrustService.ts index 3cabb495102..00610fa6eb5 100644 --- a/src/vs/workbench/services/extensionManagement/electron-sandbox/extensionUrlTrustService.ts +++ b/src/vs/workbench/services/extensionManagement/electron-sandbox/extensionUrlTrustService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { IExtensionUrlTrustService } from 'vs/platform/extensionManagement/common/extensionUrlTrust'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; @@ -13,7 +13,7 @@ class ExtensionUrlTrustService { declare readonly _serviceBrand: undefined; constructor(@IMainProcessService mainProcessService: IMainProcessService) { - return createChannelSender(mainProcessService.getChannel('extensionUrlTrust')); + return ProxyChannel.toService(mainProcessService.getChannel('extensionUrlTrust')); } } diff --git a/src/vs/workbench/services/issue/electron-sandbox/issueService.ts b/src/vs/workbench/services/issue/electron-sandbox/issueService.ts index ce1f795ccbc..de309efcbd1 100644 --- a/src/vs/workbench/services/issue/electron-sandbox/issueService.ts +++ b/src/vs/workbench/services/issue/electron-sandbox/issueService.ts @@ -5,7 +5,7 @@ import { IIssueService } from 'vs/platform/issue/electron-sandbox/issue'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; // @ts-ignore: interface is implemented via proxy @@ -14,7 +14,7 @@ export class IssueService implements IIssueService { declare readonly _serviceBrand: undefined; constructor(@IMainProcessService mainProcessService: IMainProcessService) { - return createChannelSender(mainProcessService.getChannel('issue')); + return ProxyChannel.toService(mainProcessService.getChannel('issue')); } } diff --git a/src/vs/workbench/services/keybinding/electron-sandbox/nativeKeyboardLayout.ts b/src/vs/workbench/services/keybinding/electron-sandbox/nativeKeyboardLayout.ts index 318e3910633..a20f74953ca 100644 --- a/src/vs/workbench/services/keybinding/electron-sandbox/nativeKeyboardLayout.ts +++ b/src/vs/workbench/services/keybinding/electron-sandbox/nativeKeyboardLayout.ts @@ -15,7 +15,7 @@ import { DispatchConfig } from 'vs/platform/keyboardLayout/common/dispatchConfig import { IKeyboardEvent } from 'vs/platform/keybinding/common/keybinding'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; import { IKeyboardLayoutMainService } from 'vs/platform/keyboardLayout/common/keyboardLayoutMainService'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; export class KeyboardLayoutService extends Disposable implements IKeyboardLayoutService { @@ -34,7 +34,7 @@ export class KeyboardLayoutService extends Disposable implements IKeyboardLayout @IMainProcessService mainProcessService: IMainProcessService ) { super(); - this._keyboardLayoutMainService = createChannelSender(mainProcessService.getChannel('keyboardLayout')); + this._keyboardLayoutMainService = ProxyChannel.toService(mainProcessService.getChannel('keyboardLayout')); this._initPromise = null; this._keyboardMapping = null; this._keyboardLayoutInfo = null; diff --git a/src/vs/workbench/services/localizations/electron-sandbox/localizationsService.ts b/src/vs/workbench/services/localizations/electron-sandbox/localizationsService.ts index 60d652092cc..7b980dd9b70 100644 --- a/src/vs/workbench/services/localizations/electron-sandbox/localizationsService.ts +++ b/src/vs/workbench/services/localizations/electron-sandbox/localizationsService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { ILocalizationsService } from 'vs/platform/localizations/common/localizations'; import { ISharedProcessService } from 'vs/platform/ipc/electron-sandbox/sharedProcessService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; @@ -16,7 +16,7 @@ export class LocalizationsService implements ILocalizationsService { constructor( @ISharedProcessService sharedProcessService: ISharedProcessService, ) { - return createChannelSender(sharedProcessService.getChannel('localizations')); + return ProxyChannel.toService(sharedProcessService.getChannel('localizations')); } } diff --git a/src/vs/workbench/services/menubar/electron-sandbox/menubarService.ts b/src/vs/workbench/services/menubar/electron-sandbox/menubarService.ts index c1356a21011..55d28ef7062 100644 --- a/src/vs/workbench/services/menubar/electron-sandbox/menubarService.ts +++ b/src/vs/workbench/services/menubar/electron-sandbox/menubarService.ts @@ -5,7 +5,7 @@ import { IMenubarService } from 'vs/platform/menubar/electron-sandbox/menubar'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; // @ts-ignore: interface is implemented via proxy @@ -14,7 +14,7 @@ export class MenubarService implements IMenubarService { declare readonly _serviceBrand: undefined; constructor(@IMainProcessService mainProcessService: IMainProcessService) { - return createChannelSender(mainProcessService.getChannel('menubar')); + return ProxyChannel.toService(mainProcessService.getChannel('menubar')); } } diff --git a/src/vs/workbench/services/url/electron-sandbox/urlService.ts b/src/vs/workbench/services/url/electron-sandbox/urlService.ts index 90f842f7d47..6e6b0e1a030 100644 --- a/src/vs/workbench/services/url/electron-sandbox/urlService.ts +++ b/src/vs/workbench/services/url/electron-sandbox/urlService.ts @@ -10,7 +10,7 @@ import { URLHandlerChannel } from 'vs/platform/url/common/urlIpc'; import { IOpenerService, IOpener, matchesScheme } from 'vs/platform/opener/common/opener'; import { IProductService } from 'vs/platform/product/common/productService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { INativeHostService } from 'vs/platform/native/electron-sandbox/native'; import { NativeURLService } from 'vs/platform/url/common/urlService'; @@ -31,7 +31,7 @@ export class RelayURLService extends NativeURLService implements IURLHandler, IO ) { super(); - this.urlService = createChannelSender(mainProcessService.getChannel('url')); + this.urlService = ProxyChannel.toService(mainProcessService.getChannel('url')); mainProcessService.registerChannel('urlHandler', new URLHandlerChannel(this)); openerService.registerOpener(this); diff --git a/src/vs/workbench/services/workspaces/electron-sandbox/workspacesService.ts b/src/vs/workbench/services/workspaces/electron-sandbox/workspacesService.ts index f3dd9b34f70..7ae6139c8f8 100644 --- a/src/vs/workbench/services/workspaces/electron-sandbox/workspacesService.ts +++ b/src/vs/workbench/services/workspaces/electron-sandbox/workspacesService.ts @@ -6,7 +6,7 @@ import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; -import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ProxyChannel } from 'vs/base/parts/ipc/common/ipc'; import { INativeHostService } from 'vs/platform/native/electron-sandbox/native'; // @ts-ignore: interface is implemented via proxy @@ -18,7 +18,7 @@ export class NativeWorkspacesService implements IWorkspacesService { @IMainProcessService mainProcessService: IMainProcessService, @INativeHostService nativeHostService: INativeHostService ) { - return createChannelSender(mainProcessService.getChannel('workspaces'), { context: nativeHostService.windowId }); + return ProxyChannel.toService(mainProcessService.getChannel('workspaces'), { context: nativeHostService.windowId }); } }