From 42afc4f4fcf964e7dbba71cb01daf27b7d239522 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Tue, 19 Apr 2022 12:40:33 +0200 Subject: [PATCH] [PowerPreview]Dark mode for markdown preview (#17777) --- .../MarkdownPreviewHandler.csproj | 1 + .../MarkdownPreviewHandlerControl.cs | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj index 8e8c284915..752e1ccb7d 100644 --- a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj +++ b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandler.csproj @@ -59,6 +59,7 @@ + diff --git a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs index 78b130c5c8..5b403ff53d 100644 --- a/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs +++ b/src/modules/previewpane/MarkdownPreviewHandler/MarkdownPreviewHandlerControl.cs @@ -16,7 +16,6 @@ using Microsoft.PowerToys.PreviewHandler.Markdown.Telemetry.Events; using Microsoft.PowerToys.Telemetry; using Microsoft.Web.WebView2.Core; using Microsoft.Web.WebView2.WinForms; -using PreviewHandlerCommon; using Windows.System; namespace Microsoft.PowerToys.PreviewHandler.Markdown @@ -41,9 +40,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown private readonly MarkdownPipelineBuilder _pipelineBuilder; /// - /// Markdown HTML header. + /// Markdown HTML header for light theme. /// - private readonly string htmlHeader = "
"; + private readonly string htmlLightHeader = "
"; + + /// + /// Markdown HTML header for dark theme. + /// + private readonly string htmlDarkHeader = "
"; /// /// Markdown HTML footer. @@ -130,6 +134,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown _infoBarDisplayed = true; } + var htmlHeader = Common.UI.ThemeManager.GetWindowsBaseColor().ToLowerInvariant() == "dark" ? htmlDarkHeader : htmlLightHeader; _extension.FilePath = Path.GetDirectoryName(filePath); MarkdownPipeline pipeline = _pipelineBuilder.Build(); string parsedMarkdown = Markdig.Markdown.ToHtml(fileText, pipeline); @@ -151,12 +156,12 @@ namespace Microsoft.PowerToys.PreviewHandler.Markdown InvokeOnControlThread(() => { - ConfiguredTaskAwaitable.ConfiguredTaskAwaiter - webView2EnvironmentAwaiter = CoreWebView2Environment - .CreateAsync(userDataFolder: System.Environment.GetEnvironmentVariable("USERPROFILE") + - "\\AppData\\LocalLow\\Microsoft\\PowerToys\\MarkdownPreview-Temp") - .ConfigureAwait(true).GetAwaiter(); - webView2EnvironmentAwaiter.OnCompleted(() => + ConfiguredTaskAwaitable.ConfiguredTaskAwaiter + webView2EnvironmentAwaiter = CoreWebView2Environment + .CreateAsync(userDataFolder: System.Environment.GetEnvironmentVariable("USERPROFILE") + + "\\AppData\\LocalLow\\Microsoft\\PowerToys\\MarkdownPreview-Temp") + .ConfigureAwait(true).GetAwaiter(); + webView2EnvironmentAwaiter.OnCompleted(() => { InvokeOnControlThread(async () => {