From 14946332045fdf4d222e80be14759edd68c575e0 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Fri, 8 Jan 2021 00:35:44 -0800 Subject: [PATCH] WebView fixes Wpf/WinForms: Detect WebView2 on 32-bit windows properly Wpf/WinForms: Fix installation of WebView2 on .NET Framework Mac: Fix warning when printing --- .../Forms/Controls/WKWebViewHandler.cs | 22 +++++++++++++------ src/Eto.Wpf/Forms/Controls/WebView2Handler.cs | 9 ++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Eto.Mac/Forms/Controls/WKWebViewHandler.cs b/src/Eto.Mac/Forms/Controls/WKWebViewHandler.cs index 0501a7f888..844aec4d2b 100644 --- a/src/Eto.Mac/Forms/Controls/WKWebViewHandler.cs +++ b/src/Eto.Mac/Forms/Controls/WKWebViewHandler.cs @@ -22,14 +22,8 @@ namespace Eto.Mac.Forms.Controls { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void Blar(IntPtr block); - public class WKWebViewHandler : MacView, WebView.IHandler { - static readonly Selector selIgnore = new Selector("ignore"); - static readonly Selector selUse = new Selector("use"); - public override NSView ContainerControl { get { return Control; } } public wk.WKWebViewConfiguration Configuration { get; set; } = new wk.WKWebViewConfiguration(); @@ -315,7 +309,21 @@ public void ShowPrintDialog() if (printOperation != null) { // RunOperation() doesn't work.. - printOperation.RunOperationModal(Control.Window, Control, new Selector("printOperationDidRun:success:contextInfo:"), IntPtr.Zero); + var printHelper = new PrintHelper(); + printOperation.RunOperationModal(Control.Window, printHelper, PrintHelper.PrintOperationDidRunSelector, IntPtr.Zero); + } + } + + class PrintHelper : NSObject + { + public static Selector PrintOperationDidRunSelector = new Selector("printOperationDidRun:success:contextInfo:"); + + public bool Success { get; set; } + + [Export("printOperationDidRun:success:contextInfo:")] + public void PrintOperationDidRun(IntPtr printOperation, bool success, IntPtr contextInfo) + { + Success = success; } } diff --git a/src/Eto.Wpf/Forms/Controls/WebView2Handler.cs b/src/Eto.Wpf/Forms/Controls/WebView2Handler.cs index 6992dc29b2..32278101be 100755 --- a/src/Eto.Wpf/Forms/Controls/WebView2Handler.cs +++ b/src/Eto.Wpf/Forms/Controls/WebView2Handler.cs @@ -59,6 +59,10 @@ static class WebView2Loader /// public static WebView2InstallMode InstallMode = WebView2InstallMode.Manual; + + const string reg64BitKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"; + const string reg32BitKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"; + /// /// Detects whether WebView2 is installed /// @@ -69,7 +73,7 @@ public static bool Detect() return false; #endif // https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#deploying-the-evergreen-webview2-runtime - var pv = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}", "pv", null); + var pv = Registry.GetValue(Environment.Is64BitOperatingSystem ? reg64BitKey : reg32BitKey, "pv", null); return pv is string s && !string.IsNullOrEmpty(s); } @@ -203,7 +207,7 @@ void Progress(double progress) reportProgress?.Invoke(info); } // download bootstrapper to temp folder - var tempFile = Path.GetTempFileName(); + var tempFile = Path.GetTempFileName() + ".exe"; try { info.Text = Loc("Downloading bootstrapper..."); @@ -229,6 +233,7 @@ void Progress(double progress) // run with elevated privileges var startInfo = new ProcessStartInfo(tempFile); startInfo.Verb = "runas"; + startInfo.UseShellExecute = false; var result = await RunProcessAsync(startInfo); if (result != 0 && !Detect()) {