Add screen lock feature.

pull/1/head
Matthew Chen 6 years ago
parent cf0e6fce09
commit 2d6d375e82

@ -12,9 +12,21 @@ import LocalAuthentication
public enum OWSScreenLockOutcome {
case success
case cancel
// case userCancel
// case otherCancel
case failure(error:String)
// case permanentFailure(error:String)
}
@objc public let screenLockTimeouts = [
5 * kSecondInterval,
15 * kSecondInterval,
30 * kSecondInterval,
1 * kMinuteInterval,
5 * kMinuteInterval,
0
]
@objc public static let ScreenLockDidChange = Notification.Name("ScreenLockDidChange")
let primaryStorage: OWSPrimaryStorage
@ -68,7 +80,8 @@ import LocalAuthentication
return 0
}
return self.dbConnection.double(forKey: OWSScreenLock_Key_ScreenLockTimeoutSeconds, inCollection: OWSScreenLock_Collection, defaultValue: 0)
let defaultTimeout = screenLockTimeouts[0]
return self.dbConnection.double(forKey: OWSScreenLock_Key_ScreenLockTimeoutSeconds, inCollection: OWSScreenLock_Collection, defaultValue: defaultTimeout)
}
private func setIsScreenLockEnabled(value: TimeInterval) {

@ -143,16 +143,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(screenLockTimeout >= 0);
if (self.appBecameInactiveDate && screenLockInterval < screenLockTimeout) {
// Don't show 'Screen Lock' if 'Screen Lock' timeout hasn't elapsed.
shouldHaveScreenProtection = YES;
// Check again when screen lock timeout should elapse.
NSTimeInterval screenLockRemaining = screenLockTimeout - screenLockInterval + 0.2f;
OWSAssert(screenLockRemaining >= 0);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(screenLockRemaining * NSEC_PER_SEC)),
dispatch_get_main_queue(),
^{
[self ensureScreenProtection];
});
shouldHaveScreenLock = NO;
} else {
// Otherwise, show 'Screen Lock'.
shouldHaveScreenLock = YES;
@ -160,6 +151,11 @@ NS_ASSUME_NONNULL_BEGIN
}
BOOL shouldShowBlockWindow = shouldHaveScreenProtection || shouldHaveScreenLock;
DDLogVerbose(@"%@, shouldHaveScreenProtection: %d, shouldHaveScreenLock: %d, shouldShowBlockWindow: %d",
self.logTag,
shouldHaveScreenProtection,
shouldHaveScreenLock,
shouldShowBlockWindow);
self.screenBlockingWindow.hidden = !shouldShowBlockWindow;
if (shouldHaveScreenLock) {

@ -5,6 +5,7 @@
NS_ASSUME_NONNULL_BEGIN
// These NSTimeInterval constants provide simplified durations for readability.
extern const NSTimeInterval kSecondInterval;
extern const NSTimeInterval kMinuteInterval;
extern const NSTimeInterval kHourInterval;
extern const NSTimeInterval kDayInterval;

@ -7,6 +7,8 @@
NS_ASSUME_NONNULL_BEGIN
const NSTimeInterval kSecondInterval = 1;
const NSTimeInterval kMinuteInterval = 60;
const NSTimeInterval kHourInterval = 60 * kMinuteInterval;
const NSTimeInterval kDayInterval = 24 * kHourInterval;

Loading…
Cancel
Save