Workspace level window.zoomLevel does not reset after closing project (fix #187982) (#188655)

This commit is contained in:
Benjamin Pasero 2023-07-24 10:36:36 +02:00 committed by GitHub
parent e2693cfe82
commit de6839abe8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 32 deletions

View file

@ -16,7 +16,7 @@ class WindowManager {
public getZoomLevel(): number {
return this._zoomLevel;
}
public setZoomLevel(zoomLevel: number, isTrusted: boolean): void {
public setZoomLevel(zoomLevel: number): void {
if (this._zoomLevel === zoomLevel) {
return;
}
@ -159,8 +159,8 @@ export function addMatchMediaChangeListener(query: string | MediaQueryList, call
export const PixelRatio = new PixelRatioFacade();
/** A zoom index, e.g. 1, 2, 3 */
export function setZoomLevel(zoomLevel: number, isTrusted: boolean): void {
WindowManager.INSTANCE.setZoomLevel(zoomLevel, isTrusted);
export function setZoomLevel(zoomLevel: number): void {
WindowManager.INSTANCE.setZoomLevel(zoomLevel);
}
export function getZoomLevel(): number {
return WindowManager.INSTANCE.getZoomLevel();

View file

@ -14,10 +14,7 @@ import { zoomLevelToZoomFactor } from 'vs/platform/window/common/window';
export function applyZoom(zoomLevel: number): void {
webFrame.setZoomLevel(zoomLevel);
setZoomFactor(zoomLevelToZoomFactor(zoomLevel));
// Cannot be trusted because the webFrame might take some time
// until it really applies the new zoom level
// See https://github.com/microsoft/vscode/issues/26151
setZoomLevel(zoomLevel, false /* isTrusted */);
setZoomLevel(zoomLevel);
}
export function zoomIn(): void {

View file

@ -5,10 +5,10 @@
import { localize } from 'vs/nls';
import product from 'vs/platform/product/common/product';
import { INativeWindowConfiguration, zoomLevelToZoomFactor } from 'vs/platform/window/common/window';
import { INativeWindowConfiguration, IWindowsConfiguration } from 'vs/platform/window/common/window';
import { Workbench } from 'vs/workbench/browser/workbench';
import { NativeWindow } from 'vs/workbench/electron-sandbox/window';
import { setZoomLevel, setZoomFactor, setFullscreen } from 'vs/base/browser/browser';
import { setFullscreen } from 'vs/base/browser/browser';
import { domContentLoaded } from 'vs/base/browser/dom';
import { onUnexpectedError } from 'vs/base/common/errors';
import { URI } from 'vs/base/common/uri';
@ -58,6 +58,8 @@ import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/c
import { BrowserSocketFactory } from 'vs/platform/remote/browser/browserSocketFactory';
import { RemoteSocketFactoryService, IRemoteSocketFactoryService } from 'vs/platform/remote/common/remoteSocketFactoryService';
import { ElectronRemoteResourceLoader } from 'vs/platform/remote/electron-sandbox/electronRemoteResourceLoader';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { applyZoom } from 'vs/platform/window/electron-sandbox/window';
export class DesktopMain extends Disposable {
@ -74,10 +76,7 @@ export class DesktopMain extends Disposable {
// Massage configuration file URIs
this.reviveUris();
// Browser config
const zoomLevel = this.configuration.zoomLevel || 0;
setZoomFactor(zoomLevelToZoomFactor(zoomLevel));
setZoomLevel(zoomLevel, true /* isTrusted */);
// Apply fullscreen early if configured
setFullscreen(!!this.configuration.fullscreen);
}
@ -112,6 +111,13 @@ export class DesktopMain extends Disposable {
// Init services and wait for DOM to be ready in parallel
const [services] = await Promise.all([this.initServices(), domContentLoaded()]);
// Apply zoom level early once we have a configuration service
// and before the workbench is created to prevent flickering.
// We also need to respect that zoom level can be configured per
// workspace, so we need the resolved configuration service.
// (fixes https://github.com/microsoft/vscode/issues/187982)
this.applyConfiguredWindowZoomLevel(services.configurationService);
// Create Workbench
const workbench = new Workbench(document.body, { extraClasses: this.getExtraClasses() }, services.serviceCollection, services.logService);
@ -125,6 +131,13 @@ export class DesktopMain extends Disposable {
this._register(instantiationService.createInstance(NativeWindow));
}
private applyConfiguredWindowZoomLevel(configurationService: IConfigurationService) {
const windowConfig = configurationService.getValue<IWindowsConfiguration>();
const windowZoomLevel = typeof windowConfig.window?.zoomLevel === 'number' ? windowConfig.window.zoomLevel : 0;
applyZoom(windowZoomLevel);
}
private getExtraClasses(): string[] {
if (isMacintosh) {
if (this.configuration.os.release > '20.0.0') {
@ -142,7 +155,7 @@ export class DesktopMain extends Disposable {
this._register(workbench.onDidShutdown(() => this.dispose()));
}
private async initServices(): Promise<{ serviceCollection: ServiceCollection; logService: ILogService; storageService: NativeWorkbenchStorageService }> {
private async initServices(): Promise<{ serviceCollection: ServiceCollection; logService: ILogService; storageService: NativeWorkbenchStorageService; configurationService: IConfigurationService }> {
const serviceCollection = new ServiceCollection();
@ -310,7 +323,7 @@ export class DesktopMain extends Disposable {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return { serviceCollection, logService, storageService };
return { serviceCollection, logService, storageService, configurationService };
}
private resolveWorkspaceIdentifier(environmentService: INativeWorkbenchEnvironmentService): IAnyWorkspaceIdentifier {

View file

@ -79,8 +79,6 @@ export class NativeWindow extends Disposable {
private readonly customTitleContextMenuDisposable = this._register(new DisposableStore());
private previousConfiguredZoomLevel: number | undefined;
private readonly addFoldersScheduler = this._register(new RunOnceScheduler(() => this.doAddFolders(), 100));
private pendingFoldersToAdd: URI[] = [];
@ -320,7 +318,6 @@ export class NativeWindow extends Disposable {
});
// Zoom level changes
this.updateWindowZoomLevel();
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('window.zoomLevel')) {
this.updateWindowZoomLevel();
@ -605,21 +602,10 @@ export class NativeWindow extends Disposable {
private updateWindowZoomLevel(): void {
const windowConfig = this.configurationService.getValue<IWindowsConfiguration>();
const windowZoomLevel = typeof windowConfig.window?.zoomLevel === 'number' ? windowConfig.window.zoomLevel : 0;
let configuredZoomLevel = 0;
if (windowConfig.window && typeof windowConfig.window.zoomLevel === 'number') {
configuredZoomLevel = windowConfig.window.zoomLevel;
// Leave early if the configured zoom level did not change (https://github.com/microsoft/vscode/issues/1536)
if (this.previousConfiguredZoomLevel === configuredZoomLevel) {
return;
}
this.previousConfiguredZoomLevel = configuredZoomLevel;
}
if (getZoomLevel() !== configuredZoomLevel) {
applyZoom(configuredZoomLevel);
if (getZoomLevel() !== windowZoomLevel) {
applyZoom(windowZoomLevel);
}
}