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:
31
src/background/idle.background.ts
Normal file
31
src/background/idle.background.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user