diff --git a/src/App/Services/MobileBroadcasterMessagingService.cs b/src/App/Services/MobileBroadcasterMessagingService.cs new file mode 100644 index 000000000..94c1908b1 --- /dev/null +++ b/src/App/Services/MobileBroadcasterMessagingService.cs @@ -0,0 +1,21 @@ +using Bit.Core.Abstractions; +using Bit.Core.Models.Domain; + +namespace Bit.App.Services +{ + public class MobileBroadcasterMessagingService : IMessagingService + { + private readonly IBroadcasterService _broadcasterService; + + public MobileBroadcasterMessagingService(IBroadcasterService broadcasterService) + { + _broadcasterService = broadcasterService; + } + + public void Send(string subscriber, object arg = null) + { + var message = new Message { Command = subscriber, Data = arg }; + _broadcasterService.Send(message); + } + } +} diff --git a/src/App/Services/MobileBroadcasterService.cs b/src/App/Services/MobileBroadcasterService.cs deleted file mode 100644 index c2e53cfc0..000000000 --- a/src/App/Services/MobileBroadcasterService.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Bit.Core.Abstractions; -using System; -using Xamarin.Forms; - -namespace Bit.App.Services -{ - public class MobileBroadcasterService : IBroadcasterService - { - public void Send(T message, string id = null) - { - if(string.IsNullOrWhiteSpace(id)) - { - throw new NotSupportedException("Cannot send a message to all subscribers."); - } - MessagingCenter.Send(Application.Current, id, message); - } - - public void Subscribe(string id, Action messageCallback) - { - MessagingCenter.Subscribe(Application.Current, id, - (sender, message) => messageCallback(message)); - } - - public void Unsubscribe(string id) - { - MessagingCenter.Unsubscribe(Application.Current, id); - } - } -} diff --git a/src/App/Services/MobileMessagingService.cs b/src/App/Services/MobileMessagingService.cs deleted file mode 100644 index 450d75372..000000000 --- a/src/App/Services/MobileMessagingService.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Bit.Core.Abstractions; - -namespace Bit.App.Services -{ - public class MobileMessagingService : IMessagingService - { - public void Send(string subscriber, T arg = default(T)) - { - Xamarin.Forms.MessagingCenter.Send(Xamarin.Forms.Application.Current, subscriber, arg); - } - } -} diff --git a/src/App/Services/MobilePlatformUtilsService.cs b/src/App/Services/MobilePlatformUtilsService.cs index 3e5e30e52..c5d92aeb0 100644 --- a/src/App/Services/MobilePlatformUtilsService.cs +++ b/src/App/Services/MobilePlatformUtilsService.cs @@ -35,29 +35,33 @@ namespace Bit.App.Services public void Init() { - _broadcasterService.Subscribe>("showDialogResolve", (details) => + _broadcasterService.Subscribe("showDialogResolve", (message) => { - var dialogId = details.Item1; - var confirmed = details.Item2; - if(_showDialogResolves.ContainsKey(dialogId)) + if(message.Command == "") { - var resolveObj = _showDialogResolves[dialogId].Item1; - resolveObj.TrySetResult(confirmed); - } - - // Clean up old tasks - var deleteIds = new HashSet(); - foreach(var item in _showDialogResolves) - { - var age = DateTime.UtcNow - item.Value.Item2; - if(age.TotalMilliseconds > DialogPromiseExpiration) + var details = message.Data as Tuple; + var dialogId = details.Item1; + var confirmed = details.Item2; + if(_showDialogResolves.ContainsKey(dialogId)) { - deleteIds.Add(item.Key); + var resolveObj = _showDialogResolves[dialogId].Item1; + resolveObj.TrySetResult(confirmed); + } + + // Clean up old tasks + var deleteIds = new HashSet(); + foreach(var item in _showDialogResolves) + { + var age = DateTime.UtcNow - item.Value.Item2; + if(age.TotalMilliseconds > DialogPromiseExpiration) + { + deleteIds.Add(item.Key); + } + } + foreach(var id in deleteIds) + { + _showDialogResolves.Remove(id); } - } - foreach(var id in deleteIds) - { - _showDialogResolves.Remove(id); } }); }