Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/parts/ipc/electron-browser/ipc.electron.ts
4780 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { VSBuffer } from '../../../common/buffer.js';
7
import { Event } from '../../../common/event.js';
8
import { IDisposable } from '../../../common/lifecycle.js';
9
import { IPCClient } from '../common/ipc.js';
10
import { Protocol as ElectronProtocol } from '../common/ipc.electron.js';
11
import { ipcRenderer } from '../../sandbox/electron-browser/globals.js';
12
13
/**
14
* An implementation of `IPCClient` on top of Electron `ipcRenderer` IPC communication
15
* provided from sandbox globals (via preload script).
16
*/
17
export class Client extends IPCClient implements IDisposable {
18
19
private protocol: ElectronProtocol;
20
21
private static createProtocol(): ElectronProtocol {
22
const onMessage = Event.fromNodeEventEmitter<VSBuffer>(ipcRenderer, 'vscode:message', (_, message) => VSBuffer.wrap(message));
23
ipcRenderer.send('vscode:hello');
24
25
return new ElectronProtocol(ipcRenderer, onMessage);
26
}
27
28
constructor(id: string) {
29
const protocol = Client.createProtocol();
30
super(protocol, id);
31
32
this.protocol = protocol;
33
}
34
35
override dispose(): void {
36
this.protocol.disconnect();
37
super.dispose();
38
}
39
}
40
41