<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import * as path from 'path';
import * as platform from 'vs/base/common/platform';
import * as objects from 'vs/base/common/objects';
import { IStorageService } from 'vs/code/electron-main/storage';
import { shell, screen, BrowserWindow } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { ICommandLineArguments, IEnvService, IProcessEnvironment } from 'vs/code/electron-main/env';
import { ILogService } from 'vs/code/electron-main/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { parseArgs } from 'vs/platform/environment/node/argv';

export interface IWindowState {
	width?: number;
	height?: number;
	x?: number;
	y?: number;
	mode?: WindowMode;
}

export interface IWindowCreationOptions {
	state: IWindowState;
	extensionDevelopmentPath?: string;
	allowFullscreen?: boolean;
}

export enum WindowMode {
	Maximized,
	Normal,
	Minimized,
	Fullscreen
}

export const defaultWindowState = function (mode = WindowMode.Normal): IWindowState {
	return {
		width: 1024,
		height: 768,
		mode: mode
	};
};

export enum ReadyState {

	/**
	 * This window has not loaded any HTML yet
	 */
	NONE,

	/**
	 * This window is loading HTML
	 */
	LOADING,

	/**
	 * This window is navigating to another HTML
	 */
	NAVIGATING,

	/**
	 * This window is done loading HTML
	 */
	READY
}

export interface IPath {

	// the workspace spath for a VSCode instance which can be null
	workspacePath?: string;

	// the file path to open within a VSCode instance
	filePath?: string;

	// the line number in the file path to open
	lineNumber?: number;

	// the column number in the file path to open
	columnNumber?: number;

	// indicator to create the file path in the VSCode instance
	createFilePath?: boolean;

	// indicator to install the extension (path to .vsix) in the VSCode instance
	installExtensionPath?: boolean;
}

export interface IWindowConfiguration extends ICommandLineArguments {
	appRoot: string;
	execPath: string;

	userEnv: IProcessEnvironment;

	zoomLevel?: number;

	workspacePath?: string;

	filesToOpen?: IPath[];
	filesToCreate?: IPath[];
	filesToDiff?: IPath[];

	extensionsToInstall: string[];
}

export interface IWindowSettings {
	openFilesInNewWindow: boolean;
	reopenFolders: 'all' | 'one' | 'none';
	restoreFullscreen: boolean;
	zoomLevel: number;
}

export class VSCodeWindow {

	public static menuBarHiddenKey = 'menuBarHidden';
	public static colorThemeStorageKey = 'theme';

	private static MIN_WIDTH = 200;
	private static MIN_HEIGHT = 120;

	private options: IWindowCreationOptions;
	private showTimeoutHandle: any;
	private _id: number;
	private _win: Electron.BrowserWindow;
	private _lastFocusTime: number;
	private _readyState: ReadyState;
	private _extensionDevelopmentPath: string;
	private windowState: IWindowState;
	private currentWindowMode: WindowMode;

	private whenReadyCallbacks: TValueCallback<VSCodeWindow>[];

	private currentConfig: IWindowConfiguration;
	private pendingLoadConfig: IWindowConfiguration;

