1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00
Files
browser/src/background/idle.background.ts
2018-01-09 14:26:20 -05:00

32 lines
967 B
TypeScript

import ConstantsService from '../services/constants.service';
import LockService from '../services/lock.service';
import MainBackground from './main.background';
import { StorageService } from 'jslib/abstractions';
export default class IdleBackground {
private idle: any;
constructor(private main: MainBackground, private lockService: LockService,
private storageService: StorageService) {
this.idle = chrome.idle;
}
async init() {
if (!this.idle) {
return;
}
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();
}
}
});
}
}
}