From dd5955af3bd1917ce10166a95f2acb9ce6260543 Mon Sep 17 00:00:00 2001 From: ema Date: Tue, 28 Apr 2026 04:04:16 +0800 Subject: [PATCH] Enable WebView2 dark rendering for CHM --- .../ChmWebpagePanel.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/QuickLook.Plugin/QuickLook.Plugin.ChmViewer/ChmWebpagePanel.cs b/QuickLook.Plugin/QuickLook.Plugin.ChmViewer/ChmWebpagePanel.cs index 07f0b0b..4dd4957 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.ChmViewer/ChmWebpagePanel.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.ChmViewer/ChmWebpagePanel.cs @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +using QuickLook.Common.Helpers; using QuickLook.Plugin.HtmlViewer; using System; using System.Collections.Generic; @@ -41,6 +42,27 @@ public class ChmWebpagePanel : WebpagePanel public ChmWebpagePanel() { _homePage = ReadResource("/chm2html.html") ?? []; + + if (OSThemeHelper.AppsUseDarkTheme()) + { + // Invoke using reflection: WebView2.CreationProperties.AdditionalBrowserArguments + // This approach allows the library to avoid direct dependency on WebView2 + if (typeof(WebpagePanel).GetField("_webView", BindingFlags.NonPublic | BindingFlags.Instance) is FieldInfo fieldInfo) + { + object webView2 = fieldInfo.GetValue(this); + + if (webView2?.GetType().GetProperty("CreationProperties", BindingFlags.Public | BindingFlags.Instance) is PropertyInfo creationPropertiesProperty) + { + object creationProperties = creationPropertiesProperty.GetValue(webView2); + + if (creationProperties?.GetType().GetProperty("AdditionalBrowserArguments", BindingFlags.Public | BindingFlags.Instance) is PropertyInfo additionalBrowserArgumentsProperty) + { + string additionalBrowserArguments = (additionalBrowserArgumentsProperty.GetValue(creationProperties) as string) ?? string.Empty; + additionalBrowserArgumentsProperty.SetValue(creationProperties, additionalBrowserArguments + " --enable-features=WebContentsForceDark"); + } + } + } + } } private static void InitializeResources()