From 37fd854e33190001e53ae3da4e00b0efa07d81ab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 7 Oct 2022 23:28:19 +0530 Subject: [PATCH] Edit book: Preview panel: In dark mode when all of the background/foreground/link colors are set to "No change" do not render the book using dark colors --- src/calibre/gui2/tweak_book/preferences.py | 4 +++- src/calibre/gui2/tweak_book/preview.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tweak_book/preferences.py b/src/calibre/gui2/tweak_book/preferences.py index dc4c022117..cac49bc710 100644 --- a/src/calibre/gui2/tweak_book/preferences.py +++ b/src/calibre/gui2/tweak_book/preferences.py @@ -407,7 +407,9 @@ class PreviewSettings(BasicSettings): # {{{ ans.setObjectName(name) return ans - b('unset', _('No change'), _('Use the colors from the book styles, defaulting to black-on-white')) + b('unset', _('No change'), _('Use the colors from the book styles, defaulting to black-on-white.' + ' Note that in dark mode, you must set all three colors to "No change"' + ' otherwise the book is rendered with dark colors.')) b('auto', _('Theme based'), _('When using a dark theme force dark colors, otherwise same as "No change"')) b('manual', _('Custom'), _('Choose a custom color')) diff --git a/src/calibre/gui2/tweak_book/preview.py b/src/calibre/gui2/tweak_book/preview.py index fa7d1b1015..8cd226ef5a 100644 --- a/src/calibre/gui2/tweak_book/preview.py +++ b/src/calibre/gui2/tweak_book/preview.py @@ -277,7 +277,9 @@ def create_dark_mode_script(): function apply_css() { var css = ''; if (settings.link) css += 'html > body :link, html > body :link * { color: ' + settings.link + ' !important; }'; - if (settings.is_dark_theme) { css = ':root { color-scheme: dark; }' + css; } + var using_custom_colors = false; + if (settings.bg || settings.fg || settings.link) using_custom_colors = true; + if (settings.is_dark_theme && using_custom_colors) { css = ':root { color-scheme: dark; }' + css; } var style = document.createElement('style'); style.textContent = css; document.documentElement.appendChild(style);