1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

IdleBackground, clean up lock service chrome refs

This commit is contained in:
Kyle Spearrin
2018-01-04 17:04:26 -05:00
parent 2986bd1e29
commit 2ef937f333
3 changed files with 35 additions and 12 deletions

View File

@@ -0,0 +1,31 @@
import ConstantsService from '../services/constants.service';
import LockService from '../services/lock.service';
import MainBackground from './main.background';
import { StorageService } from '../services/abstractions/storage.service';
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();
}
}
});
}
}
}