vscode/test/unit/electron/preload.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.0 KiB
JavaScript
Raw Normal View History

2024-11-15 06:29:18 +00:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// @ts-check
(function () {
'use strict';
const { ipcRenderer, webFrame, contextBridge, webUtils } = require('electron');
const globals = {
ipcRenderer: {
send(channel, ...args) {
ipcRenderer.send(channel, ...args);
},
invoke(channel, ...args) {
return ipcRenderer.invoke(channel, ...args);
},
on(channel, listener) {
ipcRenderer.on(channel, listener);
return this;
},
once(channel, listener) {
ipcRenderer.once(channel, listener);
return this;
},
removeListener(channel, listener) {
ipcRenderer.removeListener(channel, listener);
return this;
}
},
webFrame: {
setZoomLevel(level) {
if (typeof level === 'number') {
webFrame.setZoomLevel(level);
}
}
},
webUtils: {
getPathForFile(file) {
return webUtils.getPathForFile(file);
}
},
process: {
get platform() { return process.platform; },
get arch() { return process.arch; },
get env() { return { ...process.env }; },
get versions() { return process.versions; },
get type() { return 'renderer'; },
get execPath() { return process.execPath; },
cwd() {
return process.env['VSCODE_CWD'] || process.execPath.substr(0, process.execPath.lastIndexOf(process.platform === 'win32' ? '\\' : '/'));
},
getProcessMemoryInfo() {
return process.getProcessMemoryInfo();
},
on(type, callback) {
// @ts-ignore
process.on(type, callback);
}
},
};
if (process.contextIsolated) {
try {
contextBridge.exposeInMainWorld('vscode', globals);
} catch (error) {
console.error(error);
}
} else {
// @ts-ignore
window.vscode = globals;
}
}());