/// </inheritdoc>
        public Task<BrowserResult> InvokeAsync(BrowserOptions options)
        {
            var tcs = new TaskCompletionSource<BrowserResult>();

            var window = _formFactory();
            var webView = new WebViewCompatible { Dock = DockStyle.Fill };

            webView.NavigationStarting += (sender, e) =>
            {
                if (e.Uri.AbsoluteUri.StartsWith(options.EndUrl))
                {
                    tcs.SetResult(new BrowserResult { ResultType = BrowserResultType.Success, Response = e.Uri.ToString() });
                    window.Close();
                }
            };

            window.Closing += (sender, e) =>
            {
                if (!tcs.Task.IsCompleted)
                    tcs.SetResult(new BrowserResult { ResultType = BrowserResultType.UserCancel });
            };


            window.Controls.Add(webView);
            window.Show();
            webView.Navigate(options.StartUrl);

            return tcs.Task;
        }
        private void LoadWebpage()
        {
            switch (webpageName)
            {
            case "eftMonster":
                this.Text        = "EFT.Monster";
                webpageUrlString = "https://eft.monster/";
                break;

            case "noFoodGoogleDoc":
                this.Text        = "NoFoodAfterMidnight's EFT Ammo Chart";
                webpageUrlString = "https://docs.google.com/spreadsheets/d/1jjWcIue0_PCsbLQAiL5VrIulPK8SzM5jjiCMx9zUuvE/htmlview?pru=AAABcrM5Ot0*zfa_Zlp1oww5fmcam1YG1w#";
                break;

            case "wikiAmmo":
                this.Text        = "EFT Wiki";
                webpageUrlString = "https://escapefromtarkov.gamepedia.com/Ballistics";
                break;

            case "wikiTasks":
                this.Text        = "EFT Wiki";
                webpageUrlString = "https://escapefromtarkov.gamepedia.com/Quests";
                break;

            case "taskItemTracker":
                this.Text = "Google Sheet Item Tracker";
                if (String.IsNullOrWhiteSpace(rootOverlay.settings.googleDocURL))
                {
                    webpageUrlString = "https://docs.google.com/spreadsheets/d/1FZMjvxB0RM89Nf7o7nNIWYf78ahp8-0q4nV6CrP-Kw8/edit?usp=sharing";
                }
                else
                {
                    webpageUrlString = rootOverlay.settings.googleDocURL;
                }
                break;
            }
            try
            {
                webpageUri = new Uri(webpageUrlString);
                webBrowser.Navigate(webpageUri);
            }
            catch (Exception ea)
            {
                System.Diagnostics.Debug.WriteLine("Error connecting to webpage: " + ea.Message);
            }
        }
        /// <inheritdoc />
        public Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
        {
            var tcs = new TaskCompletionSource <BrowserResult>();

            var window  = _windowFactory();
            var webView = new WebViewCompatible();

            window.Content = webView;

            webView.NavigationStarting += (sender, e) =>
            {
                if (e.Uri.AbsoluteUri.StartsWith(options.EndUrl))
                {
                    tcs.SetResult(new BrowserResult {
                        ResultType = BrowserResultType.Success, Response = e.Uri.ToString()
                    });
                    if (_shouldCloseWindow)
                    {
                        window.Close();
                    }
                    else
                    {
                        window.Content = null;
                    }
                }
            };

            window.Closing += (sender, e) =>
            {
                webView.Dispose();
                if (!tcs.Task.IsCompleted)
                {
                    tcs.SetResult(new BrowserResult {
                        ResultType = BrowserResultType.UserCancel
                    });
                }
            };

            window.Show();
            webView.Navigate(options.StartUrl);

            return(tcs.Task);
        }
Exemple #4
0
        /// <inheritdoc />
        public Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
        {
            var tcs = new TaskCompletionSource <BrowserResult>();

            var window  = _formFactory();
            var webView = new WebViewCompatible {
                Dock = DockStyle.Fill
            };

            window.Controls.Add(webView);

            webView.NavigationStarting += (sender, e) =>
            {
                if (e.Uri.AbsoluteUri.StartsWith(options.EndUrl))
                {
                    tcs.SetResult(new BrowserResult {
                        ResultType = BrowserResultType.Success, Response = e.Uri.ToString()
                    });
                    window.Close();
                }
            };

            window.Closing += (sender, e) =>
            {
                if (!tcs.Task.IsCompleted)
                {
                    tcs.SetResult(new BrowserResult {
                        ResultType = BrowserResultType.UserCancel
                    });
                }
            };


            if (options.DisplayMode == DisplayMode.Hidden)
            {
                window.WindowState = FormWindowState.Minimized;
            }
            window.Show();
            webView.Navigate(options.StartUrl);

            return(tcs.Task);
        }