Skip to content

Commit 0ed0a9f

Browse files
authored
ignore window.systemColorTheme when window.autoDetectColorScheme is enabled (microsoft#211265)
* ignore window.systemColorTheme when window.autoDetectColorScheme is enabled * remove import
1 parent 1d25a86 commit 0ed0a9f

File tree

5 files changed

+71
-51
lines changed

5 files changed

+71
-51
lines changed

src/vs/platform/theme/electron-main/themeMainService.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const THEME_STORAGE_KEY = 'theme';
2222
const THEME_BG_STORAGE_KEY = 'themeBackground';
2323
const THEME_WINDOW_SPLASH = 'windowSplash';
2424

25-
const SYSTEM_COLOR_THEME = 'window.systemColorTheme';
25+
namespace ThemeSettings {
26+
export const DETECT_COLOR_SCHEME = 'window.autoDetectColorScheme';
27+
export const SYSTEM_COLOR_THEME = 'window.systemColorTheme';
28+
}
2629

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

@@ -51,35 +54,43 @@ export class ThemeMainService extends Disposable implements IThemeMainService {
5154
super();
5255

5356
// System Theme
54-
this._register(this.configurationService.onDidChangeConfiguration(e => {
55-
if (e.affectsConfiguration(SYSTEM_COLOR_THEME)) {
56-
this.updateSystemColorTheme();
57-
}
58-
}));
57+
if (!isLinux) {
58+
this._register(this.configurationService.onDidChangeConfiguration(e => {
59+
if (e.affectsConfiguration(ThemeSettings.SYSTEM_COLOR_THEME) || e.affectsConfiguration(ThemeSettings.DETECT_COLOR_SCHEME)) {
60+
this.updateSystemColorTheme();
61+
}
62+
}));
63+
}
5964
this.updateSystemColorTheme();
6065

6166
// Color Scheme changes
6267
this._register(Event.fromNodeEventEmitter(nativeTheme, 'updated')(() => this._onDidChangeColorScheme.fire(this.getColorScheme())));
6368
}
6469

6570
private updateSystemColorTheme(): void {
66-
switch (this.configurationService.getValue<'default' | 'matchColorTheme' | 'light' | 'dark'>(SYSTEM_COLOR_THEME)) {
67-
case 'dark':
68-
nativeTheme.themeSource = 'dark';
69-
break;
70-
case 'light':
71-
nativeTheme.themeSource = 'light';
72-
break;
73-
case 'matchColorTheme':
74-
switch (this.getBaseTheme()) {
75-
case 'vs': nativeTheme.themeSource = 'light'; break;
76-
case 'vs-dark': nativeTheme.themeSource = 'dark'; break;
77-
default: nativeTheme.themeSource = 'system';
78-
}
79-
break;
80-
default:
81-
nativeTheme.themeSource = 'system';
82-
break;
71+
if (isLinux || this.configurationService.getValue(ThemeSettings.DETECT_COLOR_SCHEME)) {
72+
// only with `system` we can detect the system color scheme
73+
nativeTheme.themeSource = 'system';
74+
} else {
75+
switch (this.configurationService.getValue<'default' | 'auto' | 'light' | 'dark'>(ThemeSettings.SYSTEM_COLOR_THEME)) {
76+
case 'dark':
77+
nativeTheme.themeSource = 'dark';
78+
break;
79+
case 'light':
80+
nativeTheme.themeSource = 'light';
81+
break;
82+
case 'auto':
83+
switch (this.getBaseTheme()) {
84+
case 'vs': nativeTheme.themeSource = 'light'; break;
85+
case 'vs-dark': nativeTheme.themeSource = 'dark'; break;
86+
default: nativeTheme.themeSource = 'system';
87+
}
88+
break;
89+
default:
90+
nativeTheme.themeSource = 'system';
91+
break;
92+
}
93+
8394
}
8495
}
8596

src/vs/workbench/contrib/themes/browser/themes.contribution.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import { IPreferencesService } from 'vs/workbench/services/preferences/common/pr
4949
import { Toggle } from 'vs/base/browser/ui/toggle/toggle';
5050
import { defaultToggleStyles } from 'vs/platform/theme/browser/defaultStyles';
5151
import { DisposableStore } from 'vs/base/common/lifecycle';
52-
import { COLOR_THEME_CONFIGURATION_SETTINGS_TAG } from 'vs/workbench/services/themes/common/themeConfiguration';
5352

5453
export const manageExtensionIcon = registerIcon('theme-selection-manage-extension', Codicon.gear, localize('manageExtensionIcon', 'Icon for the \'Manage\' action in the theme selection quick pick.'));
5554

@@ -425,12 +424,12 @@ registerAction2(class extends Action2 {
425424

426425
private getTitle(colorScheme: ColorScheme | undefined): string {
427426
switch (colorScheme) {
428-
case ColorScheme.DARK: return localize('themes.selectTheme.darkScheme', "Select Color Theme for Dark OS System Theme");
429-
case ColorScheme.LIGHT: return localize('themes.selectTheme.lightScheme', "Select Color Theme for Light OS System Theme");
430-
case ColorScheme.HIGH_CONTRAST_DARK: return localize('themes.selectTheme.darkHC', "Select Color Theme for Dark High Contrast Mode");
431-
case ColorScheme.HIGH_CONTRAST_LIGHT: return localize('themes.selectTheme.lightHC', "Select Color Theme for Light High Contrast Mode");
427+
case ColorScheme.DARK: return localize('themes.selectTheme.darkScheme', "Select Color Theme for System Dark Mode");
428+
case ColorScheme.LIGHT: return localize('themes.selectTheme.lightScheme', "Select Color Theme for System Light Mode");
429+
case ColorScheme.HIGH_CONTRAST_DARK: return localize('themes.selectTheme.darkHC', "Select Color Theme for High Contrast Dark Mode");
430+
case ColorScheme.HIGH_CONTRAST_LIGHT: return localize('themes.selectTheme.lightHC', "Select Color Theme for High Contrast Light Mode");
432431
default:
433-
return localize('themes.selectTheme.default', "Select Color Theme for all OS System Themes");
432+
return localize('themes.selectTheme.default', "Select Color Theme (detect system color mode disabled)");
434433
}
435434
}
436435

@@ -443,14 +442,14 @@ registerAction2(class extends Action2 {
443442
let modeConfigureToggle;
444443
if (preferredColorScheme) {
445444
modeConfigureToggle = new Toggle({
446-
title: localize('themes.configure.switchingEnabled', 'Configure themes for other OS system themes.'),
445+
title: localize('themes.configure.switchingEnabled', 'Detect system color mode enabled. Click to configure.'),
447446
icon: Codicon.colorMode,
448447
isChecked: false,
449448
...defaultToggleStyles
450449
});
451450
} else {
452451
modeConfigureToggle = new Toggle({
453-
title: localize('themes.configure.switchingDisabled', 'Configure themes switching based on the OS system theme.'),
452+
title: localize('themes.configure.switchingDisabled', 'Detect system color mode disabled. Click to configure.'),
454453
icon: Codicon.colorMode,
455454
isChecked: false,
456455
...defaultToggleStyles
@@ -465,7 +464,7 @@ registerAction2(class extends Action2 {
465464
toggles: [modeConfigureToggle],
466465
onToggle: async (toggle, picker) => {
467466
picker.hide();
468-
await preferencesService.openSettings({ query: `@tag:${COLOR_THEME_CONFIGURATION_SETTINGS_TAG}` });
467+
await preferencesService.openSettings({ query: ThemeSettings.DETECT_COLOR_SCHEME });
469468
}
470469
} satisfies InstalledThemesPickerOptions;
471470
const setTheme = (theme: IWorkbenchTheme | undefined, settingsTarget: ThemeSettingTarget) => themeService.setColorTheme(theme as IWorkbenchColorTheme, settingsTarget);
@@ -722,6 +721,21 @@ registerAction2(class extends Action2 {
722721
override async run(accessor: ServicesAccessor) {
723722
const themeService = accessor.get(IWorkbenchThemeService);
724723
const configurationService = accessor.get(IConfigurationService);
724+
const notificationService = accessor.get(INotificationService);
725+
const preferencesService = accessor.get(IPreferencesService);
726+
727+
if (configurationService.getValue(ThemeSettings.DETECT_COLOR_SCHEME)) {
728+
const message = localize({ key: 'cannotToggle', comment: ['{0} is a setting name'] }, "Cannot toggle between light and dark themes when `{0}` is enabled in settings.", ThemeSettings.DETECT_COLOR_SCHEME);
729+
notificationService.prompt(Severity.Info, message, [
730+
{
731+
label: localize('goToSetting', "Open Settings"),
732+
run: () => {
733+
return preferencesService.openUserSettings({ query: ThemeSettings.DETECT_COLOR_SCHEME });
734+
}
735+
}
736+
]);
737+
return;
738+
}
725739

726740
const currentTheme = themeService.getColorTheme();
727741
let newSettingsId: string = ThemeSettings.PREFERRED_DARK_THEME;

src/vs/workbench/services/themes/common/themeConfiguration.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
1212
import { textmateColorsSchemaId, textmateColorGroupSchemaId } from 'vs/workbench/services/themes/common/colorThemeSchema';
1313
import { workbenchColorsSchemaId } from 'vs/platform/theme/common/colorRegistry';
1414
import { tokenStylingSchemaId } from 'vs/platform/theme/common/tokenClassificationRegistry';
15-
import { ThemeSettings, IWorkbenchColorTheme, IWorkbenchFileIconTheme, IColorCustomizations, ITokenColorCustomizations, IWorkbenchProductIconTheme, ISemanticTokenColorCustomizations, ThemeSettingTarget, ThemeSettingDefaults, ENABLE_SYSTEM_COLOR_SCHEME_SETTING } from 'vs/workbench/services/themes/common/workbenchThemeService';
15+
import { ThemeSettings, IWorkbenchColorTheme, IWorkbenchFileIconTheme, IColorCustomizations, ITokenColorCustomizations, IWorkbenchProductIconTheme, ISemanticTokenColorCustomizations, ThemeSettingTarget, ThemeSettingDefaults } from 'vs/workbench/services/themes/common/workbenchThemeService';
1616
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
1717
import { isWeb } from 'vs/base/common/platform';
1818
import { ColorScheme } from 'vs/platform/theme/common/theme';
@@ -43,7 +43,7 @@ const colorThemeSettingSchema: IConfigurationPropertySchema = {
4343
};
4444
const preferredDarkThemeSettingSchema: IConfigurationPropertySchema = {
4545
type: 'string', //
46-
markdownDescription: nls.localize({ key: 'preferredDarkColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme when the system color is dark and {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
46+
markdownDescription: nls.localize({ key: 'preferredDarkColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme when system color mode is dark and {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
4747
default: ThemeSettingDefaults.COLOR_THEME_DARK,
4848
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
4949
enum: colorThemeSettingEnum,
@@ -53,7 +53,7 @@ const preferredDarkThemeSettingSchema: IConfigurationPropertySchema = {
5353
};
5454
const preferredLightThemeSettingSchema: IConfigurationPropertySchema = {
5555
type: 'string',
56-
markdownDescription: nls.localize({ key: 'preferredLightColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme when the system color is light and {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
56+
markdownDescription: nls.localize({ key: 'preferredLightColorTheme', comment: ['{0} will become a link to another setting.'] }, 'Specifies the color theme when system color mode is light and {0} is enabled.', formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
5757
default: ThemeSettingDefaults.COLOR_THEME_LIGHT,
5858
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
5959
enum: colorThemeSettingEnum,
@@ -83,10 +83,7 @@ const preferredHCLightThemeSettingSchema: IConfigurationPropertySchema = {
8383
};
8484
const detectColorSchemeSettingSchema: IConfigurationPropertySchema = {
8585
type: 'boolean',
86-
markdownDescription:
87-
nls.localize({ key: 'detectColorScheme', comment: ['{0} and {1} will become links to other settings.'] }, 'If enabled, will automatically select a color theme based on the OS system color. If the OS system color is dark, the theme specified at {0} is used, else {1}.', formatSettingAsLink(ThemeSettings.PREFERRED_DARK_THEME), formatSettingAsLink(ThemeSettings.PREFERRED_LIGHT_THEME))
88-
+ (ENABLE_SYSTEM_COLOR_SCHEME_SETTING ? nls.localize({ key: 'detectColorSchemeSys', comment: ['{0} will become a link to another setting.'] }, '\n\nThis setting is ignored if {0} is configured.', formatSettingAsLink(ThemeSettings.SYSTEM_COLOR_THEME)) : ''),
89-
86+
markdownDescription: nls.localize({ key: 'detectColorScheme', comment: ['{0} and {1} will become links to other settings.'] }, 'If enabled, will automatically select a color theme based on the system color mode. If the system color mode is dark, {0} is used, else {1}.', formatSettingAsLink(ThemeSettings.PREFERRED_DARK_THEME), formatSettingAsLink(ThemeSettings.PREFERRED_LIGHT_THEME)),
9087
default: false,
9188
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
9289
};
@@ -316,7 +313,7 @@ export class ThemeConfiguration {
316313
if (this.configurationService.getValue(ThemeSettings.DETECT_HC) && this.hostColorService.highContrast) {
317314
return this.hostColorService.dark ? ColorScheme.HIGH_CONTRAST_DARK : ColorScheme.HIGH_CONTRAST_LIGHT;
318315
}
319-
if (this.configurationService.getValue(ThemeSettings.DETECT_COLOR_SCHEME) && (!ENABLE_SYSTEM_COLOR_SCHEME_SETTING || this.configurationService.getValue(ThemeSettings.SYSTEM_COLOR_THEME) === 'default')) {
316+
if (this.configurationService.getValue(ThemeSettings.DETECT_COLOR_SCHEME)) {
320317
return this.hostColorService.dark ? ColorScheme.DARK : ColorScheme.LIGHT;
321318
}
322319
return undefined;

src/vs/workbench/services/themes/common/workbenchThemeService.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { ConfigurationTarget } from 'vs/platform/configuration/common/configurat
1111
import { isBoolean, isString } from 'vs/base/common/types';
1212
import { IconContribution, IconDefinition } from 'vs/platform/theme/common/iconRegistry';
1313
import { ColorScheme } from 'vs/platform/theme/common/theme';
14-
import { isLinux } from 'vs/base/common/platform';
1514

1615
export const IWorkbenchThemeService = refineServiceDecorator<IThemeService, IWorkbenchThemeService>(IThemeService);
1716

@@ -44,8 +43,6 @@ export enum ThemeSettings {
4443
SYSTEM_COLOR_THEME = 'window.systemColorTheme'
4544
}
4645

47-
export const ENABLE_SYSTEM_COLOR_SCHEME_SETTING = !isLinux;
48-
4946
export enum ThemeSettingDefaults {
5047
COLOR_THEME_DARK = 'Default Dark Modern',
5148
COLOR_THEME_LIGHT = 'Default Light Modern',

src/vs/workbench/services/themes/electron-sandbox/themes.contribution.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
import { localize } from 'vs/nls';
77
import { Registry } from 'vs/platform/registry/common/platform';
88
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
9-
import { ENABLE_SYSTEM_COLOR_SCHEME_SETTING, ThemeSettings } from 'vs/workbench/services/themes/common/workbenchThemeService';
9+
import { ThemeSettings } from 'vs/workbench/services/themes/common/workbenchThemeService';
1010
import { COLOR_THEME_CONFIGURATION_SETTINGS_TAG, formatSettingAsLink } from 'vs/workbench/services/themes/common/themeConfiguration';
11+
import { isLinux } from 'vs/base/common/platform';
1112

1213
const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
1314
configurationRegistry.registerConfiguration({
1415
properties: {
1516
[ThemeSettings.SYSTEM_COLOR_THEME]: {
1617
type: 'string',
17-
enum: ['default', 'matchColorTheme', 'light', 'dark'],
18+
enum: ['default', 'auto', 'light', 'dark'],
1819
enumDescriptions: [
19-
localize('window.systemColorTheme.default', "System color theme matches the configured OS theme."),
20-
localize('window.systemColorTheme.matchColorTheme', "Enforce a light system color theme when a light workbench color theme is configured and the same for configured dark workbench color themes."),
21-
localize('window.systemColorTheme.light', "Enforce a light system color theme."),
22-
localize('window.systemColorTheme.dark', "Enforce a dark system color theme."),
20+
localize('window.systemColorTheme.default', "Native widget colors match the system colors."),
21+
localize('window.systemColorTheme.auto', "Use light native widget colors for light color themes and dark for dark color themes."),
22+
localize('window.systemColorTheme.light', "Use light native widget colors."),
23+
localize('window.systemColorTheme.dark', "Use dark native widget colors."),
2324
],
24-
markdownDescription: localize({ key: 'window.systemColorTheme', comment: ['{0} and {1} will become links to other settings.'] }, "Overrides the system color theme that is used for native UI elements such as native dialogs, menus and title bar. Even if your OS is configured in light appearance mode, you can select a dark system color theme for the window. You can also configure to automatically adjust based on the {0} setting. Note: Using this setting will disable {1}.", formatSettingAsLink(ThemeSettings.COLOR_THEME), formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
25+
markdownDescription: localize({ key: 'window.systemColorTheme', comment: ['{0} and {1} will become links to other settings.'] }, "Set the color mode for native UI elements such as native dialogs, menus and title bar. Even if your OS is configured in light color mode, you can select a dark system color theme for the window. You can also configure to automatically adjust based on the {0} setting.\n\nNote: This setting is ignored when {1} is enabled.", formatSettingAsLink(ThemeSettings.COLOR_THEME), formatSettingAsLink(ThemeSettings.DETECT_COLOR_SCHEME)),
2526
default: 'default',
26-
included: ENABLE_SYSTEM_COLOR_SCHEME_SETTING,
27+
included: !isLinux,
2728
scope: ConfigurationScope.APPLICATION,
2829
tags: [COLOR_THEME_CONFIGURATION_SETTINGS_TAG],
2930
}

0 commit comments

Comments
 (0)