From de73b2802559fc113289cb4dd79b33bc9815dae4 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Wed, 15 Feb 2017 16:38:13 +0100 Subject: [PATCH] [theme] store baseTheme in storage --- src/vs/code/electron-main/window.ts | 23 +++++++++---------- src/vs/code/electron-main/windows.ts | 8 ++++++- .../themes/electron-browser/themeService.ts | 16 ++++++------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 22f0ab90365..1fc8f0373a8 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -9,6 +9,7 @@ import * as path from 'path'; import * as platform from 'vs/base/common/platform'; import * as objects from 'vs/base/common/objects'; import nls = require('vs/nls'); +import { IStorageService } from 'vs/code/electron-main/storage'; import { shell, screen, BrowserWindow, systemPreferences, app } from 'electron'; import { TPromise, TValueCallback } from 'vs/base/common/winjs.base'; import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment'; @@ -20,6 +21,7 @@ import { getCommonHTTPHeaders } from 'vs/platform/environment/node/http'; import { IWindowSettings, MenuBarVisibility } from 'vs/platform/windows/common/windows'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; + export interface IWindowState { width?: number; height?: number; @@ -134,6 +136,8 @@ export interface IVSCodeWindow { export class VSCodeWindow implements IVSCodeWindow { + public static baseThemeStorageKey = 'baseTheme'; + private static MIN_WIDTH = 200; private static MIN_HEIGHT = 120; @@ -160,7 +164,8 @@ export class VSCodeWindow implements IVSCodeWindow { config: IWindowCreationOptions, @ILogService private logService: ILogService, @IEnvironmentService private environmentService: IEnvironmentService, - @IConfigurationService private configurationService: IConfigurationService + @IConfigurationService private configurationService: IConfigurationService, + @IStorageService private storageService: IStorageService ) { this.options = config; this._lastFocusTime = -1; @@ -174,9 +179,9 @@ export class VSCodeWindow implements IVSCodeWindow { this.restoreWindowState(config.state); // For VS theme we can show directly because background is white - const themeId = this.configurationService.lookup('workbench.colorTheme').value; - const usesLightTheme = /^l-/.test(themeId); - const usesHighContrastTheme = /^hc-/.test(themeId) || (platform.isWindows && systemPreferences.isInvertedColorScheme()); + const baseTheme = this.storageService.getItem(VSCodeWindow.baseThemeStorageKey); + const usesLightTheme = 'vs' === baseTheme; + const usesHighContrastTheme = 'hc-black' === baseTheme || (platform.isWindows && systemPreferences.isInvertedColorScheme()); // 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); @@ -503,14 +508,8 @@ export class VSCodeWindow implements IVSCodeWindow { windowConfiguration.accessibilitySupport = app.isAccessibilitySupportEnabled(); // background color - const themeId = this.configurationService.lookup('workbench.colorTheme').value; - if (themeId[0] === 'h') { - windowConfiguration.baseTheme = 'hc-black'; - } else if (themeId[0] === 'l') { - windowConfiguration.baseTheme = 'vs'; - } else { - windowConfiguration.baseTheme = 'vs-dark'; - } + const baseTheme = this.storageService.getItem(VSCodeWindow.baseThemeStorageKey, 'vs-dark'); + windowConfiguration.baseTheme = baseTheme; // Perf Counters windowConfiguration.perfStartTime = global.perfStartTime; diff --git a/src/vs/code/electron-main/windows.ts b/src/vs/code/electron-main/windows.ts index 2f53dc8cc0b..ed7d57f72c8 100644 --- a/src/vs/code/electron-main/windows.ts +++ b/src/vs/code/electron-main/windows.ts @@ -289,6 +289,11 @@ export class WindowsManager implements IWindowsMainService { } private onBroadcast(event: string, payload: any): void { + + // Theme changes + if (event === 'vscode:changeBaseTheme' && typeof payload === 'string') { + this.storageService.setItem(VSCodeWindow.baseThemeStorageKey, payload); + } } public reload(win: VSCodeWindow, cli?: ParsedArgs): void { @@ -788,7 +793,8 @@ export class WindowsManager implements IWindowsMainService { }, this.logService, this.environmentService, - this.configurationService + this.configurationService, + this.storageService ); WindowsManager.WINDOWS.push(vscodeWindow); diff --git a/src/vs/workbench/services/themes/electron-browser/themeService.ts b/src/vs/workbench/services/themes/electron-browser/themeService.ts index 3884501f427..52b76e6da5b 100644 --- a/src/vs/workbench/services/themes/electron-browser/themeService.ts +++ b/src/vs/workbench/services/themes/electron-browser/themeService.ts @@ -15,6 +15,7 @@ import { ExtensionsRegistry, ExtensionMessageCollector } from 'vs/platform/exten import { IThemeService, IThemeSetting, IColorTheme, IFileIconTheme, VS_LIGHT_THEME, VS_DARK_THEME, VS_HC_THEME, COLOR_THEME_SETTING, ICON_THEME_SETTING } from 'vs/workbench/services/themes/common/themeService'; import { EditorStylesContribution, SearchViewStylesContribution, TerminalStylesContribution } from 'vs/workbench/services/themes/electron-browser/stylesContributions'; import { getBaseThemeId, getSyntaxThemeId, isDarkTheme, isLightTheme } from 'vs/platform/theme/common/themes'; +import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { Registry } from 'vs/platform/platform'; @@ -35,7 +36,7 @@ import pfs = require('vs/base/node/pfs'); // implementation const DEFAULT_THEME_ID = 'vs-dark vscode-theme-defaults-themes-dark_plus-json'; -const DEFAULT_THEME_NAME = 'd-Dark+ (default dark)'; +const DEFAULT_THEME_NAME = 'Default Dark+'; const defaultBaseTheme = getBaseThemeId(DEFAULT_THEME_ID); @@ -220,12 +221,6 @@ let defaultThemeColors: { [baseTheme: string]: IThemeSetting[] } = { ], }; -const settingsIdPrefix = { - [VS_DARK_THEME]: 'd-', - [VS_LIGHT_THEME]: 'l-', - [VS_HC_THEME]: 'hc-', -}; - export class ThemeService implements IThemeService { _serviceBrand: any; @@ -242,6 +237,7 @@ export class ThemeService implements IThemeService { container: HTMLElement, @IExtensionService private extensionService: IExtensionService, @IStorageService private storageService: IStorageService, + @IWindowIPCService private windowService: IWindowIPCService, @IConfigurationService private configurationService: IConfigurationService, @IConfigurationEditingService private configurationEditingService: IConfigurationEditingService, @ITelemetryService private telemetryService: ITelemetryService) { @@ -394,6 +390,10 @@ export class ThemeService implements IThemeService { this.onColorThemeChange.fire(this.currentColorTheme); + if (settingsTarget === ConfigurationTarget.USER) { + this.windowService.broadcast({ channel: 'vscode:changeBaseTheme', payload: newTheme.getBaseThemeId() }); + } + return this.writeColorThemeConfiguration(settingsTarget); }; @@ -485,7 +485,7 @@ export class ThemeService implements IThemeService { let themeData = new ColorThemeData(); themeData.id = `${baseTheme} ${themeSelector}`; themeData.label = theme.label || Paths.basename(theme.path); - themeData.settingsId = settingsIdPrefix[baseTheme] + (theme.id || themeData.label); + themeData.settingsId = theme.id || themeData.label; themeData.description = theme.description; themeData.path = normalizedAbsolutePath; themeData.extensionData = extensionData; -- GitLab