2 second webview cache.
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
|
||||
namespace Wino.Mail.WinUI.Extensions;
|
||||
|
||||
public static class WebViewExtensions
|
||||
{
|
||||
private static readonly object _environmentLock = new();
|
||||
private static bool _environmentInitialized;
|
||||
private static Task<CoreWebView2Environment>? _sharedEnvironmentTask;
|
||||
|
||||
/// <summary>
|
||||
/// Sets WebView2 environment variables once per process.
|
||||
@@ -22,6 +26,17 @@ public static class WebViewExtensions
|
||||
_environmentInitialized = true;
|
||||
}
|
||||
|
||||
public static Task<CoreWebView2Environment> GetSharedEnvironmentAsync()
|
||||
{
|
||||
EnsureWebView2Environment();
|
||||
|
||||
lock (_environmentLock)
|
||||
{
|
||||
_sharedEnvironmentTask ??= CoreWebView2Environment.CreateAsync().AsTask();
|
||||
return _sharedEnvironmentTask;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a script function in the WebView2 control.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user