bitwarden-estensione-browser/src/background/idle.background.ts

35 lines
927 B
TypeScript
Raw Normal View History

import MainBackground from './main.background';
2018-01-10 04:22:49 +01:00
import { ConstantsService } from 'jslib/services';
2018-01-10 05:18:55 +01:00
import {
LockService,
StorageService,
} from 'jslib/abstractions';
export default class IdleBackground {
private idle: any;
constructor(private main: MainBackground, private lockService: LockService,
2018-01-09 20:26:20 +01:00
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();
}
}
});
}
}
}