From 93d14de95c3cc644c77a3c1d2e86b9a36e0cf6c2 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 8 Dec 2022 21:54:04 +1000 Subject: [PATCH] Set night-mode class on web page initialization Ensures the background is the correct color by the time the webview is shown. We keep the #night check for now, as it's useful when testing in an external browser. --- qt/aqt/webview.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qt/aqt/webview.py b/qt/aqt/webview.py index fc816093b..5bb7de371 100644 --- a/qt/aqt/webview.py +++ b/qt/aqt/webview.py @@ -664,6 +664,10 @@ html {{ {font} }} gui_hooks.webview_did_inject_style_into_page(self) self.show() + if theme_manager.night_mode: + night_mode = 'document.documentElement.classList.add("night-mode");' + else: + night_mode = "" self.evalWithCallback( f""" (function(){{ @@ -671,6 +675,7 @@ html {{ {font} }} style.innerHTML = `{css}`; document.head.appendChild(style); document.body.classList.add({", ".join([f'"{c}"' for c in body_classes])}); + {night_mode} }})(); """, after_injection,