Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/parts/sandbox/electron-browser/preload-aux.ts
3296 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
(function () {
7
8
const { ipcRenderer, webFrame, contextBridge } = require('electron');
9
10
function validateIPC(channel: string): true | never {
11
if (!channel || !channel.startsWith('vscode:')) {
12
throw new Error(`Unsupported event IPC channel '${channel}'`);
13
}
14
15
return true;
16
}
17
18
const globals = {
19
20
/**
21
* A minimal set of methods exposed from Electron's `ipcRenderer`
22
* to support communication to main process.
23
*/
24
ipcRenderer: {
25
26
send(channel: string, ...args: any[]): void {
27
if (validateIPC(channel)) {
28
ipcRenderer.send(channel, ...args);
29
}
30
},
31
32
invoke(channel: string, ...args: any[]): Promise<any> {
33
validateIPC(channel);
34
35
return ipcRenderer.invoke(channel, ...args);
36
}
37
},
38
39
/**
40
* Support for subset of methods of Electron's `webFrame` type.
41
*/
42
webFrame: {
43
44
setZoomLevel(level: number): void {
45
if (typeof level === 'number') {
46
webFrame.setZoomLevel(level);
47
}
48
}
49
}
50
};
51
52
try {
53
contextBridge.exposeInMainWorld('vscode', globals);
54
} catch (error) {
55
console.error(error);
56
}
57
}());
58
59