提交 fe948046 编写于 作者: B Benjamin Pasero

bootstrap - use preload script to access Electron IPC

上级 c7fe3b41
......@@ -22,7 +22,6 @@
}
}(this, function () {
const path = require.__$__nodeRequire('path');
const ipc = require.__$__nodeRequire('electron').ipcRenderer;
const bootstrap = globalThis.MonacoBootstrap;
/**
......@@ -151,6 +150,8 @@
* @returns {() => void}
*/
function registerDeveloperKeybindings(disallowReloadKeybinding) {
const ipcRenderer = globals().ipcRenderer;
const extractKey = function (e) {
return [
e.ctrlKey ? 'ctrl-' : '',
......@@ -169,9 +170,9 @@
let listener = function (e) {
const key = extractKey(e);
if (key === TOGGLE_DEV_TOOLS_KB || key === TOGGLE_DEV_TOOLS_KB_ALT) {
ipc.send('vscode:toggleDevTools');
ipcRenderer.send('vscode:toggleDevTools');
} else if (key === RELOAD_KB && !disallowReloadKeybinding) {
ipc.send('vscode:reloadWindow');
ipcRenderer.send('vscode:reloadWindow');
}
};
......@@ -191,7 +192,8 @@
*/
function onUnexpectedError(error, enableDeveloperTools) {
if (enableDeveloperTools) {
ipc.send('vscode:openDevTools');
const ipcRenderer = globals().ipcRenderer;
ipcRenderer.send('vscode:openDevTools');
}
console.error(`[uncaught exception]: ${error}`);
......@@ -201,7 +203,16 @@
}
}
/**
* @return {typeof import('./vs/base/parts/sandbox/electron-sandbox/globals')}
*/
function globals() {
// @ts-ignore (defined in globals.js)
return window.vscode;
}
return {
load
load,
globals
};
}));
......@@ -33,17 +33,20 @@ const perf = (function () {
perf.mark('renderer/started');
// Setup shell environment
process['lazyEnv'] = getLazyEnv();
/**
* @type {{ load: (modules: string[], resultCallback: (result, configuration: object) => any, options: object) => unknown }}
* @type {{
* load: (modules: string[], resultCallback: (result, configuration: object) => any, options: object) => unknown,
* globals: () => typeof import('../../../base/parts/sandbox/electron-sandbox/globals')
* }}
*/
const bootstrapWindow = (() => {
// @ts-ignore (defined in bootstrap-window.js)
return window.MonacoBootstrapWindow;
})();
// Setup shell environment
process['lazyEnv'] = getLazyEnv();
// Load workbench main JS, CSS and NLS all in parallel. This is an
// optimization to prevent a waterfall of loading to happen, because
// we know for a fact that workbench.desktop.main will depend on
......@@ -184,8 +187,7 @@ function showPartsSplash(configuration) {
* @returns {Promise<void>}
*/
function getLazyEnv() {
const ipc = require.__$__nodeRequire('electron').ipcRenderer;
const ipcRenderer = bootstrapWindow.globals().ipcRenderer;
return new Promise(function (resolve) {
const handle = setTimeout(function () {
......@@ -193,13 +195,13 @@ function getLazyEnv() {
console.warn('renderer did not receive lazyEnv in time');
}, 10000);
ipc.once('vscode:acceptShellEnv', function (event, shellEnv) {
ipcRenderer.once('vscode:acceptShellEnv', function (event, shellEnv) {
clearTimeout(handle);
Object.assign(process.env, shellEnv);
// @ts-ignore
resolve(process.env);
});
ipc.send('vscode:fetchShellEnv');
ipcRenderer.send('vscode:fetchShellEnv');
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册