Autolock UI

This commit is contained in:
Mo Bitar
2018-11-14 14:06:23 -06:00
parent 091f4cff7f
commit bb8140d89c
7 changed files with 911 additions and 28 deletions

View File

@@ -1,7 +1,8 @@
class PasscodeManager {
constructor(authManager, storageManager) {
document.addEventListener('visibilitychange', () => {
document.addEventListener('visibilitychange', (e) => {
console.log("visibilitychange", e, document.visibilityState);
this.documentVisibilityChanged(document.visibilityState);
});
@@ -13,6 +14,7 @@ class PasscodeManager {
const MillisecondsPerSecond = 1000;
PasscodeManager.AutoLockIntervalNone = 0;
PasscodeManager.AutoLockIntervalFiveSecs = 5 * MillisecondsPerSecond;
PasscodeManager.AutoLockIntervalOneMinute = 60 * MillisecondsPerSecond;
PasscodeManager.AutoLockIntervalFiveMinutes = 300 * MillisecondsPerSecond;
PasscodeManager.AutoLockIntervalOneHour = 3600 * MillisecondsPerSecond;
@@ -26,6 +28,10 @@ class PasscodeManager {
value: PasscodeManager.AutoLockIntervalNone,
label: "None"
},
{
value: PasscodeManager.AutoLockIntervalFiveSecs,
label: "5 Secs"
},
{
value: PasscodeManager.AutoLockIntervalOneMinute,
label: "1 Min"
@@ -51,20 +57,21 @@ class PasscodeManager {
}
async beginAutoLockTimer() {
console.log("beginAutoLockTimer");
var interval = await this.getAutoLockInterval();
if(interval == PasscodeManager.AutoLockIntervalNone) {
return;
}
this.lockTimeout = setTimeout(() => {
this.lockApplication();
}, interval);
}
cancelAutoLockTimer() {
console.log("cancelAutoLockTimer");
clearTimeout(this.lockTimeout);
}
lockApplication() {
console.log("lockApplication");
window.location.reload();
this.cancelAutoLockTimer();
}
@@ -82,14 +89,16 @@ class PasscodeManager {
}
async setAutoLockInterval(interval) {
console.log("Set autolock interval", interval);
return this.storageManager.setItem(PasscodeManager.AutoLockIntervalKey, JSON.stringify(interval), StorageManager.Fixed);
}
async getAutoLockInterval() {
let interval = await this.storageManager.getItem(PasscodeManager.AutoLockIntervalKey, StorageManager.Fixed);
console.log("Got interval", interval);
return interval && JSON.parse(interval);
if(interval) {
return JSON.parse(interval);
} else {
return PasscodeManager.AutoLockIntervalNone;
}
}
passcodeAuthParams() {