diff --git a/MinimalWebView.csproj b/MinimalWebView.csproj index ed9361b..ac42258 100644 --- a/MinimalWebView.csproj +++ b/MinimalWebView.csproj @@ -5,7 +5,7 @@ WinExe net6.0-windows app.manifest - 0.4.2 + 0.4.3 true diff --git a/NativeMethods.txt b/NativeMethods.txt index 223135e..73c8119 100644 --- a/NativeMethods.txt +++ b/NativeMethods.txt @@ -23,4 +23,6 @@ WM_SIZE WM_CLOSE WM_USER -AllocConsole \ No newline at end of file +AllocConsole + +MessageBox \ No newline at end of file diff --git a/Program.cs b/Program.cs index c8c844d..379f3a7 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,6 @@ -using Microsoft.Web.WebView2.Core; -using System.Drawing; +using System.Drawing; using System.Reflection; +using Microsoft.Web.WebView2.Core; using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.Graphics.Gdi; @@ -112,8 +112,23 @@ private static void OnSize(HWND hwnd, WPARAM wParam, int width, int height) private static async void CreateCoreWebView2(HWND hwnd) { Console.WriteLine("Initializing WebView2..."); - var environment = await CoreWebView2Environment.CreateAsync(null, null, null); - _controller = await environment.CreateCoreWebView2ControllerAsync(hwnd); + + try + { + var environment = await CoreWebView2Environment.CreateAsync(null, null, null); + _controller = await environment.CreateCoreWebView2ControllerAsync(hwnd); + } + catch (WebView2RuntimeNotFoundException) + { + var result = PInvoke.MessageBox(hwnd, "WebView2 runtime not installed.", "Error", MESSAGEBOX_STYLE.MB_OK | MESSAGEBOX_STYLE.MB_ICONERROR); + + if (result == MESSAGEBOX_RESULT.IDYES) + { + //TODO: download WV2 bootstrapper from https://go.microsoft.com/fwlink/p/?LinkId=2124703 and run it + } + + throw; + } Console.WriteLine("WebView2 initialization finished."); _controller.DefaultBackgroundColor = Color.Transparent; // avoids flash of white when page first renders