/// </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;
        }
        /// <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);
        }
Пример #3
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);
        }
 internal static void PlaySong(WebViewCompatible wb, Label label)
 {
     Google.Apis.Drive.v3.Data.File song = GetRandomSong();
     wb.Source  = new Uri(song.WebViewLink);
     label.Text = "Playing: " + song.Name;
 }