Path: blob/main/src/vs/base/parts/ipc/common/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 { IMessagePassingProtocol } from './ipc.js';89export interface Sender {10send(channel: string, msg: unknown): void;11}1213/**14* The Electron `Protocol` leverages Electron style IPC communication (`ipcRenderer`, `ipcMain`)15* for the implementation of the `IMessagePassingProtocol`. That style of API requires a channel16* name for sending data.17*/18export class Protocol implements IMessagePassingProtocol {1920constructor(private sender: Sender, readonly onMessage: Event<VSBuffer>) { }2122send(message: VSBuffer): void {23try {24this.sender.send('vscode:message', message.buffer);25} catch (e) {26// systems are going down27}28}2930disconnect(): void {31this.sender.send('vscode:disconnect', null);32}33}343536