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 confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
AppResources.Ok : details.ConfirmText;
if(!string.IsNullOrWhiteSpace(details.CancelText))
Device.BeginInvokeOnMainThread(async () =>
{
confirmed = await MainPage.DisplayAlert(details.Title, details.Text, confirmText,
details.CancelText);
}
else
{
await MainPage.DisplayAlert(details.Title, details.Text, confirmText);
}
_messagingService.Send("showDialogResolve", new Tuple<int, bool>(details.DialogId, confirmed));
if(!string.IsNullOrWhiteSpace(details.CancelText))
{
confirmed = await MainPage.DisplayAlert(details.Title, details.Text, confirmText,
details.CancelText);
}
else
{
await MainPage.DisplayAlert(details.Title, details.Text, confirmText);
}
_messagingService.Send("showDialogResolve", new Tuple<int, bool>(details.DialogId, confirmed));
});
}
else if(message.Command == "locked")
{
await _stateService.PurgeAsync();
MainPage = new NavigationPage(new LockPage());
Device.BeginInvokeOnMainThread(() => MainPage = new NavigationPage(new LockPage()));
}
else if(message.Command == "lockVault")
{

View file

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

View file

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

View file

@ -63,7 +63,10 @@ namespace Bit.App.Pages
if(message.Command == "syncCompleted")
{
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")
{
var data = message.Data as Dictionary<string, object>;
if(data.ContainsKey("successfully"))
Device.BeginInvokeOnMainThread(() =>
{
var success = data["successfully"] as bool?;
if(success.HasValue && success.Value)
var data = message.Data as Dictionary<string, object>;
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 () =>

View file

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