mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 23:33:31 +00:00
lock reload
This commit is contained in:
@@ -6,4 +6,6 @@ export abstract class LockService {
|
||||
setLockOption: (lockOption: number) => Promise<void>;
|
||||
isPinLockSet: () => Promise<[boolean, boolean]>;
|
||||
clear: () => Promise<any>;
|
||||
startLockReload: () => void;
|
||||
cancelLockReload: () => void;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ export class LockService implements LockServiceAbstraction {
|
||||
pinLocked = false;
|
||||
|
||||
private inited = false;
|
||||
private reloadInterval: any = null;
|
||||
|
||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||
private collectionService: CollectionService, private cryptoService: CryptoService,
|
||||
@@ -117,4 +118,31 @@ export class LockService implements LockServiceAbstraction {
|
||||
clear(): Promise<any> {
|
||||
return this.storageService.remove(ConstantsService.protectedPin);
|
||||
}
|
||||
|
||||
startLockReload(): void {
|
||||
if (this.pinLocked || this.reloadInterval != null) {
|
||||
return;
|
||||
}
|
||||
this.reloadInterval = setInterval(async () => {
|
||||
let doRefresh = false;
|
||||
const lastActive = await this.storageService.get<number>(ConstantsService.lastActiveKey);
|
||||
if (lastActive != null) {
|
||||
const diffSeconds = (new Date()).getTime() - lastActive;
|
||||
// Don't refresh if they are still active in the window
|
||||
doRefresh = diffSeconds >= 5000;
|
||||
}
|
||||
if (doRefresh) {
|
||||
clearInterval(this.reloadInterval);
|
||||
this.reloadInterval = null;
|
||||
this.messagingService.send('reloadProcess');
|
||||
}
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
cancelLockReload(): void {
|
||||
if (this.reloadInterval != null) {
|
||||
clearInterval(this.reloadInterval);
|
||||
this.reloadInterval = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user