Skip to content

Commit

Permalink
auth failures in websocket init cause navigation to StartPage
Browse files Browse the repository at this point in the history
  • Loading branch information
Trolldemorted committed Aug 6, 2017
1 parent f160fae commit 3be340c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
38 changes: 18 additions & 20 deletions Signal-Windows/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using GalaSoft.MvvmLight;
using libsignalservice;
using libsignalservice.push.exceptions;
using libsignalservice.util;
using Nito.AsyncEx;
using Signal_Windows.Models;
using Signal_Windows.Storage;
using Signal_Windows.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -96,16 +98,15 @@ public void UIUpdateThread(SignalConversation thread)
public MainPageViewModel()
{
App.MainPageActive = true;
Init();
}

public void Init()
public async Task Init()
{
CancelSource = new CancellationTokenSource();
var l = ActionInProgress.Lock(CancelSource.Token);
try
{
Task.Run(async () =>
await Task.Run(async () =>
{
List<SignalContact> contacts = SignalDBContext.GetAllContactsLocked();
List<SignalGroup> groups = SignalDBContext.GetAllGroupsLocked();
Expand Down Expand Up @@ -156,30 +157,27 @@ public void Init()
Debug.WriteLine(e.StackTrace);
}
});
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
try
{
MessageReceiver = new SignalServiceMessageReceiver(CancelSource.Token, App.ServiceUrls, new StaticCredentialsProvider(App.Store.Username, App.Store.Password, App.Store.SignalingKey, (int)App.Store.DeviceId), App.USER_AGENT);
Pipe = MessageReceiver.createMessagePipe();
MessageSender = new SignalServiceMessageSender(CancelSource.Token, App.ServiceUrls, App.Store.Username, App.Store.Password, (int)App.Store.DeviceId, new Store(), Pipe, null, App.USER_AGENT);
IncomingMessagesTask = Task.Factory.StartNew(HandleIncomingMessages, TaskCreationOptions.LongRunning);
OutgoingMessagesTask = Task.Factory.StartNew(HandleOutgoingMessages, TaskCreationOptions.LongRunning);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
});
l.Dispose();
MessageReceiver = new SignalServiceMessageReceiver(CancelSource.Token, App.ServiceUrls, new StaticCredentialsProvider(App.Store.Username, App.Store.Password, App.Store.SignalingKey, (int)App.Store.DeviceId), App.USER_AGENT);
Pipe = MessageReceiver.createMessagePipe();
MessageSender = new SignalServiceMessageSender(CancelSource.Token, App.ServiceUrls, App.Store.Username, App.Store.Password, (int)App.Store.DeviceId, new Store(), Pipe, null, App.USER_AGENT);
IncomingMessagesTask = Task.Factory.StartNew(HandleIncomingMessages, TaskCreationOptions.LongRunning);
OutgoingMessagesTask = Task.Factory.StartNew(HandleOutgoingMessages, TaskCreationOptions.LongRunning);
});
}
catch(AuthorizationFailedException)
{
Debug.WriteLine("OWS server rejected our credentials - redirecting to StartPage");
View.Frame.Navigate(typeof(StartPage));
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
finally
{
l.Dispose();
}
}

public async Task Shutdown()
Expand Down
3 changes: 2 additions & 1 deletion Signal-Windows/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public PageStyle GetCurrentViewStyle()
return Utils.GetViewStyle(new Size(ActualWidth, ActualHeight));
}

protected override void OnNavigatedTo(NavigationEventArgs e)
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
await Vm.Init();
}

private void Frame_SizeChanged(object sender, SizeChangedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Signal-Windows/project.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"libsignal-service-dotnet": "1.5.5",
"libsignal-service-dotnet": "1.5.6",
"Microsoft.EntityFrameworkCore": "1.1.2",
"Microsoft.EntityFrameworkCore.Design": "1.1.2",
"Microsoft.EntityFrameworkCore.Sqlite": "1.1.2",
Expand Down

0 comments on commit 3be340c

Please sign in to comment.