css: Change mode detection to look for `@light-mode`
This commit is contained in:
parent
55330c81c4
commit
74971359a3
|
@ -213,12 +213,8 @@ class PreferenceForm extends Form
|
||||||
if (isset($formData['theme']) && $formData['theme'] !== StyleSheet::DEFAULT_THEME) {
|
if (isset($formData['theme']) && $formData['theme'] !== StyleSheet::DEFAULT_THEME) {
|
||||||
$themeFile = StyleSheet::getThemeFile($formData['theme']);
|
$themeFile = StyleSheet::getThemeFile($formData['theme']);
|
||||||
$file = $themeFile !== null ? @file_get_contents($themeFile) : false;
|
$file = $themeFile !== null ? @file_get_contents($themeFile) : false;
|
||||||
if ($file && ! preg_match(StyleSheet::REGEX_ALL_MODE_QUERY, $file)) {
|
if ($file && strpos($file, StyleSheet::LIGHT_MODE_IDENTIFIER) === false) {
|
||||||
$disabled = ['', 'light', 'system'];
|
$disabled = ['', 'light', 'system'];
|
||||||
if (preg_match(StyleSheet::REGEX_AUTO_MODE_QUERY, $file)) {
|
|
||||||
$value = 'system';
|
|
||||||
$disabled = ['', 'light'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,19 +41,11 @@ class StyleSheet
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RegEx pattern for matching full css @media query of theme mode
|
* Sequence that signals that a theme supports light mode
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
const REGEX_ALL_MODE_QUERY = '/@media\s*\(\s*min-height\s*:\s*@prefer-light-color-scheme\s*\)\s*,' .
|
const LIGHT_MODE_IDENTIFIER = '@light-mode:';
|
||||||
'\s*\(\s*prefers-color-scheme\s*:\s*light\s*\)\s*and\s*\(\s*min-height\s*:\s*@enable-color-preference\s*\)/';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RegEx pattern for matching css @media query of theme mode
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const REGEX_AUTO_MODE_QUERY = '/@media.*prefers-color-scheme/';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of core LESS files Web 2 sends to the client
|
* Array of core LESS files Web 2 sends to the client
|
||||||
|
@ -178,12 +170,8 @@ class StyleSheet
|
||||||
|
|
||||||
$mode = 'none';
|
$mode = 'none';
|
||||||
if ($user = Auth::getInstance()->getUser()) {
|
if ($user = Auth::getInstance()->getUser()) {
|
||||||
$file = $themePath !== null ? @file_get_contents($themePath) : '';
|
$file = $themePath !== null ? @file_get_contents($themePath) : false;
|
||||||
if ($file && $file !== '' && ! preg_match(self::REGEX_ALL_MODE_QUERY, $file)) {
|
if (! $file || strpos($file, self::LIGHT_MODE_IDENTIFIER) !== false) {
|
||||||
if (preg_match(self::REGEX_AUTO_MODE_QUERY, $file)) {
|
|
||||||
$mode = 'system';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$mode = $user->getPreferences()->getValue('icingaweb', 'theme_mode', self::DEFAULT_MODE);
|
$mode = $user->getPreferences()->getValue('icingaweb', 'theme_mode', self::DEFAULT_MODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue