From 2c1106a114813453a62e3153926a8caaabdca555 Mon Sep 17 00:00:00 2001 From: Patrick Kranz Date: Sun, 9 May 2021 11:33:48 +0200 Subject: [PATCH] Manipulate the captcha callback, so no longer a seccond App is required. --- .../ViewModels/CaptchaPageViewModel.cs | 8 +++++++ Signal-Windows/Views/CaptchaPage.xaml | 22 +++++++++++++------ Signal-Windows/Views/CaptchaPage.xaml.cs | 19 ++++++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) 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"> - - 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; }" }); + } + } } }