Improve browser and instructions

This commit is contained in:
Timothy Baldridge 2022-05-21 11:20:28 -06:00
parent acf0bee082
commit 36091920c1
6 changed files with 47 additions and 15 deletions

View File

@ -65,7 +65,7 @@ public class VectorPlexusLoginManager : ViewModel, INeedsLogin
{
var view = new BrowserWindow();
view.Closed += (sender, args) => { RefreshTokenState(); };
var provider = _serviceProvider.GetRequiredService<VectorPlexusLoginManager>();
var provider = _serviceProvider.GetRequiredService<VectorPlexusLoginHandler>();
view.DataContext = provider;
view.Show();
}

View File

@ -39,7 +39,8 @@ public abstract class OAuth2LoginHandler<TLoginType> : BrowserWindowViewModel
var tlogin = new TLoginType();
var tcs = new TaskCompletionSource<Uri>();
await WaitForReady();
await NavigateTo(tlogin.AuthorizationEndpoint);
Browser!.Browser.CoreWebView2.Settings.UserAgent = "Wabbajack";
Browser!.Browser.NavigationStarting += (sender, args) =>
{
@ -56,7 +57,7 @@ public abstract class OAuth2LoginHandler<TLoginType> : BrowserWindowViewModel
var state = Guid.NewGuid().ToString();
await NavigateTo(new Uri(tlogin.AuthorizationEndpoint +
$"?response_type=code&client_id={tlogin.ClientID}&state={state}&scope={scopes}"));
$"?response_type=code&client_id={tlogin.ClientID}&state={state}&scope={scopes}"));
var uri = await tcs.Task.WaitAsync(token);

View File

@ -23,6 +23,8 @@ public abstract class BrowserWindowViewModel : ViewModel
[Reactive] public string HeaderText { get; set; }
[Reactive] public string Instructions { get; set; }
[Reactive] public string Address { get; set; }
public BrowserWindow? Browser { get; set; }
@ -47,6 +49,7 @@ public abstract class BrowserWindowViewModel : ViewModel
public async Task NavigateTo(Uri uri)
{
var tcs = new TaskCompletionSource();
Address = uri.ToString();
void Completed(object? o, CoreWebView2NavigationCompletedEventArgs a)
{
@ -56,7 +59,7 @@ public abstract class BrowserWindowViewModel : ViewModel
}
else
{
if (a.WebErrorStatus == CoreWebView2WebErrorStatus.ConnectionAborted)
if (a.WebErrorStatus is CoreWebView2WebErrorStatus.ConnectionAborted or CoreWebView2WebErrorStatus.Unknown )
{
tcs.TrySetResult();
}

View File

@ -24,26 +24,29 @@
mc:Ignorable="d">
<Grid Background="#121212" MouseDown="UIElement_OnMouseDown">
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="3" FontSize="16">Browser Window</TextBlock>
<TextBlock Grid.Row="0" Margin="4, 0, 0, 0" Grid.ColumnSpan="3" FontSize="16" Name="Header"></TextBlock>
<Button Grid.Row="1" Grid.Column="0">
<TextBlock Grid.Row="1" Grid.ColumnSpan="3" Margin="4" FontSize="20" FontWeight="Bold" Name="Instructions"></TextBlock>
<Button Grid.Row="2" Grid.Column="0" Margin="4" Name="BackButton">
<icon:PackIconModern Kind="NavigatePrevious"></icon:PackIconModern>
</Button>
<Button Grid.Row="1" Grid.Column="1">
<icon:PackIconModern Kind="Home"></icon:PackIconModern>
<Button Grid.Row="2" Grid.Column="1" Margin="4" Name="CopyButton">
<icon:PackIconModern Kind="PageCopy"></icon:PackIconModern>
</Button>
<TextBox Grid.Row="1" Grid.Column="3" VerticalContentAlignment="Center"></TextBox>
<TextBox Grid.Row="2" Grid.Column="3" Margin="4" VerticalContentAlignment="Center" Name="AddressBar" IsEnabled="False"></TextBox>
<wpf:WebView2 Grid.Row="2" Grid.ColumnSpan="3" Name="Browser"></wpf:WebView2>
<wpf:WebView2 Grid.Row="3" Grid.ColumnSpan="3" Name="Browser"></wpf:WebView2>
</Grid>
</mahapps:MetroWindow>

View File

@ -1,17 +1,24 @@
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using MahApps.Metro.Controls;
using ReactiveUI;
using Wabbajack.Common;
namespace Wabbajack;
public partial class BrowserWindow : MetroWindow
{
private readonly CompositeDisposable _disposable;
public BrowserWindow()
{
InitializeComponent();
_disposable = new CompositeDisposable();
}
private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
@ -23,6 +30,24 @@ public partial class BrowserWindow : MetroWindow
{
var vm = ((BrowserWindowViewModel) DataContext);
vm.Browser = this;
vm.WhenAnyValue(vm => vm.HeaderText)
.BindToStrict(this, view => view.Header.Text)
.DisposeWith(_disposable);
vm.WhenAnyValue(vm => vm.Instructions)
.BindToStrict(this, view => view.Instructions.Text)
.DisposeWith(_disposable);
vm.WhenAnyValue(vm => vm.Address)
.BindToStrict(this, view => view.AddressBar.Text)
.DisposeWith(_disposable);
this.CopyButton.Command = ReactiveCommand.Create(() =>
{
Clipboard.SetText(vm.Address.ToString());
});
vm.RunWrapper(CancellationToken.None)
.ContinueWith(_ => Dispatcher.Invoke(Close));
}

View File

@ -39,7 +39,7 @@
<ColumnDefinition Width="140"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" FontSize="16" Margin="0, 0, 8, 0" Name="AppName"></TextBlock>
<TextBlock Grid.Column="1" Margin="5, 0" Name="ResourceUsage" HorizontalAlignment="Right"></TextBlock>
<TextBlock Grid.Column="1" FontSize="16" Margin="5, 0" Name="ResourceUsage" HorizontalAlignment="Right" VerticalAlignment="Center"></TextBlock>
<Button Grid.Column="2" Name="SettingsButton">
<icon:Material Kind="Cog"></icon:Material>
</Button>