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

import { isWindows, isMacintosh } from 'vs/base/common/platform';
import { ipcMain, nativeTheme } from 'electron';
import { IStateService } from 'vs/platform/state/node/state';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';

const DEFAULT_BG_LIGHT = '#FFFFFF';
const DEFAULT_BG_DARK = '#1E1E1E';
const DEFAULT_BG_HC_BLACK = '#000000';

const THEME_STORAGE_KEY = 'theme';
const THEME_BG_STORAGE_KEY = 'themeBackground';

export const IThemeMainService = createDecorator<IThemeMainService>('themeMainService');

export interface IThemeMainService {
	readonly _serviceBrand: undefined;

	getBackgroundColor(): string;
}

export class ThemeMainService implements IThemeMainService {

	declare readonly _serviceBrand: undefined;

	constructor(@IStateService private stateService: IStateService) {
		ipcMain.on('vscode:changeColorTheme', (e: Event, windowId: number, broadcast: string) => {
			// Theme changes
			if (typeof broadcast === 'string') {
				this.storeBackgroundColor(JSON.parse(broadcast));
			}
		});
	}

	private storeBackgroundColor(data: { baseTheme: string, background: string }): void {
		this.stateService.setItem(THEME_STORAGE_KEY, data.baseTheme);
		this.stateService.setItem(THEME_BG_STORAGE_KEY, data.background);
	}

	getBackgroundColor(): string {
		if ((isWindows || isMacintosh) && nativeTheme.shouldUseInvertedColorScheme) {
			return DEFAULT_BG_HC_BLACK;
		}

		let background = this.stateService.getItem<string | null>(THEME_BG_STORAGE_KEY, null);<commit_msg>ThemeMainService: update window background color<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { isWindows, isMacintosh } from 'vs/base/common/platform';
import { BrowserWindow, ipcMain, nativeTheme } from 'electron';
import { IStateService } from 'vs/platform/state/node/state';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';

const DEFAULT_BG_LIGHT = '#FFFFFF';
const DEFAULT_BG_DARK = '#1E1E1E';
const DEFAULT_BG_HC_BLACK = '#000000';

const THEME_STORAGE_KEY = 'theme';
const THEME_BG_STORAGE_KEY = 'themeBackground';

export const IThemeMainService = createDecorator<IThemeMainService>('themeMainService');

export interface IThemeMainService {
	readonly _serviceBrand: undefined;

	getBackgroundColor(): string;
}

interface ThemeData {
	baseTheme: string;
	background: string;
}

export class ThemeMainService implements IThemeMainService {

	declare readonly _serviceBrand: undefined;

	constructor(@IStateService private stateService: IStateService) {
		ipcMain.on('vscode:changeColorTheme', (e: Event, windowId: number, broadcast: string) => {
			// Theme changes
			if (typeof broadcast === 'string') {
				const themeData = JSON.parse(broadcast) as ThemeData;
				this.storeBackgroundColor(themeData);
				this.updateBackgroundColor(windowId, themeData);
			}
		});
	}

	private storeBackgroundColor(data: ThemeData): void {
		this.stateService.setItem(THEME_STORAGE_KEY, data.baseTheme);
		this.stateService.setItem(THEME_BG_STORAGE_KEY, data.background);
	}

	private updateBackgroundColor(windowId: number, data: ThemeData): void {
		BrowserWindow.getAllWindows().forEach(window => {
			if (window.id === windowId) {
				window.setBackgroundColor(data.background);
			}
		});
	}

	getBackgroundColor(): string {
		if ((isWindows || isMacintosh) && nativeTheme.shouldUseInvertedColorScheme) {
			return DEFAULT_BG_HC_BLACK;
		}

		let background = this.stateService.getItem<string | null>(THEME_BG_STORAGE_KEY, null);
{'fraction_non_alphanumeric': 0.1875149485768955, 'fraction_numerical': 0.004305190145898111, 'mean_word_length': 3.5064655172413794, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6436355', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1152, 'n_words': 261}