Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Signal-Windows/ViewModels/CaptchaPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
22 changes: 15 additions & 7 deletions Signal-Windows/Views/CaptchaPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
19 changes: 19 additions & 0 deletions Signal-Windows/Views/CaptchaPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }" });
}
}
}
}