Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/parts/ipc/common/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 { IMessagePassingProtocol } from './ipc.js';
9
10
export interface Sender {
11
send(channel: string, msg: unknown): void;
12
}
13
14
/**
15
* The Electron `Protocol` leverages Electron style IPC communication (`ipcRenderer`, `ipcMain`)
16
* for the implementation of the `IMessagePassingProtocol`. That style of API requires a channel
17
* name for sending data.
18
*/
19
export class Protocol implements IMessagePassingProtocol {
20
21
constructor(private sender: Sender, readonly onMessage: Event<VSBuffer>) { }
22
23
send(message: VSBuffer): void {
24
try {
25
this.sender.send('vscode:message', message.buffer);
26
} catch (e) {
27
// systems are going down
28
}
29
}
30
31
disconnect(): void {
32
this.sender.send('vscode:disconnect', null);
33
}
34
}
35
36