fix(graph): don't listen to system theme changes in console (#22938)

This commit is contained in:
MaxKless 2024-04-23 03:59:07 +02:00 committed by GitHub
parent f5327b4baa
commit b37bfdb1af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,5 @@
import { getEnvironmentConfig } from '@nx/graph/shared';
const htmlEl = document.documentElement;
export const localStorageThemeKey = 'nx-dep-graph-theme';
export type Theme = 'light' | 'dark' | 'system';
@ -48,6 +50,10 @@ export function getSystemTheme(): 'light' | 'dark' {
if (isVSCodeDark || isVSCodeLight) {
return isVSCodeDark ? 'dark' : 'light';
}
// we don't want to use system theme in nx-console because it might conflict with the IDE theme
if (getEnvironmentConfig().environment === 'nx-console') {
return 'light';
}
const isDarkMedia = window.matchMedia('(prefers-color-scheme: dark)').matches;
return isDarkMedia || isVSCodeDark ? 'dark' : 'light';
}
@ -65,8 +71,9 @@ export function themeResolver(theme: Theme) {
currentTheme = theme;
} else {
const resolver = getSystemTheme();
if (getEnvironmentConfig().environment !== 'nx-console') {
darkMedia.addEventListener('change', mediaListener);
}
vscodeDarkOberserver.observe(document.body, {
attributes: true,
attributeFilter: ['class'],