diff --git a/src/bootstrap-window.js b/src/bootstrap-window.js index e62c0a611ef..a08e7b668ff 100644 --- a/src/bootstrap-window.js +++ b/src/bootstrap-window.js @@ -43,16 +43,18 @@ * }} [options] */ async function load(modulePaths, resultCallback, options) { - performance.mark('code/willWaitForWindowConfig'); - /** @type {import('./vs/base/parts/sandbox/common/sandboxTypes').ISandboxConfiguration} */ - const configuration = await preloadGlobals.context.configuration; - performance.mark('code/didWaitForWindowConfig'); // Error handler safeProcess.on('uncaughtException', function (/** @type {string | Error} */ error) { onUnexpectedError(error, enableDeveloperKeybindings); }); + // Await window configuration from preload + performance.mark('code/willWaitForWindowConfig'); + /** @type {import('./vs/base/parts/sandbox/common/sandboxTypes').ISandboxConfiguration} */ + const configuration = await preloadGlobals.context.configuration; + performance.mark('code/didWaitForWindowConfig'); + // Developer tools const enableDeveloperKeybindings = safeProcess.env['VSCODE_DEV'] || configuration.forceEnableDeveloperKeybindings || options?.forceEnableDeveloperKeybindings; let developerDeveloperKeybindingsDisposable; @@ -63,6 +65,7 @@ // Enable ASAR support globalThis.MonacoBootstrap.enableASARSupport(configuration.appRoot); + // Signal DOM modifications are now OK if (typeof options?.canModifyDOM === 'function') { options.canModifyDOM(configuration); } @@ -79,24 +82,22 @@ window.document.documentElement.setAttribute('lang', locale); - // do not advertise AMD to avoid confusing UMD modules loaded with nodejs + // Do not advertise AMD to avoid confusing UMD modules loaded with nodejs if (!useCustomProtocol) { window['define'] = undefined; } - // replace the patched electron fs with the original node fs for all AMD code (TODO@sandbox non-sandboxed only) + // Replace the patched electron fs with the original node fs for all AMD code (TODO@sandbox non-sandboxed only) if (!safeProcess.sandboxed) { require.define('fs', [], function () { return require.__$__nodeRequire('original-fs'); }); } window['MonacoEnvironment'] = {}; - const baseUrl = useCustomProtocol ? - `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out` : - `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32' })}/out`; - const loaderConfig = { - baseUrl, + baseUrl: useCustomProtocol ? + `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out` : + `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32' })}/out`, 'vs/nls': nlsConfig, preferScriptTags: useCustomProtocol }; @@ -132,7 +133,7 @@ loaderConfig.amdModulesPattern = /^vs\//; } - // cached data config + // Cached data config if (configuration.nodeCachedDataDir) { loaderConfig.nodeCachedData = { path: configuration.nodeCachedDataDir, @@ -140,22 +141,27 @@ }; } + // Signal before require.config() if (typeof options?.beforeLoaderConfig === 'function') { options.beforeLoaderConfig(configuration, loaderConfig); } + // Configure loader require.config(loaderConfig); + // Handle pseudo NLS if (nlsConfig.pseudo) { require(['vs/nls'], function (nlsPlugin) { nlsPlugin.setPseudoTranslation(nlsConfig.pseudo); }); } + // Signal before require() if (typeof options?.beforeRequire === 'function') { options.beforeRequire(); } + // Actually require the main module as specified require(modulePaths, async result => { try { diff --git a/src/vs/base/parts/sandbox/electron-browser/preload.js b/src/vs/base/parts/sandbox/electron-browser/preload.js index d9a3faab299..02545028a8b 100644 --- a/src/vs/base/parts/sandbox/electron-browser/preload.js +++ b/src/vs/base/parts/sandbox/electron-browser/preload.js @@ -17,6 +17,9 @@ // ### ### // ####################################################################### + /** + * @type {import('../electron-sandbox/globals')} + */ const globals = { /** @@ -234,17 +237,19 @@ } try { - const configuration = await ipcRenderer.invoke(windowConfigIpcChannel); + if (validateIPC(windowConfigIpcChannel)) { + const configuration = await ipcRenderer.invoke(windowConfigIpcChannel); - // Apply zoom level early before even building the - // window DOM elements to avoid UI flicker. We always - // have to set the zoom level from within the window - // because Chrome has it's own way of remembering zoom - // settings per origin (if vscode-file:// is used) and - // we want to ensure that the user configuration wins. - webFrame.setZoomLevel(configuration.zoomLevel ?? 0); + // Apply zoom level early before even building the + // window DOM elements to avoid UI flicker. We always + // have to set the zoom level from within the window + // because Chrome has it's own way of remembering zoom + // settings per origin (if vscode-file:// is used) and + // we want to ensure that the user configuration wins. + webFrame.setZoomLevel(configuration.zoomLevel ?? 0); - return configuration; + return configuration; + } } catch (error) { throw new Error(`Preload: unable to fetch vscode-window-config: ${error}`); }