Skip to content

Commit a2352c8

Browse files
author
Benjamin Pasero
committed
debt - adopt ipc proxy for launch service
1 parent 0f6305f commit a2352c8

3 files changed

Lines changed: 11 additions & 71 deletions

File tree

src/vs/code/electron-main/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Server as ElectronIPCServer } from 'vs/base/parts/ipc/electron-main/ipc
1616
import { Client } from 'vs/base/parts/ipc/common/ipc.net';
1717
import { Server, connect } from 'vs/base/parts/ipc/node/ipc.net';
1818
import { SharedProcess } from 'vs/code/electron-main/sharedProcess';
19-
import { LaunchMainService, LaunchChannel, ILaunchMainService } from 'vs/platform/launch/electron-main/launchMainService';
19+
import { LaunchMainService, ILaunchMainService } from 'vs/platform/launch/electron-main/launchMainService';
2020
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
2121
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
2222
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
@@ -530,7 +530,7 @@ export class CodeApplication extends Disposable {
530530

531531
// Register more Main IPC services
532532
const launchMainService = accessor.get(ILaunchMainService);
533-
const launchChannel = new LaunchChannel(launchMainService);
533+
const launchChannel = createChannelReceiver(launchMainService, { disableMarshalling: true });
534534
this.mainIpcServer.registerChannel('launch', launchChannel);
535535

536536
// Register more Electron IPC services

src/vs/code/electron-main/main.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { mkdirp } from 'vs/base/node/pfs';
1414
import { validatePaths } from 'vs/code/node/paths';
1515
import { LifecycleMainService, ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
1616
import { Server, serve, connect } from 'vs/base/parts/ipc/node/ipc.net';
17-
import { LaunchChannelClient } from 'vs/platform/launch/electron-main/launchMainService';
17+
import { createChannelSender } from 'vs/base/parts/ipc/common/ipc';
18+
import { ILaunchMainService } from 'vs/platform/launch/electron-main/launchMainService';
1819
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1920
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
2021
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
@@ -270,8 +271,7 @@ class CodeMain {
270271
}, 10000);
271272
}
272273

273-
const channel = client.getChannel('launch');
274-
const launchClient = new LaunchChannelClient(channel);
274+
const launchService = createChannelSender<ILaunchMainService>(client.getChannel('launch'), { disableMarshalling: true });
275275

