mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
[theme] store baseTheme in storage
This commit is contained in:
parent
acdb4e941a
commit
de73b28025
|
@ -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<string>('workbench.colorTheme').value;
|
||||
const usesLightTheme = /^l-/.test(themeId);
|
||||
const usesHighContrastTheme = /^hc-/.test(themeId) || (platform.isWindows && systemPreferences.isInvertedColorScheme());
|
||||
const baseTheme = this.storageService.getItem<string>(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<string>('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<string>(VSCodeWindow.baseThemeStorageKey, 'vs-dark');
|
||||
windowConfiguration.baseTheme = baseTheme;
|
||||
|
||||
// Perf Counters
|
||||
windowConfiguration.perfStartTime = global.perfStartTime;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue