UNPKG

sussudio

Version:

An unofficial VS Code Internal API

30 lines (29 loc) 1.32 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { VSBuffer } from "../../../common/buffer.mjs"; import { Event } from "../../../common/event.mjs"; import { IPCClient } from "../common/ipc.mjs"; import { Protocol as ElectronProtocol } from "../common/ipc.electron.mjs"; import { ipcRenderer } from "../../sandbox/electron-sandbox/globals.mjs"; /** * An implementation of `IPCClient` on top of Electron `ipcRenderer` IPC communication * provided from sandbox globals (via preload script). */ export class Client extends IPCClient { protocol; static createProtocol() { const onMessage = Event.fromNodeEventEmitter(ipcRenderer, 'vscode:message', (_, message) => VSBuffer.wrap(message)); ipcRenderer.send('vscode:hello'); return new ElectronProtocol(ipcRenderer, onMessage); } constructor(id) { const protocol = Client.createProtocol(); super(protocol, id); this.protocol = protocol; } dispose() { this.protocol.disconnect(); } }