From cdc88c38fa2bfabacca27bf7b337979cbc1e3edb Mon Sep 17 00:00:00 2001 From: huan <81978106+huan1936@users.noreply.github.com> Date: Mon, 24 Jun 2024 19:17:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20edgechromium.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat: implement initialization of WebView2 environment  - Added initialization logic for the WebView2 environment in the EdgeChrome class. - Utilized CoreWebView2Environment.CreateAsync() to asynchronously create the environment. - Implemented a callback function to ensure the WebView2 control is synchronized with the newly created environment. --- webview/platforms/edgechromium.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/webview/platforms/edgechromium.py b/webview/platforms/edgechromium.py index d548e590..d90e426b 100644 --- a/webview/platforms/edgechromium.py +++ b/webview/platforms/edgechromium.py @@ -27,7 +27,7 @@ clr.AddReference(interop_dll_path('Microsoft.Web.WebView2.Core.dll')) clr.AddReference(interop_dll_path('Microsoft.Web.WebView2.WinForms.dll')) -from Microsoft.Web.WebView2.Core import CoreWebView2Cookie, CoreWebView2ServerCertificateErrorAction +from Microsoft.Web.WebView2.Core import CoreWebView2Cookie, CoreWebView2ServerCertificateErrorAction, CoreWebView2Environment from Microsoft.Web.WebView2.WinForms import CoreWebView2CreationProperties, WebView2 for platform in ('win-arm64', 'win-x64', 'win-x86'): @@ -71,7 +71,17 @@ def __init__(self, form, window, cache_dir): self.url = None self.ishtml = False self.html = DEFAULT_HTML - self.web_view.EnsureCoreWebView2Async(None) + self.setup_webview2_environment() + + def setup_webview2_environment(self): + def _callback(task): + self.web_view.EnsureCoreWebView2Async(task.Result) + + environment = CoreWebView2Environment.CreateAsync() + environment.ContinueWith( + Action[Task[CoreWebView2Environment]](_callback), + self.syncContextTaskScheduler, + ) def evaluate_js(self, script, semaphore, js_result, callback=None): def _callback(result):