diff --git a/Signal-Windows/ViewModels/CaptchaPageViewModel.cs b/Signal-Windows/ViewModels/CaptchaPageViewModel.cs index 01611b2..17c3281 100644 --- a/Signal-Windows/ViewModels/CaptchaPageViewModel.cs +++ b/Signal-Windows/ViewModels/CaptchaPageViewModel.cs @@ -40,5 +40,13 @@ private void BackButton_Click(object sender, BackRequestedEventArgs e) View.Frame.GoBack(); e.Handled = true; } + + public void SetToken(string signalCaptchaToken) + { + var registerPageInstance = App.CurrentSignalWindowsFrontend(App.MainViewId).Locator.RegisterPageInstance; + registerPageInstance.CaptchaCode = signalCaptchaToken; + registerPageInstance.CaptchaWebViewEnabled = false; + App.CurrentSignalWindowsFrontend(App.MainViewId).Locator.CaptchaPageInstance.View.Frame.GoBack(); + } } } diff --git a/Signal-Windows/Views/CaptchaPage.xaml b/Signal-Windows/Views/CaptchaPage.xaml index a2f419a..bb2a4a2 100644 --- a/Signal-Windows/Views/CaptchaPage.xaml +++ b/Signal-Windows/Views/CaptchaPage.xaml @@ -2,18 +2,26 @@ x:Class="Signal_Windows.Views.CaptchaPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="using:Signal_Windows.Views" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="using:Signal_Windows.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" - DataContext="{Binding CaptchaPageInstance, Source={StaticResource Locator}}"> + DataContext="{Binding CaptchaPageInstance, Source={StaticResource Locator}}" + mc:Ignorable="d"> <Grid> - <WebView x:Name="webView" Source="{x:Bind Vm.WebViewSource, Mode=TwoWay}"/> - <Button x:Name="refreshButton" VerticalAlignment="Bottom" HorizontalAlignment="Center" Click="refreshButton_Click"> + <WebView + x:Name="webView" + NavigationStarting="webView_NavigationStarting" + NavigationCompleted="webView_NavigationCompleted" + Source="{x:Bind Vm.WebViewSource, Mode=TwoWay}" /> + <Button + x:Name="refreshButton" + HorizontalAlignment="Center" + VerticalAlignment="Bottom" + Click="refreshButton_Click"> <StackPanel Orientation="Horizontal"> - <SymbolIcon Symbol="Refresh"/> - <TextBlock Text="Refresh" Margin="8,0,0,0"/> + <SymbolIcon Symbol="Refresh" /> + <TextBlock Margin="8,0,0,0" Text="Refresh" /> </StackPanel> </Button> </Grid> diff --git a/Signal-Windows/Views/CaptchaPage.xaml.cs b/Signal-Windows/Views/CaptchaPage.xaml.cs index 1cf0b12..6a3ec7d 100644 --- a/Signal-Windows/Views/CaptchaPage.xaml.cs +++ b/Signal-Windows/Views/CaptchaPage.xaml.cs @@ -54,5 +54,24 @@ private void refreshButton_Click(object sender, RoutedEventArgs e) // KeyDown event doesn't work with WebView so just use a button to allow users to refresh the page webView.Refresh(); } + + private void webView_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) + { + if (args.Uri.ToString().StartsWith("http://token/")) + { + args.Cancel = true; + var token = args.Uri.ToString().Substring("http://token/".Length); + Vm.SetToken(token); + } + } + + private async void webView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) + { + var result = await sender.InvokeScriptAsync("eval", new[] { "document.getElementsByTagName('html')[0].innerHTML;" }); + if (result.Contains("\"signalcaptcha://\"") && result.Contains("function onToken(token)")) + { + await sender.InvokeScriptAsync("eval", new[] { @"function onToken(token) { window.location = ""http://Token/"" + token; }" }); + } + } } }