mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 17:53:39 +00:00
[Auto-Logout] Implement Vault Timeout Options (#1194)
* Update jslib31a2574->28e3fff* Initial commit for vault timeout * Updated timeout/action retrieval in idle.background * Cycle saved for idle check * Await async calls for lock/logout in idle bg * Updated lock vs log out conditional Co-authored-by: Vincent Salucci <vsalucci@bitwarden.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { ConstantsService } from 'jslib/services/constants.service';
|
||||
|
||||
import {
|
||||
LockService,
|
||||
StorageService,
|
||||
VaultTimeoutService,
|
||||
} from 'jslib/abstractions';
|
||||
import { NotificationsService } from 'jslib/abstractions/notifications.service';
|
||||
|
||||
@@ -13,7 +13,7 @@ export default class IdleBackground {
|
||||
private idleTimer: number = null;
|
||||
private idleState = 'active';
|
||||
|
||||
constructor(private lockService: LockService, private storageService: StorageService,
|
||||
constructor(private vaultTimeoutService: VaultTimeoutService, private storageService: StorageService,
|
||||
private notificationsService: NotificationsService) {
|
||||
this.idle = chrome.idle || (browser != null ? browser.idle : null);
|
||||
}
|
||||
@@ -39,10 +39,15 @@ export default class IdleBackground {
|
||||
|
||||
if (this.idle.onStateChanged) {
|
||||
this.idle.onStateChanged.addListener(async (newState: string) => {
|
||||
if (newState === 'locked') {
|
||||
const lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
||||
if (lockOption === -2) {
|
||||
this.lockService.lock(true);
|
||||
if (newState === 'locked') { // If the screen is locked or the screensaver activates
|
||||
const timeout = await this.storageService.get<number>(ConstantsService.vaultTimeoutKey);
|
||||
if (timeout === -2) { // On System Lock vault timeout option
|
||||
const action = await this.storageService.get<string>(ConstantsService.vaultTimeoutActionKey);
|
||||
if (action === 'lock') {
|
||||
await this.vaultTimeoutService.lock(true);
|
||||
} else {
|
||||
await this.vaultTimeoutService.logOut();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user