Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/auxiliaryWindow/electron-main/auxiliaryWindow.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { BrowserWindow, BrowserWindowConstructorOptions, WebContents } from 'electron';
7
import { isLinux, isWindows } from '../../../base/common/platform.js';
8
import { IConfigurationService } from '../../configuration/common/configuration.js';
9
import { IEnvironmentMainService } from '../../environment/electron-main/environmentMainService.js';
10
import { ILifecycleMainService } from '../../lifecycle/electron-main/lifecycleMainService.js';
11
import { ILogService } from '../../log/common/log.js';
12
import { IStateService } from '../../state/node/state.js';
13
import { hasNativeTitlebar, TitlebarStyle } from '../../window/common/window.js';
14
import { IBaseWindow, WindowMode } from '../../window/electron-main/window.js';
15
import { BaseWindow } from '../../windows/electron-main/windowImpl.js';
16
17
export interface IAuxiliaryWindow extends IBaseWindow {
18
readonly parentId: number;
19
}
20
21
export class AuxiliaryWindow extends BaseWindow implements IAuxiliaryWindow {
22
23
readonly id: number;
24
parentId = -1;
25
26
override get win() {
27
if (!super.win) {
28
this.tryClaimWindow();
29
}
30
31
return super.win;
32
}
33
34
private stateApplied = false;
35
36
constructor(
37
private readonly webContents: WebContents,
38
@IEnvironmentMainService environmentMainService: IEnvironmentMainService,
39
@ILogService logService: ILogService,
40
@IConfigurationService configurationService: IConfigurationService,
41
@IStateService stateService: IStateService,
42
@ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService
43
) {
44
super(configurationService, stateService, environmentMainService, logService);
45
46
this.id = this.webContents.id;
47
48
// Try to claim window
49
this.tryClaimWindow();
50
}
51
52
tryClaimWindow(options?: BrowserWindowConstructorOptions): void {
53
if (this._store.isDisposed || this.webContents.isDestroyed()) {
54
return; // already disposed
55
}
56
57
this.doTryClaimWindow(options);
58
59
if (options && !this.stateApplied) {
60
this.stateApplied = true;
61
62
this.applyState({
63
x: options.x,
64
y: options.y,
65
width: options.width,
66
height: options.height,
67
// We currently do not support restoring fullscreen state for auxiliary
68
// windows because we do not get hold of the original `features` string
69
// that contains that info in `window-fullscreen`. However, we can
70
// probe the `options.show` value for whether the window should be maximized
71
// or not because we never show maximized windows initially to reduce flicker.
72
mode: options.show === false ? WindowMode.Maximized : WindowMode.Normal
73
});
74
}
75
}
76
77
private doTryClaimWindow(options?: BrowserWindowConstructorOptions): void {
78
if (this._win) {
79
return; // already claimed
80
}
81
82
const window = BrowserWindow.fromWebContents(this.webContents);
83
if (window) {
84
this.logService.trace('[aux window] Claimed browser window instance');
85
86
// Remember
87
this.setWin(window, options);
88
89
// Disable Menu
90
window.setMenu(null);
91
if ((isWindows || isLinux) && hasNativeTitlebar(this.configurationService, options?.titleBarStyle === 'hidden' ? TitlebarStyle.CUSTOM : undefined /* unknown */)) {
92
window.setAutoHideMenuBar(true); // Fix for https://github.com/microsoft/vscode/issues/200615
93
}
94
95
// Lifecycle
96
this.lifecycleMainService.registerAuxWindow(this);
97
}
98
}
99
100
matches(webContents: WebContents): boolean {
101
return this.webContents.id === webContents.id;
102
}
103
}
104
105