diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index a9e4a22f7c7..4e1a41fadff 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -16,7 +16,7 @@ import { Server as ElectronIPCServer } from 'vs/base/parts/ipc/electron-main/ipc import { Client } from 'vs/base/parts/ipc/common/ipc.net'; import { Server, connect } from 'vs/base/parts/ipc/node/ipc.net'; import { SharedProcess } from 'vs/code/electron-main/sharedProcess'; -import { LaunchMainService, LaunchChannel, ILaunchMainService } from 'vs/platform/launch/electron-main/launchMainService'; +import { LaunchMainService, ILaunchMainService } from 'vs/platform/launch/electron-main/launchMainService'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; @@ -530,7 +530,7 @@ export class CodeApplication extends Disposable { // Register more Main IPC services const launchMainService = accessor.get(ILaunchMainService); - const launchChannel = new LaunchChannel(launchMainService); + const launchChannel = createChannelReceiver(launchMainService, { disableMarshalling: true }); this.mainIpcServer.registerChannel('launch', launchChannel); // Register more Electron IPC services diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 7702f0f7273..ce30aa5f109 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -14,7 +14,8 @@ import { mkdirp } from 'vs/base/node/pfs'; import { validatePaths } from 'vs/code/node/paths'; import { LifecycleMainService, ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService'; import { Server, serve, connect } from 'vs/base/parts/ipc/node/ipc.net'; -import { LaunchChannelClient } from 'vs/platform/launch/electron-main/launchMainService'; +import { createChannelSender } from 'vs/base/parts/ipc/common/ipc'; +import { ILaunchMainService } from 'vs/platform/launch/electron-main/launchMainService'; import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; @@ -270,8 +271,7 @@ class CodeMain { }, 10000); } - const channel = client.getChannel('launch'); - const launchClient = new LaunchChannelClient(channel); + const launchService = createChannelSender(client.getChannel('launch'), { disableMarshalling: true }); // Process Info if (environmentService.args.status) { @@ -280,8 +280,8 @@ class CodeMain { const sharedProcessClient = await connect(environmentService.sharedIPCHandle, 'main'); const diagnosticsChannel = sharedProcessClient.getChannel('diagnostics'); const diagnosticsService = new DiagnosticsService(diagnosticsChannel); - const mainProcessInfo = await launchClient.getMainProcessInfo(); - const remoteDiagnostics = await launchClient.getRemoteDiagnostics({ includeProcesses: true, includeWorkspaceMetadata: true }); + const mainProcessInfo = await launchService.getMainProcessInfo(); + const remoteDiagnostics = await launchService.getRemoteDiagnostics({ includeProcesses: true, includeWorkspaceMetadata: true }); const diagnostics = await diagnosticsService.getDiagnostics(mainProcessInfo, remoteDiagnostics); console.log(diagnostics); @@ -291,12 +291,12 @@ class CodeMain { // Windows: allow to set foreground if (platform.isWindows) { - await this.windowsAllowSetForegroundWindow(launchClient, logService); + await this.windowsAllowSetForegroundWindow(launchService, logService); } // Send environment over... logService.trace('Sending env to running instance...'); - await launchClient.start(environmentService.args, process.env as platform.IProcessEnvironment); + await launchService.start(environmentService.args, process.env as platform.IProcessEnvironment); // Cleanup await client.dispose(); @@ -358,9 +358,9 @@ class CodeMain { }); } - private async windowsAllowSetForegroundWindow(client: LaunchChannelClient, logService: ILogService): Promise { + private async windowsAllowSetForegroundWindow(launchService: ILaunchMainService, logService: ILogService): Promise { if (platform.isWindows) { - const processId = await client.getMainProcessId(); + const processId = await launchService.getMainProcessId(); logService.trace('Sending some foreground love to the running instance:', processId); diff --git a/src/vs/platform/launch/electron-main/launchMainService.ts b/src/vs/platform/launch/electron-main/launchMainService.ts index b6f7fbbc094..c127f8da240 100644 --- a/src/vs/platform/launch/electron-main/launchMainService.ts +++ b/src/vs/platform/launch/electron-main/launchMainService.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc'; import { ILogService } from 'vs/platform/log/common/log'; import { IURLService } from 'vs/platform/url/common/url'; import { IProcessEnvironment, isMacintosh } from 'vs/base/common/platform'; @@ -16,7 +15,6 @@ import { IWorkspacesMainService } from 'vs/platform/workspaces/electron-main/wor import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { URI } from 'vs/base/common/uri'; import { BrowserWindow, ipcMain, Event as IpcEvent, app } from 'electron'; -import { Event } from 'vs/base/common/event'; import { coalesce } from 'vs/base/common/arrays'; import { IDiagnosticInfoOptions, IDiagnosticInfo, IRemoteDiagnosticInfo, IRemoteDiagnosticError } from 'vs/platform/diagnostics/common/diagnostics'; import { IMainProcessInfo, IWindowInfo } from 'vs/platform/launch/common/launch'; @@ -60,64 +58,6 @@ export interface ILaunchMainService { getRemoteDiagnostics(options: IRemoteDiagnosticOptions): Promise<(IRemoteDiagnosticInfo | IRemoteDiagnosticError)[]>; } -export class LaunchChannel implements IServerChannel { - - constructor(private service: ILaunchMainService) { } - - listen(_: unknown, event: string): Event { - throw new Error(`Event not found: ${event}`); - } - - call(_: unknown, command: string, arg: any): Promise { - switch (command) { - case 'start': - const { args, userEnv } = arg as IStartArguments; - return this.service.start(args, userEnv); - - case 'get-main-process-id': - return this.service.getMainProcessId(); - - case 'get-main-process-info': - return this.service.getMainProcessInfo(); - - case 'get-logs-path': - return this.service.getLogsPath(); - - case 'get-remote-diagnostics': - return this.service.getRemoteDiagnostics(arg); - } - - throw new Error(`Call not found: ${command}`); - } -} - -export class LaunchChannelClient implements ILaunchMainService { - - _serviceBrand: undefined; - - constructor(private channel: IChannel) { } - - start(args: ParsedArgs, userEnv: IProcessEnvironment): Promise { - return this.channel.call('start', { args, userEnv }); - } - - getMainProcessId(): Promise { - return this.channel.call('get-main-process-id', null); - } - - getMainProcessInfo(): Promise { - return this.channel.call('get-main-process-info', null); - } - - getLogsPath(): Promise { - return this.channel.call('get-logs-path', null); - } - - getRemoteDiagnostics(options: IRemoteDiagnosticOptions): Promise { - return this.channel.call('get-remote-diagnostics', options); - } -} - export class LaunchMainService implements ILaunchMainService { _serviceBrand: undefined;