run subscribed messages on main thread

This commit is contained in:
Kyle Spearrin 2019-05-30 11:40:33 -04:00
parent 70fa41ca3e
commit c3b9f4e5a8
6 changed files with 41 additions and 25 deletions

View File

@ -71,21 +71,24 @@ namespace Bit.App
var confirmed = true; var confirmed = true;
var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ? var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
AppResources.Ok : details.ConfirmText; AppResources.Ok : details.ConfirmText;
if(!string.IsNullOrWhiteSpace(details.CancelText)) Device.BeginInvokeOnMainThread(async () =>
{ {
confirmed = await MainPage.DisplayAlert(details.Title, details.Text, confirmText, if(!string.IsNullOrWhiteSpace(details.CancelText))
details.CancelText); {
} confirmed = await MainPage.DisplayAlert(details.Title, details.Text, confirmText,
else details.CancelText);
{ }
await MainPage.DisplayAlert(details.Title, details.Text, confirmText); else
} {
_messagingService.Send("showDialogResolve", new Tuple<int, bool>(details.DialogId, confirmed)); await MainPage.DisplayAlert(details.Title, details.Text, confirmText);
}
_messagingService.Send("showDialogResolve", new Tuple<int, bool>(details.DialogId, confirmed));
});
} }
else if(message.Command == "locked") else if(message.Command == "locked")
{ {
await _stateService.PurgeAsync(); await _stateService.PurgeAsync();
MainPage = new NavigationPage(new LockPage()); Device.BeginInvokeOnMainThread(() => MainPage = new NavigationPage(new LockPage()));
} }
else if(message.Command == "lockVault") else if(message.Command == "lockVault")
{ {

View File

@ -46,14 +46,17 @@ namespace Bit.App.Pages
protected async override void OnAppearing() protected async override void OnAppearing()
{ {
base.OnAppearing(); base.OnAppearing();
_broadcasterService.Subscribe(nameof(TwoFactorPage), async (message) => _broadcasterService.Subscribe(nameof(TwoFactorPage), (message) =>
{ {
if(message.Command == "gotYubiKeyOTP") if(message.Command == "gotYubiKeyOTP")
{ {
if(_vm.YubikeyMethod) if(_vm.YubikeyMethod)
{ {
_vm.Token = (string)message.Data; Device.BeginInvokeOnMainThread(async () =>
await _vm.SubmitAsync(); {
_vm.Token = (string)message.Data;
await _vm.SubmitAsync();
});
} }
} }
else if(message.Command == "resumeYubiKey") else if(message.Command == "resumeYubiKey")

View File

@ -27,9 +27,12 @@ namespace Bit.App.Pages
{ {
if(message.Command == "selectFileResult") if(message.Command == "selectFileResult")
{ {
var data = message.Data as Tuple<byte[], string>; Device.BeginInvokeOnMainThread(() =>
_vm.FileData = data.Item1; {
_vm.FileName = data.Item2; var data = message.Data as Tuple<byte[], string>;
_vm.FileData = data.Item1;
_vm.FileName = data.Item2;
});
} }
}); });
await LoadOnAppearedAsync(_scrollView, true, () => _vm.InitAsync()); await LoadOnAppearedAsync(_scrollView, true, () => _vm.InitAsync());

View File

@ -63,7 +63,10 @@ namespace Bit.App.Pages
if(message.Command == "syncCompleted") if(message.Command == "syncCompleted")
{ {
await Task.Delay(500); await Task.Delay(500);
await _vm.LoadAsync(); Device.BeginInvokeOnMainThread(() =>
{
var task = _vm.LoadAsync();
});
} }
}); });

View File

@ -38,15 +38,18 @@ namespace Bit.App.Pages
{ {
if(message.Command == "syncCompleted") if(message.Command == "syncCompleted")
{ {
var data = message.Data as Dictionary<string, object>; Device.BeginInvokeOnMainThread(() =>
if(data.ContainsKey("successfully"))
{ {
var success = data["successfully"] as bool?; var data = message.Data as Dictionary<string, object>;
if(success.HasValue && success.Value) if(data.ContainsKey("successfully"))
{ {
await _vm.LoadAsync(); var success = data["successfully"] as bool?;
if(success.HasValue && success.Value)
{
var task = _vm.LoadAsync();
}
} }
} });
} }
}); });
await LoadOnAppearedAsync(_scrollView, true, async () => await LoadOnAppearedAsync(_scrollView, true, async () =>

View File

@ -2,6 +2,7 @@
using Bit.Core.Models.Domain; using Bit.Core.Models.Domain;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks;
namespace Bit.App.Services namespace Bit.App.Services
{ {
@ -15,13 +16,13 @@ namespace Bit.App.Services
{ {
if(_subscribers.ContainsKey(id)) if(_subscribers.ContainsKey(id))
{ {
_subscribers[id].Invoke(message); Task.Run(() => _subscribers[id].Invoke(message));
} }
return; return;
} }
foreach(var sub in _subscribers) foreach(var sub in _subscribers)
{ {
sub.Value.Invoke(message); Task.Run(() => sub.Value.Invoke(message));
} }
} }