Path: blob/main/src/vs/base/parts/sandbox/electron-browser/preload-aux.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45(function () {67const { ipcRenderer, webFrame, contextBridge } = require('electron');89function validateIPC(channel: string): true | never {10if (!channel || !channel.startsWith('vscode:')) {11throw new Error(`Unsupported event IPC channel '${channel}'`);12}1314return true;15}1617const globals = {1819/**20* A minimal set of methods exposed from Electron's `ipcRenderer`21* to support communication to main process.22*/23ipcRenderer: {2425send(channel: string, ...args: any[]): void {26if (validateIPC(channel)) {27ipcRenderer.send(channel, ...args);28}29},3031invoke(channel: string, ...args: any[]): Promise<any> {32validateIPC(channel);3334return ipcRenderer.invoke(channel, ...args);35}36},3738/**39* Support for subset of methods of Electron's `webFrame` type.40*/41webFrame: {4243setZoomLevel(level: number): void {44if (typeof level === 'number') {45webFrame.setZoomLevel(level);46}47}48}49};5051try {52contextBridge.exposeInMainWorld('vscode', globals);53} catch (error) {54console.error(error);55}56}());575859