Skip to content

Commit

Permalink
Merge pull request #1419 from huan1936/master
Browse files Browse the repository at this point in the history
feat: implement initialization of WebView2 environment 
  • Loading branch information
r0x0r authored Jun 25, 2024
2 parents e6b249f + cdc88c3 commit 96e44aa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions webview/platforms/edgechromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 96e44aa

Please sign in to comment.