Skip to content

Commit 4b48304

Browse files
authored
theme service: adopt storage scopes (microsoft#152838)
1 parent 315bccd commit 4b48304

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const DEFAULT_COLOR_THEME_ID = 'vs-dark vscode-theme-defaults-themes-dark_plus-j
4848
const DEFAULT_LIGHT_COLOR_THEME_ID = 'vs vscode-theme-defaults-themes-light_plus-json';
4949

5050
const PERSISTED_OS_COLOR_SCHEME = 'osColorScheme';
51+
const PERSISTED_OS_COLOR_SCHEME_SCOPE = StorageScope.APPLICATION; // the OS scheme depends on settings in the OS
5152

5253
const defaultThemeExtensionId = 'vscode-theme-defaults';
5354

@@ -151,7 +152,7 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
151152
// the preferred color scheme (high contrast, light, dark) has changed since the last start
152153
const preferredColorScheme = this.getPreferredColorScheme();
153154

154-
if (preferredColorScheme && themeData?.type !== preferredColorScheme && this.storageService.get(PERSISTED_OS_COLOR_SCHEME, StorageScope.PROFILE) !== preferredColorScheme) {
155+
if (preferredColorScheme && themeData?.type !== preferredColorScheme && this.storageService.get(PERSISTED_OS_COLOR_SCHEME, PERSISTED_OS_COLOR_SCHEME_SCOPE) !== preferredColorScheme) {
155156
themeData = ColorThemeData.createUnloadedThemeForThemeType(preferredColorScheme);
156157
}
157158
if (!themeData) {
@@ -209,9 +210,9 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
209210
const theme = this.colorThemeRegistry.findThemeBySettingsId(this.settings.colorTheme, fallbackTheme);
210211

211212
const preferredColorScheme = this.getPreferredColorScheme();
212-
const prevScheme = this.storageService.get(PERSISTED_OS_COLOR_SCHEME, StorageScope.PROFILE);
213+
const prevScheme = this.storageService.get(PERSISTED_OS_COLOR_SCHEME, PERSISTED_OS_COLOR_SCHEME_SCOPE);
213214
if (preferredColorScheme !== prevScheme) {
214-
this.storageService.store(PERSISTED_OS_COLOR_SCHEME, preferredColorScheme, StorageScope.PROFILE, StorageTarget.USER);
215+
this.storageService.store(PERSISTED_OS_COLOR_SCHEME, preferredColorScheme, PERSISTED_OS_COLOR_SCHEME_SCOPE, StorageTarget.USER);
215216
if (preferredColorScheme && theme?.type !== preferredColorScheme) {
216217
return this.applyPreferredColorTheme(preferredColorScheme);
217218
}
@@ -372,9 +373,9 @@ export class WorkbenchThemeService implements IWorkbenchThemeService {
372373

373374
private async handlePreferredSchemeUpdated() {
374375
const scheme = this.getPreferredColorScheme();
375-
const prevScheme = this.storageService.get(PERSISTED_OS_COLOR_SCHEME, StorageScope.PROFILE);
376+
const prevScheme = this.storageService.get(PERSISTED_OS_COLOR_SCHEME, PERSISTED_OS_COLOR_SCHEME_SCOPE);
376377
if (scheme !== prevScheme) {
377-
this.storageService.store(PERSISTED_OS_COLOR_SCHEME, scheme, StorageScope.PROFILE, StorageTarget.MACHINE);
378+
this.storageService.store(PERSISTED_OS_COLOR_SCHEME, scheme, PERSISTED_OS_COLOR_SCHEME_SCOPE, StorageTarget.MACHINE);
378379
if (scheme) {
379380
if (!prevScheme) {
380381
// remember the theme before scheme switching

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class NativeHostColorSchemeService extends Disposable implements IHostCol
4444
}
4545

4646
private getStoredValue(): IColorScheme | undefined {
47-
const stored = this.storageService.get(NativeHostColorSchemeService.STORAGE_KEY, StorageScope.PROFILE);
47+
const stored = this.storageService.get(NativeHostColorSchemeService.STORAGE_KEY, StorageScope.APPLICATION);
4848
if (stored) {
4949
try {
5050
const scheme = JSON.parse(stored);
@@ -63,7 +63,7 @@ export class NativeHostColorSchemeService extends Disposable implements IHostCol
6363

6464
this.dark = dark;
6565
this.highContrast = highContrast;
66-
this.storageService.store(NativeHostColorSchemeService.STORAGE_KEY, JSON.stringify({ highContrast, dark }), StorageScope.PROFILE, StorageTarget.MACHINE);
66+
this.storageService.store(NativeHostColorSchemeService.STORAGE_KEY, JSON.stringify({ highContrast, dark }), StorageScope.APPLICATION, StorageTarget.MACHINE);
6767
this._onDidChangeColorScheme.fire();
6868
}
6969
}

0 commit comments

Comments
 (0)