Skip to content

Commit de73b28

Browse files
committed
[theme] store baseTheme in storage
1 parent acdb4e9 commit de73b28

3 files changed

Lines changed: 26 additions & 21 deletions

File tree

src/vs/code/electron-main/window.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as path from 'path';
99
import * as platform from 'vs/base/common/platform';
1010
import * as objects from 'vs/base/common/objects';
1111
import nls = require('vs/nls');
12+
import { IStorageService } from 'vs/code/electron-main/storage';
1213
import { shell, screen, BrowserWindow, systemPreferences, app } from 'electron';
1314
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
1415
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
@@ -20,6 +21,7 @@ import { getCommonHTTPHeaders } from 'vs/platform/environment/node/http';
2021
import { IWindowSettings, MenuBarVisibility } from 'vs/platform/windows/common/windows';
2122
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
2223

24+
2325
export interface IWindowState {
2426
width?: number;
2527
height?: number;
@@ -134,6 +136,8 @@ export interface IVSCodeWindow {
134136

135137
export class VSCodeWindow implements IVSCodeWindow {
136138

139+
public static baseThemeStorageKey = 'baseTheme';
140+
137141
private static MIN_WIDTH = 200;
138142
private static MIN_HEIGHT = 120;
139143

@@ -160,7 +164,8 @@ export class VSCodeWindow implements IVSCodeWindow {
160164
config: IWindowCreationOptions,
161165
@ILogService private logService: ILogService,
162166
@IEnvironmentService private environmentService: IEnvironmentService,
163-
@IConfigurationService private configurationService: IConfigurationService
167+
@IConfigurationService private configurationService: IConfigurationService,
168+
@IStorageService private storageService: IStorageService
164169
) {
165170
this.options = config;
166171
this._lastFocusTime = -1;
@@ -174,9 +179,9 @@ export class VSCodeWindow implements IVSCodeWindow {
174179
this.restoreWindowState(config.state);
175180

176181
// For VS theme we can show directly because background is white
177-
const themeId = this.configurationService.lookup<string>('workbench.colorTheme').value;
178-
const usesLightTheme = /^l-/.test(themeId);
179-
const usesHighContrastTheme = /^hc-/.test(themeId) || (platform.isWindows && systemPreferences.isInvertedColorScheme());
182+
const baseTheme = this.storageService.getItem<string>(VSCodeWindow.baseThemeStorageKey);
183+
const usesLightTheme = 'vs' === baseTheme;
184+
const usesHighContrastTheme = 'hc-black' === baseTheme || (platform.isWindows && systemPreferences.isInvertedColorScheme());
180185

181186
// in case we are maximized or fullscreen, only show later after the call to maximize/fullscreen (see below)
182187
const isFullscreenOrMaximized = (this.currentWindowMode === WindowMode.Maximized || this.currentWindowMode === WindowMode.Fullscreen);
@@ -503,14 +508,8 @@ export class VSCodeWindow implements IVSCodeWindow {
503508
windowConfiguration.accessibilitySupport = app.isAccessibilitySupportEnabled();
504509

505510
// background color
506-
const themeId = this.configurationService.lookup<string>('workbench.colorTheme').value;
507-
if (themeId[0] === 'h') {
508-
windowConfiguration.baseTheme = 'hc-black';
509-
} else if (themeId[0] === 'l') {
510-
windowConfiguration.baseTheme = 'vs';
511-
} else {
512-
windowConfiguration.baseTheme = 'vs-dark';
513-
}
511+
const baseTheme = this.storageService.getItem<string>(VSCodeWindow.baseThemeStorageKey, 'vs-dark');
512+
windowConfiguration.baseTheme = baseTheme;
514513

515514
// Perf Counters
516515
windowConfiguration.perfStartTime = global.perfStartTime;

src/vs/code/electron-main/windows.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ export class WindowsManager implements IWindowsMainService {
289289
}
290290

291291
private onBroadcast(event: string, payload: any): void {
292+
293+
// Theme changes
294+
if (event === 'vscode:changeBaseTheme' && typeof payload === 'string') {
295+
this.storageService.setItem(VSCodeWindow.baseThemeStorageKey, payload);
296+
}
292297
}
293298
public reload(win: VSCodeWindow, cli?: ParsedArgs): void {
294299

@@ -788,7 +793,8 @@ export class WindowsManager implements IWindowsMainService {
788793
},
789794
this.logService,
790795
this.environmentService,
791-
this.configurationService
796+
this.configurationService,
797+
this.storageService
792798
);
793799

794800
WindowsManager.WINDOWS.push(vscodeWindow);

src/vs/workbench/services/themes/electron-browser/themeService.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ExtensionsRegistry, ExtensionMessageCollector } from 'vs/platform/exten
1515
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';
1616
import { EditorStylesContribution, SearchViewStylesContribution, TerminalStylesContribution } from 'vs/workbench/services/themes/electron-browser/stylesContributions';
1717
import { getBaseThemeId, getSyntaxThemeId, isDarkTheme, isLightTheme } from 'vs/platform/theme/common/themes';
18+
import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
1819
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
1920
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2021
import { Registry } from 'vs/platform/platform';
@@ -35,7 +36,7 @@ import pfs = require('vs/base/node/pfs');
3536
// implementation
3637

3738
const DEFAULT_THEME_ID = 'vs-dark vscode-theme-defaults-themes-dark_plus-json';
38-
const DEFAULT_THEME_NAME = 'd-Dark+ (default dark)';
39+
const DEFAULT_THEME_NAME = 'Default Dark+';
3940

4041
const defaultBaseTheme = getBaseThemeId(DEFAULT_THEME_ID);
4142

@@ -220,12 +221,6 @@ let defaultThemeColors: { [baseTheme: string]: IThemeSetting[] } = {
220221
],
221222
};
222223

223-
const settingsIdPrefix = {
224-
[VS_DARK_THEME]: 'd-',
225-
[VS_LIGHT_THEME]: 'l-',
226-
[VS_HC_THEME]: 'hc-',
227-
};
228-
229224
export class ThemeService implements IThemeService {
230225
_serviceBrand: any;
231226

@@ -242,6 +237,7 @@ export class ThemeService implements IThemeService {
242237
container: HTMLElement,
243238
@IExtensionService private extensionService: IExtensionService,
244239
@IStorageService private storageService: IStorageService,
240+
@IWindowIPCService private windowService: IWindowIPCService,
245241
@IConfigurationService private configurationService: IConfigurationService,
246242
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService,
247243
@ITelemetryService private telemetryService: ITelemetryService) {
@@ -394,6 +390,10 @@ export class ThemeService implements IThemeService {
394390

395391
this.onColorThemeChange.fire(this.currentColorTheme);
396392

393+
if (settingsTarget === ConfigurationTarget.USER) {
394+
this.windowService.broadcast({ channel: 'vscode:changeBaseTheme', payload: newTheme.getBaseThemeId() });
395+
}
396+
397397
return this.writeColorThemeConfiguration(settingsTarget);
398398
};
399399

@@ -485,7 +485,7 @@ export class ThemeService implements IThemeService {
485485
let themeData = new ColorThemeData();
486486
themeData.id = `${baseTheme} ${themeSelector}`;
487487
themeData.label = theme.label || Paths.basename(theme.path);
488-
themeData.settingsId = settingsIdPrefix[baseTheme] + (theme.id || themeData.label);
488+
themeData.settingsId = theme.id || themeData.label;
489489
themeData.description = theme.description;
490490
themeData.path = normalizedAbsolutePath;
491491
themeData.extensionData = extensionData;

0 commit comments

Comments
 (0)