src/vs/platform/windows/electron-main/windowImpl.ts/CodeWindow/constructor
class CodeWindow:	constructor(
		config: IWindowCreationOptions,
		@ILogService private readonly logService: ILogService,
		@IEnvironmentMainService private readonly environmentMainService: IEnvironmentMainService,
		@IPolicyService private readonly policyService: IPolicyService,
		@IUserDataProfilesMainService private readonly userDataProfilesService: IUserDataProfilesMainService,
		@IFileService private readonly fileService: IFileService,
		@IApplicationStorageMainService private readonly applicationStorageMainService: IApplicationStorageMainService,
		@IStorageMainService private readonly storageMainService: IStorageMainService,
		@IConfigurationService private readonly configurationService: IConfigurationService,
		@IThemeMainService private readonly themeMainService: IThemeMainService,
		@IWorkspacesManagementMainService private readonly workspacesManagementMainService: IWorkspacesManagementMainService,
		@IBackupMainService private readonly backupMainService: IBackupMainService,
		@ITelemetryService private readonly telemetryService: ITelemetryService,
		@IDialogMainService private readonly dialogMainService: IDialogMainService,
		@ILifecycleMainService private readonly lifecycleMainService: ILifecycleMainService,
		@IProductService private readonly productService: IProductService,
		@IProtocolMainService private readonly protocolMainService: IProtocolMainService,
		@IWindowsMainService private readonly windowsMainService: IWindowsMainService,
		@IStateMainService private readonly stateMainService: IStateMainService,
		@INativeHostMainService private readonly nativeHostMainService: INativeHostMainService
	) {
		super();

		//#region create browser window
		{
			// Load window state
			const [state, hasMultipleDisplays] = this.restoreWindowState(config.state);
			this.windowState = state;
			this.logService.trace('window#ctor: using window state', state);

			// In case we are maximized or fullscreen, only show later
			// after the call to maximize/fullscreen (see below)
			const isFullscreenOrMaximized = (this.windowState.mode === WindowMode.Maximized || this.windowState.mode === WindowMode.Fullscreen);

			if (typeof CodeWindow.sandboxState === 'undefined') {
				// we should only check this once so that we do not end up
				// with some windows in sandbox mode and some not!
				CodeWindow.sandboxState = this.stateMainService.getItem<boolean>('window.experimental.useSandbox', false);
			}

			const windowSettings = this.configurationService.getValue<IWindowSettings | undefined>('window');

			let useSandbox = false;
			if (typeof windowSettings?.experimental?.useSandbox === 'boolean') {
				useSandbox = windowSettings.experimental.useSandbox;
			} else if (this.productService.quality === 'stable' && CodeWindow.sandboxState) {
				useSandbox = true;
			} else {
				useSandbox = typeof this.productService.quality === 'string' && this.productService.quality !== 'stable';
			}

			const options: BrowserWindowConstructorOptions & { experimentalDarkMode: boolean } = {
				width: this.windowState.width,
				height: this.windowState.height,
				x: this.windowState.x,
				y: this.windowState.y,
				backgroundColor: this.themeMainService.getBackgroundColor(),
				minWidth: WindowMinimumSize.WIDTH,
				minHeight: WindowMinimumSize.HEIGHT,
				show: !isFullscreenOrMaximized, // reduce flicker by showing later
				title: this.productService.nameLong,
				webPreferences: {
					preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-browser/preload.js').fsPath,
					additionalArguments: [`--vscode-window-config=${this.configObjectUrl.resource.toString()}`],
					v8CacheOptions: this.environmentMainService.useCodeCache ? 'bypassHeatCheck' : 'none',
					enableWebSQL: false,
					spellcheck: false,
					zoomFactor: zoomLevelToZoomFactor(windowSettings?.zoomLevel),
					autoplayPolicy: 'user-gesture-required',
					// Enable experimental css highlight api https://chromestatus.com/feature/5436441440026624
					// Refs https://github.com/microsoft/vscode/issues/140098
					enableBlinkFeatures: 'HighlightAPI',
					...useSandbox ?

						// Sandbox
						{
							sandbox: true
						} :

						// No Sandbox
						{
							nodeIntegration: true,
							contextIsolation: false
						}
				},
				experimentalDarkMode: true
			};

			// Apply icon to window
			// Linux: always
			// Windows: only when running out of sources, otherwise an icon is set by us on the executable
			if (isLinux) {
				options.icon = join(this.environmentMainService.appRoot, 'resources/linux/code.png');
			} else if (isWindows && !this.environmentMainService.isBuilt) {
				options.icon = join(this.environmentMainService.appRoot, 'resources/win32/code_150x150.png');
			}

			if (isMacintosh && !this.useNativeFullScreen()) {
				options.fullscreenable = false; // enables simple fullscreen mode
			}

			if (isMacintosh) {
				options.acceptFirstMouse = true; // enabled by default

				if (windowSettings?.clickThroughInactive === false) {
					options.acceptFirstMouse = false;
				}
			}

			const useNativeTabs = isMacintosh && windowSettings?.nativeTabs === true;
			if (useNativeTabs) {
				options.tabbingIdentifier = this.productService.nameShort; // this opts in to sierra tabs
			}

			const useCustomTitleStyle = getTitleBarStyle(this.configurationService) === 'custom';
			if (useCustomTitleStyle) {
				options.titleBarStyle = 'hidden';
				if (!isMacintosh) {
					options.frame = false;
				}

				if (useWindowControlsOverlay(this.configurationService)) {

					// This logic will not perfectly guess the right colors
					// to use on initialization, but prefer to keep things
					// simple as it is temporary and not noticeable

					const titleBarColor = this.themeMainService.getWindowSplash()?.colorInfo.titleBarBackground ?? this.themeMainService.getBackgroundColor();
					const symbolColor = Color.fromHex(titleBarColor).isDarker() ? '#FFFFFF' : '#000000';

					options.titleBarOverlay = {
						height: 29, // the smallest size of the title bar on windows accounting for the border on windows 11
						color: titleBarColor,
						symbolColor
					};

					this.hasWindowControlOverlay = true;
				}
			}

			// Create the browser window
			mark('code/willCreateCodeBrowserWindow');
			this._win = new BrowserWindow(options);
			mark('code/didCreateCodeBrowserWindow');

			this._id = this._win.id;

			if (isMacintosh && useCustomTitleStyle) {
				this._win.setSheetOffset(22); // offset dialogs by the height of the custom title bar if we have any
			}

			// Update the window controls immediately based on cached values
			if (useCustomTitleStyle && ((isWindows && useWindowControlsOverlay(this.configurationService)) || isMacintosh)) {
				const cachedWindowControlHeight = this.stateMainService.getItem<number>((CodeWindow.windowControlHeightStateStorageKey));
				if (cachedWindowControlHeight) {
					this.updateWindowControls({ height: cachedWindowControlHeight });
				}
			}

			// Windows Custom System Context Menu
			// See https://github.com/electron/electron/issues/24893
			//
			// The purpose of this is to allow for the context menu in the Windows Title Bar
			//
			// Currently, all mouse events in the title bar are captured by the OS
			// thus we need to capture them here with a window hook specific to Windows
			// and then forward them to the correct window.
			if (isWindows && useCustomTitleStyle) {
				const WM_INITMENU = 0x0116; // https://docs.microsoft.com/en-us/windows/win32/menurc/wm-initmenu

				// This sets up a listener for the window hook. This is a Windows-only API provided by electron.
				this._win.hookWindowMessage(WM_INITMENU, () => {
					const [x, y] = this._win.getPosition();
					const cursorPos = screen.getCursorScreenPoint();
					const cx = cursorPos.x - x;
					const cy = cursorPos.y - y;

					// In some cases, show the default system context menu
					// 1) The mouse position is not within the title bar
					// 2) The mouse position is within the title bar, but over the app icon
					// We do not know the exact title bar height but we make an estimate based on window height
					const shouldTriggerDefaultSystemContextMenu = () => {
						// Use the custom context menu when over the title bar, but not over the app icon
						// The app icon is estimated to be 30px wide
						// The title bar is estimated to be the max of 35px and 15% of the window height
						if (cx > 30 && cy >= 0 && cy <= Math.max(this._win.getBounds().height * 0.15, 35)) {
							return false;
						}

						return true;
					};

					if (!shouldTriggerDefaultSystemContextMenu()) {
						// This is necessary to make sure the native system context menu does not show up.
						this._win.setEnabled(false);
						this._win.setEnabled(true);

						this._onDidTriggerSystemContextMenu.fire({ x: cx, y: cy });
					}

					return 0;
				});
			}

			// TODO@electron (Electron 4 regression): when running on multiple displays where the target display
			// to open the window has a larger resolution than the primary display, the window will not size
			// correctly unless we set the bounds again (https://github.com/microsoft/vscode/issues/74872)
			//
			// Extended to cover Windows as well as Mac (https://github.com/microsoft/vscode/issues/146499)
			//
			// However, when running with native tabs with multiple windows we cannot use this workaround
			// because there is a potential that the new window will be added as native tab instead of being
			// a window on its own. In that case calling setBounds() would cause https://github.com/microsoft/vscode/issues/75830
			if ((isMacintosh || isWindows) && hasMultipleDisplays && (!useNativeTabs || BrowserWindow.getAllWindows().length === 1)) {
				if ([this.windowState.width, this.windowState.height, this.windowState.x, this.windowState.y].every(value => typeof value === 'number')) {
					this._win.setBounds({
						width: this.windowState.width,
						height: this.windowState.height,
						x: this.windowState.x,
						y: this.windowState.y
					});
				}
			}

			if (isFullscreenOrMaximized) {
				mark('code/willMaximizeCodeWindow');

				// this call may or may not show the window, depends
				// on the platform: currently on Windows and Linux will
				// show the window as active. To be on the safe side,
				// we show the window at the end of this block.
				this._win.maximize();

				if (this.windowState.mode === WindowMode.Fullscreen) {
					this.setFullScreen(true);
				}

				// to reduce flicker from the default window size
				// to maximize or fullscreen, we only show after
				this._win.show();
				mark('code/didMaximizeCodeWindow');
			}

			this._lastFocusTime = Date.now(); // since we show directly, we need to set the last focus time too
		}
		//#endregion

		// Open devtools if instructed from command line args
		if (this.environmentMainService.args['open-devtools'] === true) {
			this._win.webContents.openDevTools();
		}

		// respect configured menu bar visibility
		this.onConfigurationUpdated();

		// macOS: touch bar support
		this.createTouchBar();

		// Eventing
		this.registerListeners();
	}