add colorScheme.isDark()

This commit is contained in:
tophf 2022-02-18 06:03:52 +03:00
parent bef70f6db3
commit 1364d3a8ba
2 changed files with 7 additions and 9 deletions

View File

@ -34,13 +34,12 @@ const colorScheme = (() => {
onChange(listener) {
changeListeners.add(listener);
},
/** @param {StyleObj | 'darkUI'} val - the string is used by the built-in dark themer */
shouldIncludeStyle(val) {
return val === 'darkUI'
? isDarkNow
: prefs.get(kSTATE) === 'never' ||
!SCHEMES.includes(val = val.preferScheme) ||
isDarkNow === (val === 'dark');
isDark: () => isDarkNow,
/** @param {StyleObj} _ */
shouldIncludeStyle({preferScheme: ps}) {
return prefs.get(kSTATE) === 'never' ||
!SCHEMES.includes(ps) ||
isDarkNow === (ps === 'dark');
},
updateSystemPreferDark(val) {
update('system', val);

View File

@ -11,11 +11,10 @@
* and not even a problem in the most popular case of using system dark/light mode.
*/
API.colorScheme.shouldIncludeStyle('darkUI').then(val => {
API.colorScheme.isDark().then(isDark => {
const ON = 'screen';
const OFF = 'not all';
const map = {[ON]: true, [OFF]: false};
let isDark = val;
toggleDarkStyles();
msg.onExtension(e => {
if (e.method === 'colorScheme') {