From cbd37e4c3db73dcf0ab235c28ea8bba5f7ad4821 Mon Sep 17 00:00:00 2001 From: Charlton Santana Date: Tue, 8 Aug 2023 22:24:57 +0100 Subject: [PATCH 1/2] Only save pause timestamp if app is unlocked --- lib/src/entities/authenticator_impl.dart | 1 + lib/src/entities/lock_controller.dart | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/entities/authenticator_impl.dart b/lib/src/entities/authenticator_impl.dart index f78f566..9fcbc7f 100644 --- a/lib/src/entities/authenticator_impl.dart +++ b/lib/src/entities/authenticator_impl.dart @@ -60,6 +60,7 @@ class AuthenticatorImpl with WidgetsBindingObserver implements Authenticator { /// When the app is [paused], it first goes to [inactive] before continuing to [resumed] /// Ensure that the paused timestamp is not saved just before the app becomes [resumed] if (_lastState != AppLifecycleState.paused) { + _lockController.lockState is Unlocked) { _repository.savePausedTimestamp(DateTime.now()); } break; diff --git a/lib/src/entities/lock_controller.dart b/lib/src/entities/lock_controller.dart index 578d232..2957c71 100644 --- a/lib/src/entities/lock_controller.dart +++ b/lib/src/entities/lock_controller.dart @@ -12,6 +12,9 @@ class LockController { /// state of the app late final Stream state; + // The current lock state of the app + late LockState lockState = const Unlocked(); + /// Optionally register a callback that gets triggered every time the app is locked /// (e.g., for analytics purposes) final VoidCallback? onLockCallback; @@ -36,13 +39,15 @@ class LockController { /// [availableMethods] refer to [BiometricMethod]s that the device supports, or an empty list if the /// device doesn't support biometrics or the user has not opted in to using it. void lock({required List availableMethods}) { - _streamController.add(Locked(availableBiometricMethods: availableMethods)); + lockState = Locked(availableBiometricMethods: availableMethods); + _streamController.add(lockState); } /// Results in dismissing the lock screen overlay and making the app contents visible. /// Probably shouldn't be used manually, unless there's a really good reason to. It was /// intended to be used by the pin_lock package internally void unlock() { - _streamController.add(const Unlocked()); + lockState = const Unlocked(); + _streamController.add(lockState); } } From 4b5ed72caa32d6e4fb68c563d15682f6455584f6 Mon Sep 17 00:00:00 2001 From: Charlton Santana Date: Mon, 21 Aug 2023 14:11:02 +0100 Subject: [PATCH 2/2] Typo fix --- lib/src/entities/authenticator_impl.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/entities/authenticator_impl.dart b/lib/src/entities/authenticator_impl.dart index 9fcbc7f..0a319b8 100644 --- a/lib/src/entities/authenticator_impl.dart +++ b/lib/src/entities/authenticator_impl.dart @@ -59,7 +59,7 @@ class AuthenticatorImpl with WidgetsBindingObserver implements Authenticator { /// When the app is [paused], it first goes to [inactive] before continuing to [resumed] /// Ensure that the paused timestamp is not saved just before the app becomes [resumed] - if (_lastState != AppLifecycleState.paused) { + if (_lastState != AppLifecycleState.paused && _lockController.lockState is Unlocked) { _repository.savePausedTimestamp(DateTime.now()); }