mirror of
https://github.com/bitwarden/browser.git
synced 2025-03-02 03:41:09 +01:00
35 lines
927 B
TypeScript
35 lines
927 B
TypeScript
import MainBackground from './main.background';
|
|
|
|
import { ConstantsService } from 'jslib/services';
|
|
|
|
import {
|
|
LockService,
|
|
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();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|