Path: blob/main/src/vs/platform/auxiliaryWindow/electron-main/auxiliaryWindow.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*--------------------------------------------------------------------------------------------*/45import { BrowserWindow, BrowserWindowConstructorOptions, WebContents } from 'electron';6import { isLinux, isWindows } from '../../../base/common/platform.js';7import { IConfigurationService } from '../../configuration/common/configuration.js';8import { IEnvironmentMainService } from '../../environment/electron-main/environmentMainService.js';9import { ILifecycleMainService } from '../../lifecycle/electron-main/lifecycleMainService.js';10import { ILogService } from '../../log/common/log.js';11import { IStateService } from '../../state/node/state.js';12import { hasNativeTitlebar, TitlebarStyle } from '../../window/common/window.js';13import { IBaseWindow, WindowMode } from '../../window/electron-main/window.js';14import { BaseWindow } from '../../windows/electron-main/windowImpl.js';1516export interface IAuxiliaryWindow extends IBaseWindow {17readonly parentId: number;18}1920export class AuxiliaryWindow extends BaseWindow implements IAuxiliaryWindow {2122readonly id: number;23parentId = -1;2425override get win() {26if (!super.win) {27this.tryClaimWindow();28}2930return super.win;31}3233private stateApplied = false;3435constructor(36private readonly webContents: WebContents,37@IEnvironmentMainService environmentMainService: IEnvironmentMainService,38@ILogService logService: ILogService,39@IConfigurationService configurationService: IConfigurationService,40@IStateService stateService: IStateService,41@ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService42) {43super(configurationService, stateService, environmentMainService, logService);4445this.id = this.webContents.id;4647// Try to claim window48this.tryClaimWindow();49}5051tryClaimWindow(options?: BrowserWindowConstructorOptions): void {52if (this._store.isDisposed || this.webContents.isDestroyed()) {53return; // already disposed54}5556this.doTryClaimWindow(options);5758if (options && !this.stateApplied) {59this.stateApplied = true;6061this.applyState({62x: options.x,63y: options.y,64width: options.width,65height: options.height,66// We currently do not support restoring fullscreen state for auxiliary67// windows because we do not get hold of the original `features` string68// that contains that info in `window-fullscreen`. However, we can69// probe the `options.show` value for whether the window should be maximized70// or not because we never show maximized windows initially to reduce flicker.71mode: options.show === false ? WindowMode.Maximized : WindowMode.Normal72});73}74}7576private doTryClaimWindow(options?: BrowserWindowConstructorOptions): void {77if (this._win) {78return; // already claimed79}8081const window = BrowserWindow.fromWebContents(this.webContents);82if (window) {83this.logService.trace('[aux window] Claimed browser window instance');8485// Remember86this.setWin(window, options);8788// Disable Menu89window.setMenu(null);90if ((isWindows || isLinux) && hasNativeTitlebar(this.configurationService, options?.titleBarStyle === 'hidden' ? TitlebarStyle.CUSTOM : undefined /* unknown */)) {91window.setAutoHideMenuBar(true); // Fix for https://github.com/microsoft/vscode/issues/20061592}9394// Lifecycle95this.lifecycleMainService.registerAuxWindow(this);96}97}9899matches(webContents: WebContents): boolean {100return this.webContents.id === webContents.id;101}102}103104105