提交 a7caa978 编写于 作者: M Martin Aeschlimann

OSColorScheme: Separate dark and hc

上级 7c20f505
......@@ -35,7 +35,6 @@ import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifec
import { IStorageMainService } from 'vs/platform/storage/node/storageMainService';
import { IFileService } from 'vs/platform/files/common/files';
import { FileAccess, Schemas } from 'vs/base/common/network';
import { ColorScheme } from 'vs/platform/theme/common/theme';
export interface IWindowCreationOptions {
state: IWindowState;
......@@ -784,7 +783,10 @@ export class CodeWindow extends Disposable implements ICodeWindow {
windowConfiguration.fullscreen = this.isFullScreen;
// Set Accessibility Config
windowConfiguration.colorScheme = (nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors) ? ColorScheme.HIGH_CONTRAST : nativeTheme.shouldUseDarkColors ? ColorScheme.DARK : ColorScheme.LIGHT;
windowConfiguration.colorScheme = {
dark: nativeTheme.shouldUseDarkColors,
highContrast: nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors
};
windowConfiguration.autoDetectHighContrast = windowConfig?.autoDetectHighContrast ?? true;
windowConfiguration.accessibilitySupport = app.accessibilitySupportEnabled;
......
......@@ -5,10 +5,9 @@
import { Event } from 'vs/base/common/event';
import { MessageBoxOptions, MessageBoxReturnValue, OpenDevToolsOptions, SaveDialogOptions, OpenDialogOptions, OpenDialogReturnValue, SaveDialogReturnValue, MouseInputEvent } from 'vs/base/parts/sandbox/common/electronTypes';
import { IOpenedWindow, IWindowOpenable, IOpenEmptyWindowOptions, IOpenWindowOptions } from 'vs/platform/windows/common/windows';
import { IOpenedWindow, IWindowOpenable, IOpenEmptyWindowOptions, IOpenWindowOptions, IColorScheme } from 'vs/platform/windows/common/windows';
import { INativeOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { ISerializableCommandAction } from 'vs/platform/actions/common/actions';
import { ColorScheme } from 'vs/platform/theme/common/theme';
import { URI } from 'vs/base/common/uri';
export interface ICPUProperties {
......@@ -48,7 +47,7 @@ export interface ICommonNativeHostService {
readonly onOSResume: Event<unknown>;
readonly onColorSchemeChange: Event<ColorScheme>;
readonly onColorSchemeChange: Event<IColorScheme>;
// Window
getWindows(): Promise<IOpenedWindow[]>;
......
......@@ -8,7 +8,7 @@ import { IWindowsMainService, ICodeWindow } from 'vs/platform/windows/electron-m
import { MessageBoxOptions, MessageBoxReturnValue, shell, OpenDevToolsOptions, SaveDialogOptions, SaveDialogReturnValue, OpenDialogOptions, OpenDialogReturnValue, Menu, BrowserWindow, app, clipboard, powerMonitor, nativeTheme } from 'electron';
import { OpenContext } from 'vs/platform/windows/node/window';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { IOpenedWindow, IOpenWindowOptions, IWindowOpenable, IOpenEmptyWindowOptions } from 'vs/platform/windows/common/windows';
import { IOpenedWindow, IOpenWindowOptions, IWindowOpenable, IOpenEmptyWindowOptions, IColorScheme } from 'vs/platform/windows/common/windows';
import { INativeOpenDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { isMacintosh, isWindows, isRootUser, isLinux } from 'vs/base/common/platform';
import { ICommonNativeHostService, IOSProperties, IOSStatistics } from 'vs/platform/native/common/native';
......@@ -22,7 +22,6 @@ import { ITelemetryData, ITelemetryService } from 'vs/platform/telemetry/common/
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { MouseInputEvent } from 'vs/base/parts/sandbox/common/electronTypes';
import { arch, totalmem, release, platform, type, loadavg, freemem, cpus } from 'os';
import { ColorScheme } from 'vs/platform/theme/common/theme';
import { virtualMachineHint } from 'vs/base/node/id';
import { ILogService } from 'vs/platform/log/common/log';
import { dirname, join } from 'vs/base/common/path';
......@@ -52,16 +51,10 @@ export class NativeHostMainService implements INativeHostMainService {
// Color Scheme changes
nativeTheme.on('updated', () => {
let colorScheme: ColorScheme;
if (nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors) {
colorScheme = ColorScheme.HIGH_CONTRAST;
} else if (nativeTheme.shouldUseDarkColors) {
colorScheme = ColorScheme.DARK;
} else {
colorScheme = ColorScheme.LIGHT;
}
this._onColorSchemeChange.fire(colorScheme);
this._onColorSchemeChange.fire({
highContrast: nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors,
dark: nativeTheme.shouldUseDarkColors
});
});
}
......@@ -87,7 +80,7 @@ export class NativeHostMainService implements INativeHostMainService {
readonly onOSResume = Event.fromNodeEventEmitter(powerMonitor, 'resume');
private readonly _onColorSchemeChange = new Emitter<ColorScheme>();
private readonly _onColorSchemeChange = new Emitter<IColorScheme>();
readonly onColorSchemeChange = this._onColorSchemeChange.event;
//#endregion
......
......@@ -11,7 +11,6 @@ import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platf
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
import { LogLevel } from 'vs/platform/log/common/log';
import { ExportData } from 'vs/base/common/performance';
import { ColorScheme } from 'vs/platform/theme/common/theme';
export const WindowMinimumSize = {
WIDTH: 400,
......@@ -213,12 +212,17 @@ export interface INativeRunKeybindingInWindowRequest {
userSettingsLabel: string;
}
export interface IColorScheme {
dark: boolean;
highContrast: boolean;
}
export interface IWindowConfiguration {
sessionId: string;
remoteAuthority?: string;
colorScheme: ColorScheme;
colorScheme: IColorScheme;
autoDetectHighContrast?: boolean;
filesToOpenOrCreate?: IPath[];
......
......@@ -15,7 +15,6 @@ import { IProductService } from 'vs/platform/product/common/productService';
import { memoize } from 'vs/base/common/decorators';
import { onUnexpectedError } from 'vs/base/common/errors';
import { parseLineAndColumnAware } from 'vs/base/common/extpath';
import { ColorScheme } from 'vs/platform/theme/common/theme';
class BrowserWorkbenchConfiguration implements IWindowConfiguration {
......@@ -72,7 +71,7 @@ class BrowserWorkbenchConfiguration implements IWindowConfiguration {
}
get colorScheme() {
return ColorScheme.LIGHT;
return { dark: false, highContrast: false };
}
}
......
......@@ -8,7 +8,6 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { Disposable } from 'vs/base/common/lifecycle';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService';
import { ColorScheme } from 'vs/platform/theme/common/theme';
export class BrowserHostColorSchemeService extends Disposable implements IHostColorSchemeService {
......@@ -38,15 +37,20 @@ export class BrowserHostColorSchemeService extends Disposable implements IHostCo
return this._onDidSchemeChangeEvent.event;
}
get colorScheme(): ColorScheme {
if (window.matchMedia(`(forced-colors: active)`).matches) {
return ColorScheme.HIGH_CONTRAST;
} else if (window.matchMedia(`(prefers-color-scheme: light)`).matches) {
return ColorScheme.LIGHT;
get dark(): boolean {
if (window.matchMedia(`(prefers-color-scheme: light)`).matches) {
return false;
} else if (window.matchMedia(`(prefers-color-scheme: dark)`).matches) {
return ColorScheme.DARK;
return true;
}
return this.environmentService.configuration.colorScheme.dark;
}
get highContrast(): boolean {
if (window.matchMedia(`(forced-colors: active)`).matches) {
return true;
}
return this.environmentService.configuration.colorScheme;
return this.environmentService.configuration.colorScheme.highContrast;
}
}
......
......@@ -363,15 +363,11 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
}
private getPreferredColorScheme(): ColorScheme | undefined {
const detectHCThemeSetting = this.configurationService.getValue<boolean>(ThemeSettings.DETECT_HC);
if (this.hostColorService.colorScheme === ColorScheme.HIGH_CONTRAST && detectHCThemeSetting) {
if (this.configurationService.getValue<boolean>(ThemeSettings.DETECT_HC) && this.hostColorService.highContrast) {
return ColorScheme.HIGH_CONTRAST;
}
if (this.configurationService.getValue<boolean>(ThemeSettings.DETECT_COLOR_SCHEME)) {
const osScheme = this.hostColorService.colorScheme;
if (osScheme !== ColorScheme.HIGH_CONTRAST) {
return osScheme;
}
return this.hostColorService.dark ? ColorScheme.DARK : ColorScheme.LIGHT;
}
return undefined;
}
......
......@@ -5,7 +5,6 @@
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ColorScheme } from 'vs/platform/theme/common/theme';
export const IHostColorSchemeService = createDecorator<IHostColorSchemeService>('hostColorSchemeService');
......@@ -13,7 +12,8 @@ export interface IHostColorSchemeService {
readonly _serviceBrand: undefined;
readonly colorScheme: ColorScheme;
readonly dark: boolean;
readonly highContrast: boolean;
readonly onDidChangeColorScheme: Event<void>;
}
......@@ -8,7 +8,6 @@ import { INativeHostService } from 'vs/platform/native/electron-sandbox/native';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { Disposable } from 'vs/base/common/lifecycle';
import { ColorScheme } from 'vs/platform/theme/common/theme';
import { IHostColorSchemeService } from 'vs/workbench/services/themes/common/hostColorSchemeService';
export class NativeHostColorSchemeService extends Disposable implements IHostColorSchemeService {
......@@ -27,9 +26,9 @@ export class NativeHostColorSchemeService extends Disposable implements IHostCol
private registerListeners(): void {
// Color Scheme
this._register(this.nativeHostService.onColorSchemeChange(scheme => {
this._colorScheme = scheme;
this._register(this.nativeHostService.onColorSchemeChange(({ highContrast, dark }) => {
this.dark = dark;
this.highContrast = highContrast;
this._onDidChangeColorScheme.fire();
}));
}
......@@ -37,8 +36,8 @@ export class NativeHostColorSchemeService extends Disposable implements IHostCol
private readonly _onDidChangeColorScheme = this._register(new Emitter<void>());
readonly onDidChangeColorScheme = this._onDidChangeColorScheme.event;
private _colorScheme: ColorScheme = this.environmentService.configuration.colorScheme;
get colorScheme() { return this._colorScheme; }
public dark: boolean = this.environmentService.configuration.colorScheme.dark;
public highContrast: boolean = this.environmentService.configuration.colorScheme.highContrast;
}
......
......@@ -40,7 +40,6 @@ import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/ur
import { MouseInputEvent } from 'vs/base/parts/sandbox/common/electronTypes';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IOSProperties, IOSStatistics } from 'vs/platform/native/common/native';
import { ColorScheme } from 'vs/platform/theme/common/theme';
import { homedir } from 'os';
export const TestWorkbenchConfiguration: INativeWorkbenchConfiguration = {
......@@ -54,7 +53,7 @@ export const TestWorkbenchConfiguration: INativeWorkbenchConfiguration = {
userEnv: {},
execPath: process.execPath,
perfEntries: [],
colorScheme: ColorScheme.DARK,
colorScheme: { dark: true, highContrast: false },
...parseArgs(process.argv, OPTIONS)
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册