Use lockAfterDate for locking if timeout is put to sleep

This commit is contained in:
Mo Bitar
2018-12-21 10:56:54 -06:00
parent 091e484199
commit 28f5bbaf87
2 changed files with 27 additions and 9 deletions

View File

@@ -1,3 +1,5 @@
const MillisecondsPerSecond = 1000;
class PasscodeManager { class PasscodeManager {
constructor($rootScope, authManager, storageManager) { constructor($rootScope, authManager, storageManager) {
@@ -161,7 +163,6 @@ class PasscodeManager {
}); });
} }
const MillisecondsPerSecond = 1000;
PasscodeManager.AutoLockIntervalNone = 0; PasscodeManager.AutoLockIntervalNone = 0;
PasscodeManager.AutoLockIntervalImmediate = 1; PasscodeManager.AutoLockIntervalImmediate = 1;
PasscodeManager.AutoLockIntervalOneMinute = 60 * MillisecondsPerSecond; PasscodeManager.AutoLockIntervalOneMinute = 60 * MillisecondsPerSecond;
@@ -175,7 +176,7 @@ class PasscodeManager {
return [ return [
{ {
value: PasscodeManager.AutoLockIntervalNone, value: PasscodeManager.AutoLockIntervalNone,
label: "None" label: "Off"
}, },
{ {
value: PasscodeManager.AutoLockIntervalImmediate, value: PasscodeManager.AutoLockIntervalImmediate,
@@ -183,24 +184,29 @@ class PasscodeManager {
}, },
{ {
value: PasscodeManager.AutoLockIntervalOneMinute, value: PasscodeManager.AutoLockIntervalOneMinute,
label: "1 Min" label: "1m"
}, },
{ {
value: PasscodeManager.AutoLockIntervalFiveMinutes, value: PasscodeManager.AutoLockIntervalFiveMinutes,
label: "5 Min" label: "5m"
}, },
{ {
value: PasscodeManager.AutoLockIntervalOneHour, value: PasscodeManager.AutoLockIntervalOneHour,
label: "1 Hr" label: "1h"
} }
] ]
} }
documentVisibilityChanged(visible) { documentVisibilityChanged(visible) {
if(!visible) { if(visible) {
this.beginAutoLockTimer(); // check to see if lockAfterDate is not null, and if the application isn't locked.
} else { // if that's the case, it needs to be locked immediately.
if(this.lockAfterDate && new Date() > this.lockAfterDate && !this.isLocked()) {
this.lockApplication();
}
this.cancelAutoLockTimer(); this.cancelAutoLockTimer();
} else {
this.beginAutoLockTimer();
} }
} }
@@ -210,13 +216,26 @@ class PasscodeManager {
return; return;
} }
// Use a timeout if possible, but if the computer is put to sleep, timeouts won't work.
// Need to set a date as backup. this.lockAfterDate does not need to be persisted, as
// living in memory seems sufficient. If memory is cleared, then the application will lock anyway.
let addToNow = (seconds) => {
let date = new Date();
date.setSeconds(date.getSeconds() + seconds);
return date;
}
this.lockAfterDate = addToNow(interval / MillisecondsPerSecond);
this.lockTimeout = setTimeout(() => { this.lockTimeout = setTimeout(() => {
this.lockApplication(); this.lockApplication();
// We don't need to look at this anymore since we've succeeded with timeout lock
this.lockAfterDate = null;
}, interval); }, interval);
} }
cancelAutoLockTimer() { cancelAutoLockTimer() {
clearTimeout(this.lockTimeout); clearTimeout(this.lockTimeout);
this.lockAfterDate = null;
} }
} }

View File

@@ -140,7 +140,6 @@
%div{"ng-if" => "hasPasscode() && !formData.showPasscodeForm"} %div{"ng-if" => "hasPasscode() && !formData.showPasscodeForm"}
.sk-p .sk-p
Passcode lock is enabled. Passcode lock is enabled.
%span{"ng-if" => "isDesktopApplication()"} Your passcode will be required on new sessions after app quit.
.sk-notification.contrast .sk-notification.contrast
.sk-notification-title Options .sk-notification-title Options