24 lines
959 B
C#
24 lines
959 B
C#
|
|
using System.IO;
|
|||
|
|
using Microsoft.Web.WebView2.Wpf;
|
|||
|
|
using YY.Admin.Core.Util;
|
|||
|
|
|
|||
|
|
namespace YY.Admin.Helper;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// WebView2 默认将用户数据目录放在宿主 exe 旁边;安装在 Program Files 时目录只读会导致初始化失败、预览白屏。
|
|||
|
|
/// 统一到当前用户 LocalAppData 下的可写路径。
|
|||
|
|
/// </summary>
|
|||
|
|
public static class WebView2UserDataFolder
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 为控件创建 CreationProperties(须在首次 EnsureCoreWebView2Async 之前赋值)。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="subFolder">子目录名,避免不同场景争用同一 profile。</param>
|
|||
|
|
public static CoreWebView2CreationProperties CreateCreationProperties(string subFolder)
|
|||
|
|
{
|
|||
|
|
var folder = AppWritablePaths.EnsureDirectoryExists(
|
|||
|
|
Path.Combine(AppWritablePaths.LocalApplicationRoot, "WebView2", subFolder));
|
|||
|
|
return new CoreWebView2CreationProperties { UserDataFolder = folder };
|
|||
|
|
}
|
|||
|
|
}
|