276276
// Process Info
277277
if (environmentService.args.status) {
@@ -280,8 +280,8 @@ class CodeMain {
280280
const sharedProcessClient = await connect(environmentService.sharedIPCHandle, 'main');
281281
const diagnosticsChannel = sharedProcessClient.getChannel('diagnostics');
282282
const diagnosticsService = new DiagnosticsService(diagnosticsChannel);
283-
const mainProcessInfo = await launchClient.getMainProcessInfo();
284-
const remoteDiagnostics = await launchClient.getRemoteDiagnostics({ includeProcesses: true, includeWorkspaceMetadata: true });
283+
const mainProcessInfo = await launchService.getMainProcessInfo();
284+
const remoteDiagnostics = await launchService.getRemoteDiagnostics({ includeProcesses: true, includeWorkspaceMetadata: true });
285285
const diagnostics = await diagnosticsService.getDiagnostics(mainProcessInfo, remoteDiagnostics);
286286
console.log(diagnostics);
287287

@@ -291,12 +291,12 @@ class CodeMain {
291291

292292
// Windows: allow to set foreground
293293
if (platform.isWindows) {
294-
await this.windowsAllowSetForegroundWindow(launchClient, logService);
294+
await this.windowsAllowSetForegroundWindow(launchService, logService);
295295
}
296296

297297
// Send environment over...
298298
logService.trace('Sending env to running instance...');
299-
await launchClient.start(environmentService.args, process.env as platform.IProcessEnvironment);
299+
await launchService.start(environmentService.args, process.env as platform.IProcessEnvironment);
300300

301301
// Cleanup
302302
await client.dispose();
@@ -358,9 +358,9 @@ class CodeMain {
358358
});
359359
}
360360

361-
private async windowsAllowSetForegroundWindow(client: LaunchChannelClient, logService: ILogService): Promise<void> {
361+
private async windowsAllowSetForegroundWindow(launchService: ILaunchMainService, logService: ILogService): Promise<void> {
362362
if (platform.isWindows) {
363-
const processId = await client.getMainProcessId();
363+
const processId = await launchService.getMainProcessId();
364364

365365
logService.trace('Sending some foreground love to the running instance:', processId);
366366

src/vs/platform/launch/electron-main/launchMainService.ts

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
76
import { ILogService } from 'vs/platform/log/common/log';
87
import { IURLService } from 'vs/platform/url/common/url';
98
import { IProcessEnvironment, isMacintosh } from 'vs/base/common/platform';
@@ -16,7 +15,6 @@ import { IWorkspacesMainService } from 'vs/platform/workspaces/electron-main/wor
1615
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1716
import { URI } from 'vs/base/common/uri';
1817
import { BrowserWindow, ipcMain, Event as IpcEvent, app } from 'electron';
19-
import { Event } from 'vs/base/common/event';
2018
import { coalesce } from 'vs/base/common/arrays';
2119
import { IDiagnosticInfoOptions, IDiagnosticInfo, IRemoteDiagnosticInfo, IRemoteDiagnosticError } from 'vs/platform/diagnostics/common/diagnostics';
2220
import { IMainProcessInfo, IWindowInfo } from 'vs/platform/launch/common/launch';
@@ -60,64 +58,6 @@ export interface ILaunchMainService {
6058
getRemoteDiagnostics(options: IRemoteDiagnosticOptions): Promise<(IRemoteDiagnosticInfo | IRemoteDiagnosticError)[]>;
6159
}
6260

63-
export class LaunchChannel implements IServerChannel {
64-
65-
constructor(private service: ILaunchMainService) { }
66-
67-
listen<T>(_: unknown, event: string): Event<T> {
68-
throw new Error(`Event not found: ${event}`);
69-
}
70-
71-
call(_: unknown, command: string, arg: any): Promise<any> {
72-
switch (command) {
73-
case 'start':
74-
const { args, userEnv } = arg as IStartArguments;
75-
return this.service.start(args, userEnv);
76-
77-
case 'get-main-process-id':
78-
return this.service.getMainProcessId();
79-
80-
case 'get-main-process-info':
81-
return this.service.getMainProcessInfo();
82-
83-
case 'get-logs-path':
84-
return this.service.getLogsPath();
85-
86-
case 'get-remote-diagnostics':
87-
return this.service.getRemoteDiagnostics(arg);
88-
}
89-
90-
throw new Error(`Call not found: ${command}`);
91-
}
92-
}
93-
94-
export class LaunchChannelClient implements ILaunchMainService {
95-
96-
_serviceBrand: undefined;
97-
98-
constructor(private channel: IChannel) { }
99-
100-
start(args: ParsedArgs, userEnv: IProcessEnvironment): Promise<void> {
101-
return this.channel.call('start', { args, userEnv });
102-
}
103-
104-
getMainProcessId(): Promise<number> {
105-
return this.channel.call('get-main-process-id', null);
106-
}
107-
108-
getMainProcessInfo(): Promise<IMainProcessInfo> {
109-
return this.channel.call('get-main-process-info', null);
110-
}
111-
112-
getLogsPath(): Promise<string> {
113-
return this.channel.call('get-logs-path', null);
114-
}
115-
116-
getRemoteDiagnostics(options: IRemoteDiagnosticOptions): Promise<IRemoteDiagnosticInfo[]> {
117-
return this.channel.call('get-remote-diagnostics', options);
118-
}
119-
}
120-
12161
export class LaunchMainService implements ILaunchMainService {
12262

12363
_serviceBrand: undefined;

0 commit comments

Comments
 (0)