From d17da80f19518369972d705f044bbc962ed39ada Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 1 Jul 2019 21:10:24 -0400 Subject: [PATCH] lock timer --- src/iOS/AppDelegate.cs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index e845a1830..e9c33c5a8 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -33,6 +33,7 @@ namespace Bit.iOS private IMessagingService _messagingService; private IBroadcasterService _broadcasterService; private IStorageService _storageService; + private ILockService _lockService; public override bool FinishedLaunching(UIApplication app, NSDictionary options) { @@ -42,6 +43,7 @@ namespace Bit.iOS _messagingService = ServiceContainer.Resolve("messagingService"); _broadcasterService = ServiceContainer.Resolve("broadcasterService"); _storageService = ServiceContainer.Resolve("storageService"); + _lockService = ServiceContainer.Resolve("lockService"); LoadApplication(new App.App(null)); iOSCoreHelpers.AppearanceAdjustments(); @@ -51,12 +53,11 @@ namespace Bit.iOS { if(message.Command == "scheduleLockTimer") { - var lockOptionMinutes = (int)message.Data; - + LockTimer((int)message.Data); } else if(message.Command == "cancelLockTimer") { - + CancelLockTimer(); } else if(message.Command == "updatedTheme") { @@ -278,6 +279,35 @@ namespace Bit.iOS } } + private void LockTimer(int lockOptionMinutes) + { + var lockOptionMs = lockOptionMinutes * 60000; + _lockTimer?.Invalidate(); + _lockTimer?.Dispose(); + _lockTimer = null; + var lockMsSpan = TimeSpan.FromMilliseconds(lockOptionMs + 10); + Device.BeginInvokeOnMainThread(() => + { + _lockTimer = NSTimer.CreateScheduledTimer(lockMsSpan, timer => + { + Device.BeginInvokeOnMainThread(() => + { + _lockService.CheckLockAsync(); + _lockTimer?.Invalidate(); + _lockTimer?.Dispose(); + _lockTimer = null; + }); + }); + }); + } + + private void CancelLockTimer() + { + _lockTimer?.Invalidate(); + _lockTimer?.Dispose(); + _lockTimer = null; + } + private async Task ClearClipboardTimerAsync(Tuple data) { if(data.Item3)