Skip to content

Commit 438a141

Browse files
author
Benjamin Pasero
committed
electron - avoid more deprecated API (themes)
1 parent 502f5a5 commit 438a141

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as objects from 'vs/base/common/objects';
88
import * as nls from 'vs/nls';
99
import { Event as CommonEvent, Emitter } from 'vs/base/common/event';
1010
import { URI } from 'vs/base/common/uri';
11-
import { screen, BrowserWindow, systemPreferences, app, TouchBar, nativeImage, Rectangle, Display, TouchBarSegmentedControl, NativeImage, BrowserWindowConstructorOptions, SegmentedControlSegment } from 'electron';
11+
import { screen, BrowserWindow, systemPreferences, app, TouchBar, nativeImage, Rectangle, Display, TouchBarSegmentedControl, NativeImage, BrowserWindowConstructorOptions, SegmentedControlSegment, nativeTheme } from 'electron';
1212
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
1313
import { ILogService } from 'vs/platform/log/common/log';
1414
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -648,7 +648,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
648648
if (windowConfig?.autoDetectHighContrast === false) {
649649
autoDetectHighContrast = false;
650650
}
651-
windowConfiguration.highContrast = isWindows && autoDetectHighContrast && systemPreferences.isInvertedColorScheme();
651+
windowConfiguration.highContrast = isWindows && autoDetectHighContrast && nativeTheme.shouldUseInvertedColorScheme;
652652
windowConfiguration.accessibilitySupport = app.accessibilitySupportEnabled;
653653

654654
// Title style related

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { isWindows, isMacintosh } from 'vs/base/common/platform';
7-
import { systemPreferences, ipcMain as ipc } from 'electron';
7+
import { systemPreferences, ipcMain as ipc, nativeTheme } from 'electron';
88
import { IStateService } from 'vs/platform/state/node/state';
99
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1010

@@ -42,14 +42,14 @@ export class ThemeMainService implements IThemeMainService {
4242
}
4343

4444
getBackgroundColor(): string {
45-
if (isWindows && systemPreferences.isInvertedColorScheme()) {
45+
if (isWindows && nativeTheme.shouldUseInvertedColorScheme) {
4646
return DEFAULT_BG_HC_BLACK;
4747
}
4848

4949
let background = this.stateService.getItem<string | null>(THEME_BG_STORAGE_KEY, null);
5050
if (!background) {
5151
let baseTheme: string;
52-
if (isWindows && systemPreferences.isInvertedColorScheme()) {
52+
if (isWindows && nativeTheme.shouldUseInvertedColorScheme) {
5353
baseTheme = 'hc-black';
5454
} else {
5555
baseTheme = this.stateService.getItem<string>(THEME_STORAGE_KEY, 'vs-dark').split(' ')[0];

src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IEmptyWindowBackupInfo } from 'vs/platform/backup/node/backup';
1313
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
1414
import { IStateService } from 'vs/platform/state/node/state';
1515
import { CodeWindow, defaultWindowState } from 'vs/code/electron-main/window';
16-
import { ipcMain as ipc, screen, BrowserWindow, systemPreferences, MessageBoxOptions, Display, app } from 'electron';
16+
import { ipcMain as ipc, screen, BrowserWindow, MessageBoxOptions, Display, app, nativeTheme } from 'electron';
1717
import { parseLineAndColumnAware } from 'vs/code/node/paths';
1818
import { ILifecycleMainService, UnloadReason, LifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
1919
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -226,16 +226,13 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
226226

227227
// React to HC color scheme changes (Windows)
228228
if (isWindows) {
229-
const onHighContrastChange = () => {
230-
if (systemPreferences.isInvertedColorScheme() || systemPreferences.isHighContrastColorScheme()) {
229+
nativeTheme.on('updated', () => {
230+
if (nativeTheme.shouldUseInvertedColorScheme || nativeTheme.shouldUseHighContrastColors) {
231231
this.sendToAll('vscode:enterHighContrast');
232232
} else {
233233
this.sendToAll('vscode:leaveHighContrast');
234234
}
235-
};
236-
237-
systemPreferences.on('inverted-color-scheme-changed', () => onHighContrastChange());
238-
systemPreferences.on('high-contrast-color-scheme-changed', () => onHighContrastChange());
235+
});
239236
}
240237

241238
// When a window looses focus, save all windows state. This allows to

0 commit comments

Comments
 (0)