From 259c7398cbd55ad3fa98a81f74baabef1c42283f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 28 Nov 2021 19:38:42 +0530 Subject: [PATCH] Viewer: Fix the color of browser provided controls in dark mode --- src/pyj/book_list/theme.pyj | 3 ++- src/pyj/read_book/settings.pyj | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pyj/book_list/theme.pyj b/src/pyj/book_list/theme.pyj index b857156155..622b9f4422 100644 --- a/src/pyj/book_list/theme.pyj +++ b/src/pyj/book_list/theme.pyj @@ -74,6 +74,7 @@ def set_ui_colors(is_dark_theme): s.setProperty('--calibre-color-' + k, val) get_color_as_rgba.cache = {} cached_color_to_rgba.cache = {} + document.documentElement.style.colorScheme = 'dark' if is_dark_theme else 'light' def browser_in_dark_mode(): @@ -96,7 +97,7 @@ def css_for_variables(): for k in DEFAULT_COLORS: val = DEFAULT_COLORS[k][attr] ans.push(f'--calibre-color-{k}: {val};') - return ':root { ' + ans.join('\n') + '}\n\n' + input_css + return f':root {{ color-scheme: {attr}; ' + ans.join('\n') + '}\n\n' + input_css def get_color(name): diff --git a/src/pyj/read_book/settings.pyj b/src/pyj/read_book/settings.pyj index 3bce4523c3..4ce39e2f29 100644 --- a/src/pyj/read_book/settings.pyj +++ b/src/pyj/read_book/settings.pyj @@ -61,6 +61,7 @@ def apply_colors(is_content_popup): des = document.documentElement.style des.setProperty('--calibre-viewer-background-color', opts.color_scheme.background) des.setProperty('--calibre-viewer-foreground-color', opts.color_scheme.foreground) + des.colorScheme = 'dark' if opts.is_dark_theme else 'light' if opts.color_scheme.link: des.setProperty('--calibre-viewer-link-color', opts.color_scheme.link) for elem in (document.documentElement, document.body):