Skip to content

功能建议:可以添加对 WebView2 内核的检测和调用系统自带 WebView2 的版本 #7

@Gaoyifei1011

Description

@Gaoyifei1011

功能建议:可以添加对 WebView2 内核的检测和调用系统自带 WebView2 的版本

检测 WebView2 是否安装的方法,参考链接:https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreAppWebView/Helpers/Root/RuntimeHelper.cs

    /// <summary>
    /// 判断 WebView2 运行时是否已安装
    /// </summary>
    private static void GetWebView2State()
    {
        try
        {
            string webViewVersion = CoreWebView2Environment.GetAvailableBrowserVersionString();
            IsWebView2Installed = !string.IsNullOrEmpty(webViewVersion);
        }
        catch (Exception)
        {
            IsWebView2Installed = false;
        }
    }

调用 Windows 11 22621+ 自带的 WebView2 浏览器内核的代码,参考链接:https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreAppWebView/Program.cs
目录:C:\Windows\System32\Microsoft-Edge-WebView

            string systemWebView2Path = Path.Combine(SystemDataPaths.GetDefault().System, "Microsoft-Edge-WebView");

            if (Directory.Exists(systemWebView2Path))
            {
                Environment.SetEnvironmentVariable("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", Path.Combine(SystemDataPaths.GetDefault().System, "Microsoft-Edge-WebView"));
            }

如果以上这两个条件都不满足,可以添加一个提示框,要求用户主动下载 WebView2

期待您的项目发展的越来越好
真诚祝愿,怡飞

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions