From ed524b3f1d70696ede6c93614ffaf7ff6c2c53c9 Mon Sep 17 00:00:00 2001 From: Alberto Spelta Date: Thu, 18 Jul 2024 09:52:11 +0200 Subject: [PATCH] Add conditional DevTools for troubleshooting Enable the DevTools in non-stable releases when the Shift key is pressed --- src/Infrastructure/AppEnvironment.cs | 3 +++ src/Infrastructure/AppWindow.cs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/Infrastructure/AppEnvironment.cs b/src/Infrastructure/AppEnvironment.cs index 22bbe73c..6017947a 100644 --- a/src/Infrastructure/AppEnvironment.cs +++ b/src/Infrastructure/AppEnvironment.cs @@ -126,6 +126,9 @@ static AppEnvironment() public static string ProcessPath { get; } + // TODO: use custom defined constant to identify a stable release. See PublishMode property and "AdditionalConstants" in csproj + public static bool IsStableRelease => Version.TryParse(ApplicationProductVersion, out _); + public static AppPublishMode PublishMode { get diff --git a/src/Infrastructure/AppWindow.cs b/src/Infrastructure/AppWindow.cs index d1e736c1..a1436b6c 100644 --- a/src/Infrastructure/AppWindow.cs +++ b/src/Infrastructure/AppWindow.cs @@ -137,6 +137,10 @@ private async void InitializeWebViewAsync() WebView.Source = new Uri(Path.Combine(Environment.CurrentDirectory, "wwwroot\\index.html")); // /* ICoreWebView2_3 */ WebView.CoreWebView2.SetVirtualHostNameToFolderMapping("bravo.example", "wwwroot", CoreWebView2HostResourceAccessKind.Allow); //WebView.CoreWebView2.Navigate("https://bravo.example/index.html"); // For '.example' see rfc6761 + + // Allow users to open the DevTools for troubleshooting; this is only available in non-stable releases + if (!AppEnvironment.IsStableRelease && CommonHelper.IsKeyDown(System.Windows.Forms.Keys.ShiftKey)) + WebView.CoreWebView2.OpenDevToolsWindow(); } protected override void WndProc(ref Message message)