mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import BrowserApi from '../browser/browserApi';
|
|||||||
|
|
||||||
import CommandsBackground from './commands.background';
|
import CommandsBackground from './commands.background';
|
||||||
import ContextMenusBackground from './contextMenus.background';
|
import ContextMenusBackground from './contextMenus.background';
|
||||||
|
import IdleBackground from './idle.background';
|
||||||
import RuntimeBackground from './runtime.background';
|
import RuntimeBackground from './runtime.background';
|
||||||
import TabsBackground from './tabs.background';
|
import TabsBackground from './tabs.background';
|
||||||
import WebRequestBackground from './webRequest.background';
|
import WebRequestBackground from './webRequest.background';
|
||||||
@@ -67,6 +68,7 @@ export default class MainBackground {
|
|||||||
|
|
||||||
private commandsBackground: CommandsBackground;
|
private commandsBackground: CommandsBackground;
|
||||||
private contextMenusBackground: ContextMenusBackground;
|
private contextMenusBackground: ContextMenusBackground;
|
||||||
|
private idleBackground: IdleBackground;
|
||||||
private runtimeBackground: RuntimeBackground;
|
private runtimeBackground: RuntimeBackground;
|
||||||
private tabsBackground: TabsBackground;
|
private tabsBackground: TabsBackground;
|
||||||
private webRequestBackground: WebRequestBackground;
|
private webRequestBackground: WebRequestBackground;
|
||||||
@@ -118,6 +120,7 @@ export default class MainBackground {
|
|||||||
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService);
|
this.commandsBackground = new CommandsBackground(this, this.passwordGenerationService);
|
||||||
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
|
||||||
this.passwordGenerationService);
|
this.passwordGenerationService);
|
||||||
|
this.idleBackground = new IdleBackground(this, this.lockService, this.storageService);
|
||||||
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService);
|
this.runtimeBackground = new RuntimeBackground(this, this.autofillService, this.cipherService);
|
||||||
this.tabsBackground = new TabsBackground(this);
|
this.tabsBackground = new TabsBackground(this);
|
||||||
this.webRequestBackground = new WebRequestBackground(this.browserUtilsService, this.cipherService);
|
this.webRequestBackground = new WebRequestBackground(this.browserUtilsService, this.cipherService);
|
||||||
@@ -127,6 +130,7 @@ export default class MainBackground {
|
|||||||
async bootstrap() {
|
async bootstrap() {
|
||||||
await this.commandsBackground.init();
|
await this.commandsBackground.init();
|
||||||
await this.contextMenusBackground.init();
|
await this.contextMenusBackground.init();
|
||||||
|
await this.idleBackground.init();
|
||||||
await this.runtimeBackground.init();
|
await this.runtimeBackground.init();
|
||||||
await this.tabsBackground.init();
|
await this.tabsBackground.init();
|
||||||
await this.webRequestBackground.init();
|
await this.webRequestBackground.init();
|
||||||
|
|||||||
@@ -14,18 +14,6 @@ export default class LockService {
|
|||||||
private setIcon: Function, private refreshBadgeAndMenu: Function) {
|
private setIcon: Function, private refreshBadgeAndMenu: Function) {
|
||||||
this.checkLock();
|
this.checkLock();
|
||||||
setInterval(() => this.checkLock(), 10 * 1000); // check every 10 seconds
|
setInterval(() => this.checkLock(), 10 * 1000); // check every 10 seconds
|
||||||
|
|
||||||
const self = this;
|
|
||||||
if ((window as any).chrome.idle && (window as any).chrome.idle.onStateChanged) {
|
|
||||||
(window as any).chrome.idle.onStateChanged.addListener(async (newState: string) => {
|
|
||||||
if (newState === 'locked') {
|
|
||||||
const lockOption = await this.storageService.get<number>(ConstantsService.lockOptionKey);
|
|
||||||
if (lockOption === -2) {
|
|
||||||
self.lock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkLock(): Promise<void> {
|
async checkLock(): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user