microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
src/common/editorColorThemesHelper.ts
30lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | |
| 4 | import * as vscode from "vscode"; |
| 5 | |
| 6 | export enum SystemColorTheme { |
| 7 | Light = "Light", |
| 8 | Dark = "Dark", |
| 9 | } |
| 10 | |
| 11 | export class EditorColorThemesHelper { |
| 12 | public static isAutoDetectColorSchemeEnabled(): boolean { |
| 13 | return !!vscode.workspace.getConfiguration("window").get("autoDetectColorScheme"); |
| 14 | } |
| 15 | |
| 16 | public static getCurrentSystemColorTheme(): SystemColorTheme { |
| 17 | if (EditorColorThemesHelper.isAutoDetectColorSchemeEnabled()) { |
| 18 | const workbenchConfiguration = vscode.workspace.getConfiguration("workbench"); |
| 19 | const currentTheme = workbenchConfiguration.get("colorTheme"); |
| 20 | const preferredDarkColorTheme = workbenchConfiguration.get("preferredDarkColorTheme"); |
| 21 | return currentTheme === preferredDarkColorTheme |
| 22 | ? SystemColorTheme.Dark |
| 23 | : SystemColorTheme.Light; |
| 24 | } else { |
| 25 | throw new Error( |
| 26 | "Couldn't detect the current system color theme: 'window.autoDetectColorScheme' parameter is disabled", |
| 27 | ); |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |