From 1364d3a8ba60b15c2a33ae32f9ab2cf928384169 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 18 Feb 2022 06:03:52 +0300 Subject: [PATCH] add colorScheme.isDark() --- background/color-scheme.js | 13 ++++++------- js/dark-themer.js | 3 +-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/background/color-scheme.js b/background/color-scheme.js index 1c389623..95553f3c 100644 --- a/background/color-scheme.js +++ b/background/color-scheme.js @@ -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); diff --git a/js/dark-themer.js b/js/dark-themer.js index 04bf1a28..049c899a 100644 --- a/js/dark-themer.js +++ b/js/dark-themer.js @@ -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') {