Path: blob/main/src/vs/base/parts/ipc/electron-browser/ipc.electron.ts
4780 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { VSBuffer } from '../../../common/buffer.js';6import { Event } from '../../../common/event.js';7import { IDisposable } from '../../../common/lifecycle.js';8import { IPCClient } from '../common/ipc.js';9import { Protocol as ElectronProtocol } from '../common/ipc.electron.js';10import { ipcRenderer } from '../../sandbox/electron-browser/globals.js';1112/**13* An implementation of `IPCClient` on top of Electron `ipcRenderer` IPC communication14* provided from sandbox globals (via preload script).15*/16export class Client extends IPCClient implements IDisposable {1718private protocol: ElectronProtocol;1920private static createProtocol(): ElectronProtocol {21const onMessage = Event.fromNodeEventEmitter<VSBuffer>(ipcRenderer, 'vscode:message', (_, message) => VSBuffer.wrap(message));22ipcRenderer.send('vscode:hello');2324return new ElectronProtocol(ipcRenderer, onMessage);25}2627constructor(id: string) {28const protocol = Client.createProtocol();29super(protocol, id);3031this.protocol = protocol;32}3334override dispose(): void {35this.protocol.disconnect();36super.dispose();37}38}394041