Пример #1
0
    public async Task Init(Settings setting, MoeSite site)
    {
        Site        = site;
        DataContext = setting;
        Closing    += OnClosing;
        this.SetWindowFluent(setting);
        try
        {
            MainBrowser.CoreWebView2InitializationCompleted += MainBrowserOnCoreWebView2InitializationCompleted;
            if (MainBrowser == null)
            {
                return;
            }
            var option = new CoreWebView2EnvironmentOptions();
            switch (NetOperator.GetProxyMode(setting, site.SiteSettings))
            {
            case Settings.ProxyModeEnum.None:
                option.AdditionalBrowserArguments = "--no-proxy-server";
                break;

            case Settings.ProxyModeEnum.Custom:
                option.AdditionalBrowserArguments = $"--proxy-server=http://{setting.ProxySetting}";
                break;

            case Settings.ProxyModeEnum.Ie:
                break;
            }
            Environment = await CoreWebView2Environment.CreateAsync(null, App.AppDataDir, option);

            AuthButton.Click          += AuthButtonOnClick;
            GoToLoginPageButton.Click += GoToLoginPageButtonOnClick;
            var _ = MainBrowser.EnsureCoreWebView2Async(Environment);
        }
        catch (Exception ex)
        {
            var result = MessageBox.Show(this, "未找到WebView2组件,需要下载吗?(需要Webview2组件才能显示网页登录界面)", App.DisplayName, MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (result == MessageBoxResult.Yes)
            {
                "https://go.microsoft.com/fwlink/p/?LinkId=2124703".GoUrl();
            }
            Ex.Log(ex);
            Close();
        }
    }