Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/unit/electron/preload.js
3520 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
// @ts-check
7
(function () {
8
'use strict';
9
10
const { ipcRenderer, webFrame, contextBridge, webUtils } = require('electron');
11
12
const globals = {
13
14
ipcRenderer: {
15
16
send(channel, ...args) {
17
ipcRenderer.send(channel, ...args);
18
},
19
20
invoke(channel, ...args) {
21
return ipcRenderer.invoke(channel, ...args);
22
},
23
24
on(channel, listener) {
25
ipcRenderer.on(channel, listener);
26
27
return this;
28
},
29
30
once(channel, listener) {
31
ipcRenderer.once(channel, listener);
32
33
return this;
34
},
35
36
removeListener(channel, listener) {
37
ipcRenderer.removeListener(channel, listener);
38
39
return this;
40
}
41
},
42
43
webFrame: {
44
45
setZoomLevel(level) {
46
if (typeof level === 'number') {
47
webFrame.setZoomLevel(level);
48
}
49
}
50
},
51
52
webUtils: {
53
54
getPathForFile(file) {
55
return webUtils.getPathForFile(file);
56
}
57
},
58
59
process: {
60
get platform() { return process.platform; },
61
get arch() { return process.arch; },
62
get env() { return { ...process.env }; },
63
get versions() { return process.versions; },
64
get type() { return 'renderer'; },
65
get execPath() { return process.execPath; },
66
67
cwd() {
68
return process.env['VSCODE_CWD'] || process.execPath.substr(0, process.execPath.lastIndexOf(process.platform === 'win32' ? '\\' : '/'));
69
},
70
71
getProcessMemoryInfo() {
72
return process.getProcessMemoryInfo();
73
},
74
75
on(type, callback) {
76
// @ts-ignore
77
process.on(type, callback);
78
}
79
},
80
};
81
82
if (process.contextIsolated) {
83
try {
84
contextBridge.exposeInMainWorld('vscode', globals);
85
} catch (error) {
86
console.error(error);
87
}
88
} else {
89
// @ts-ignore
90
window.vscode = globals;
91
}
92
}());
93
94