Skip to content

Commit

Permalink
Merge pull request #1872 from cwensley/curtis/webview-updates
Browse files Browse the repository at this point in the history
WebView fixes
  • Loading branch information
cwensley authored Jan 8, 2021
2 parents aebf9e3 + 1494633 commit 32703b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/Eto.Mac/Forms/Controls/WKWebViewHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@

namespace Eto.Mac.Forms.Controls
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void Blar(IntPtr block);

public class WKWebViewHandler : MacView<wk.WKWebView, WebView, WebView.ICallback>, 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();
Expand Down Expand Up @@ -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;
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/Eto.Wpf/Forms/Controls/WebView2Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ static class WebView2Loader
/// </summary>
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}";

/// <summary>
/// Detects whether WebView2 is installed
/// </summary>
Expand All @@ -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);
}

Expand Down Expand Up @@ -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...");
Expand All @@ -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())
{
Expand Down

0 comments on commit 32703b9

Please sign in to comment.