コード例 #1
0
        private async void InitializeAsync()
        {
            GameHTML gameHTML          = new GameHTML();
            var      creatonProperties = new Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties();

            creatonProperties.BrowserExecutableFolder = Application.StartupPath + "\\WebView2";
            webView1.CreationProperties = creatonProperties;
            await webView1.EnsureCoreWebView2Async(null);

            webView1.CoreWebView2.SetVirtualHostNameToFolderMapping("images.arcade", Application.StartupPath + "\\images", Microsoft.Web.WebView2.Core.CoreWebView2HostResourceAccessKind.Allow);
            webView1.Source = new Uri("https://discord.com/login");
        }
コード例 #2
0
ファイル: Login.cs プロジェクト: afonsosousah/arcadedesktop
        private async void InitializeAsync()
        {
            GameHTML gameHTML          = new GameHTML();
            var      creatonProperties = new Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties();

            creatonProperties.BrowserExecutableFolder = Application.StartupPath + "\\WebView2";
            webView1.CreationProperties = creatonProperties;
            await webView1.EnsureCoreWebView2Async(null);

            webView1.CoreWebView2.SetVirtualHostNameToFolderMapping("images.arcade", Application.StartupPath + "\\images", Microsoft.Web.WebView2.Core.CoreWebView2HostResourceAccessKind.Allow);
            webView1.Source = new Uri("https://discord.com/api/oauth2/authorize?response_type=token&client_id=827127417810059286&scope=identify");
            webView1.CoreWebView2.WebResourceResponseReceived += CoreWebView2_WebResourceResponseReceived;
        }
コード例 #3
0
        private async void InitializeAsync()
        {
            GameHTML gameHTML          = new GameHTML();
            var      creatonProperties = new Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties();

            creatonProperties.BrowserExecutableFolder = Application.StartupPath + "\\WebView2";
            webView1.CreationProperties = creatonProperties;
            await webView1.EnsureCoreWebView2Async(null);

            webView1.CoreWebView2.SetVirtualHostNameToFolderMapping("images", Application.StartupPath + "\\images", Microsoft.Web.WebView2.Core.CoreWebView2HostResourceAccessKind.Allow);

            webView1.NavigationCompleted += async(sender, e) =>
            {
                if (!File.Exists(Application.StartupPath + "/images/avatar.png"))
                {
                    (new WebClient()).DownloadFile("https://benevis.com/wp-content/uploads/2019/09/default-avatar-1.jpg", Application.StartupPath + "/images/avatar.png");
                }

                if (Properties.Settings.Default.User == null)
                {
                    Properties.Settings.Default.User = new User {
                        Username = "******"
                    }
                }
                ;

                await webView1.ExecuteScriptAsync($"document.getElementById('username').innerHTML = '{ Properties.Settings.Default.User.Username }';");

                await webView1.ExecuteScriptAsync($"document.getElementById('username').value = '{ Properties.Settings.Default.User.Username }';");

                await webView1.ExecuteScriptAsync($"document.getElementById('userimage').src = '{ "http://images/avatar.png" }';");

                await webView1.ExecuteScriptAsync($"document.getElementById('parallelTransfers').value = '{ Properties.Settings.Default.ParallelTransfers }';");
            };

            webView1.CoreWebView2.NavigateToString(gameHTML.GenerateArcadePage());
            webView1.CoreWebView2.AddHostObjectToScript("arcade", new Arcade());
            webView1.CoreWebView2.AddHostObjectToScript("eventForwarder", new EventForwarder(this.Handle));
            webView1.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
            webView1.CoreWebView2.Settings.AreDevToolsEnabled            = false;
        }