preload - apply zoom level after resolving config

This commit is contained in:
Benjamin Pasero 2021-03-31 10:48:07 +02:00
parent 5c79571610
commit 970f799890
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
3 changed files with 16 additions and 13 deletions

View file

@ -23,7 +23,6 @@
}(this, function () {
const bootstrapLib = bootstrap();
const preloadGlobals = globals();
const webFrame = preloadGlobals.webFrame;
const safeProcess = preloadGlobals.process;
const useCustomProtocol = safeProcess.sandboxed || typeof safeProcess.env['ENABLE_VSCODE_BROWSER_CODE_LOADING'] === 'string';
@ -38,17 +37,10 @@
*/
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');
// 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);
// Error handler
safeProcess.on('uncaughtException', function (/** @type {string | Error} */ error) {
onUnexpectedError(error, enableDeveloperTools);

View file

@ -225,7 +225,7 @@
* The property is intentionally not using a getter to resolve
* it as soon as possible to prevent waterfalls.
*
* @type {Promise<import('../electron-sandbox/globals').ISandboxConfiguration>}
* @type {Promise<import('../common/sandboxTypes').ISandboxConfiguration>}
*/
configuration: (async () => {
const windowConfigIpcChannel = parseArgv('vscode-window-config');
@ -234,12 +234,22 @@
}
try {
return await ipcRenderer.invoke(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);
return configuration;
} catch (error) {
throw new Error(`Preload: unable to fetch vscode-window-config: ${error}`);
}
})()
},
}
};
// Use `contextBridge` APIs to expose globals to VSCode

View file

@ -4,13 +4,14 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { ipcRenderer, crashReporter, webFrame, process } from 'vs/base/parts/sandbox/electron-sandbox/globals';
import { ipcRenderer, crashReporter, webFrame, context, process } from 'vs/base/parts/sandbox/electron-sandbox/globals';
suite('Sandbox', () => {
test('globals', () => {
assert.ok(typeof ipcRenderer.send === 'function');
assert.ok(typeof crashReporter.addExtraParameter === 'function');
assert.ok(typeof webFrame.setZoomLevel === 'function');
assert.ok(context.configuration instanceof Promise);
assert.ok(typeof process.platform === 'string');
});
});