1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-29 11:05:52 +02:00

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,6 +71,8 @@ namespace Bit.App
var confirmed = true;
var confirmText = string.IsNullOrWhiteSpace(details.ConfirmText) ?
AppResources.Ok : details.ConfirmText;
Device.BeginInvokeOnMainThread(async () =>
{
if(!string.IsNullOrWhiteSpace(details.CancelText))
{
confirmed = await MainPage.DisplayAlert(details.Title, details.Text, confirmText,
@ -81,11 +83,12 @@ namespace Bit.App
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)
{
Device.BeginInvokeOnMainThread(async () =>
{
_vm.Token = (string)message.Data;
await _vm.SubmitAsync();
});
}
}
else if(message.Command == "resumeYubiKey")

View File

@ -26,10 +26,13 @@ namespace Bit.App.Pages
_broadcasterService.Subscribe(nameof(AttachmentsPage), (message) =>
{
if(message.Command == "selectFileResult")
{
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

@ -37,6 +37,8 @@ namespace Bit.App.Pages
_broadcasterService.Subscribe(nameof(ViewPage), async (message) =>
{
if(message.Command == "syncCompleted")
{
Device.BeginInvokeOnMainThread(() =>
{
var data = message.Data as Dictionary<string, object>;
if(data.ContainsKey("successfully"))
@ -44,9 +46,10 @@ namespace Bit.App.Pages
var success = data["successfully"] as bool?;
if(success.HasValue && success.Value)
{
await _vm.LoadAsync();
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));
}
}