	constructor(
		config: IWindowCreationOptions,
		@ILogService private logService: ILogService,
		@IEnvService private envService: IEnvService,
		@IConfigurationService private configurationService: IConfigurationService,
		@IStorageService private storageService: IStorageService
	) {
		this.options = config;
		this._lastFocusTime = -1;
		this._readyState = ReadyState.NONE;
		this._extensionDevelopmentPath = config.extensionDevelopmentPath;
		this.whenReadyCallbacks = [];

		// Load window state
		this.restoreWindowState(config.state);

		// For VS theme we can show directly because background is white
		const usesLightTheme = /vs($| )/.test(this.storageService.getItem<string>(VSCodeWindow.colorThemeStorageKey));
		if (!global.windowShow) {
			global.windowShow = Date.now();
		}

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

		const options: Electron.BrowserWindowOptions = {
			width: this.windowState.width,
			height: this.windowState.height,
			x: this.windowState.x,
			y: this.windowState.y,
			backgroundColor: usesLightTheme ? '#FFFFFF' : platform.isMacintosh ? '#131313' : '#1E1E1E', // https://github.com/electron/electron/issues/5150
			minWidth: VSCodeWindow.MIN_WIDTH,
			minHeight: VSCodeWindow.MIN_HEIGHT,
			show: !isFullscreenOrMaximized,
			title: this.envService.product.nameLong,
			webPreferences: {
				'backgroundThrottling': false // by default if Code is in the background, intervals and timeouts get throttled
			}
		};

		if (platform.isLinux) {
			options.icon = path.join(this.envService.appRoot, 'resources/linux/code.png'); // Windows and Mac are better off using the embedded icon(s)
		}

		// Create the browser window.
		this._win = new BrowserWindow(options);
		this._id = this._win.id;
<commit_msg>more aligned bg color on window start<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import * as path from 'path';
import * as platform from 'vs/base/common/platform';
import * as objects from 'vs/base/common/objects';
import { IStorageService } from 'vs/code/electron-main/storage';
import { shell, screen, BrowserWindow } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { ICommandLineArguments, IEnvService, IProcessEnvironment } from 'vs/code/electron-main/env';
import { ILogService } from 'vs/code/electron-main/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { parseArgs } from 'vs/platform/environment/node/argv';

export interface IWindowState {
	width?: number;
	height?: number;
	x?: number;
	y?: number;
	mode?: WindowMode;
}

export interface IWindowCreationOptions {
	state: IWindowState;
	extensionDevelopmentPath?: string;
	allowFullscreen?: boolean;
}

export enum WindowMode {
	Maximized,
	Normal,
	Minimized,
	Fullscreen
}

export const defaultWindowState = function (mode = WindowMode.Normal): IWindowState {
	return {
		width: 1024,
		height: 768,
		mode: mode
	};
};

export enum ReadyState {

	/**
	 * This window has not loaded any HTML yet
	 */
	NONE,

	/**
	 * This window is loading HTML
	 */
	LOADING,

	/**
	 * This window is navigating to another HTML
	 */
	NAVIGATING,

	/**
	 * This window is done loading HTML
	 */
	READY
}

export interface IPath {

	// the workspace spath for a VSCode instance which can be null
	workspacePath?: string;

	// the file path to open within a VSCode instance
	filePath?: string;

	// the line number in the file path to open
	lineNumber?: number;

	// the column number in the file path to open
	columnNumber?: number;

	// indicator to create the file path in the VSCode instance
	createFilePath?: boolean;

	// indicator to install the extension (path to .vsix) in the VSCode instance
	installExtensionPath?: boolean;
}

export interface IWindowConfiguration extends ICommandLineArguments {
	appRoot: string;
	execPath: string;

	userEnv: IProcessEnvironment;

	zoomLevel?: number;

	workspacePath?: string;

	filesToOpen?: IPath[];
	filesToCreate?: IPath[];
	filesToDiff?: IPath[];

	extensionsToInstall: string[];
}

export interface IWindowSettings {
	openFilesInNewWindow: boolean;
	reopenFolders: 'all' | 'one' | 'none';
	restoreFullscreen: boolean;
	zoomLevel: number;
}

export class VSCodeWindow {

	public static menuBarHiddenKey = 'menuBarHidden';
	public static colorThemeStorageKey = 'theme';

	private static MIN_WIDTH = 200;
	private static MIN_HEIGHT = 120;

	private options: IWindowCreationOptions;
	private showTimeoutHandle: any;
	private _id: number;
	private _win: Electron.BrowserWindow;
	private _lastFocusTime: number;
	private _readyState: ReadyState;
	private _extensionDevelopmentPath: string;
	private windowState: IWindowState;
	private currentWindowMode: WindowMode;

	private whenReadyCallbacks: TValueCallback<VSCodeWindow>[];

	private currentConfig: IWindowConfiguration;
	private pendingLoadConfig: IWindowConfiguration;

	constructor(
		config: IWindowCreationOptions,
		@ILogService private logService: ILogService,
		@IEnvService private envService: IEnvService,
		@IConfigurationService private configurationService: IConfigurationService,
		@IStorageService private storageService: IStorageService
	) {
		this.options = config;
		this._lastFocusTime = -1;
		this._readyState = ReadyState.NONE;
		this._extensionDevelopmentPath = config.extensionDevelopmentPath;
		this.whenReadyCallbacks = [];

		// Load window state
		this.restoreWindowState(config.state);

		// For VS theme we can show directly because background is white
		const usesLightTheme = /vs($| )/.test(this.storageService.getItem<string>(VSCodeWindow.colorThemeStorageKey));
		if (!global.windowShow) {
			global.windowShow = Date.now();
		}

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

		const options: Electron.BrowserWindowOptions = {
			width: this.windowState.width,
			height: this.windowState.height,
			x: this.windowState.x,
			y: this.windowState.y,
			backgroundColor: usesLightTheme ? '#FFFFFF' : platform.isMacintosh ? '#171717' : '#1E1E1E', // https://github.com/electron/electron/issues/5150
			minWidth: VSCodeWindow.MIN_WIDTH,
			minHeight: VSCodeWindow.MIN_HEIGHT,
			show: !isFullscreenOrMaximized,
			title: this.envService.product.nameLong,
			webPreferences: {
				'backgroundThrottling': false // by default if Code is in the background, intervals and timeouts get throttled
			}
		};

		if (platform.isLinux) {
			options.icon = path.join(this.envService.appRoot, 'resources/linux/code.png'); // Windows and Mac are better off using the embedded icon(s)
		}

		// Create the browser window.
		this._win = new BrowserWindow(options);
		this._id = this._win.id;

{'fraction_non_alphanumeric': 0.12950575994054256, 'fraction_numerical': 0.005016722408026756, 'mean_word_length': 3.890958655156747, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6797490', 'n_tokens_mistral': 3301, 'n_tokens_neox': 3038, 'n_words': 914}