1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-19 07:35:48 +02:00
bitwarden-browser/apps/browser/src/services/vaultTimeout.service.ts

31 lines
985 B
TypeScript
Raw Normal View History

2022-06-14 17:10:53 +02:00
import { VaultTimeoutService as BaseVaultTimeoutService } from "@bitwarden/common/services/vaultTimeout.service";
2022-02-24 18:14:04 +01:00
2021-12-21 15:43:35 +01:00
import { SafariApp } from "../browser/safariApp";
export default class VaultTimeoutService extends BaseVaultTimeoutService {
2021-12-21 15:43:35 +01:00
startCheck() {
this.checkVaultTimeout();
if (this.platformUtilsService.isSafari()) {
this.checkSafari();
} else {
setInterval(() => this.checkVaultTimeout(), 10 * 1000); // check every 10 seconds
}
2021-12-21 15:43:35 +01:00
}
2021-12-21 15:43:35 +01:00
// This is a work-around to safari adding an arbitary delay to setTimeout and
// setIntervals. It works by calling the native extension which sleeps for 10s,
// efficiently replicating setInterval.
async checkSafari() {
2022-02-24 18:14:04 +01:00
// eslint-disable-next-line
2021-12-21 15:43:35 +01:00
while (true) {
try {
await SafariApp.sendMessageToApp("sleep");
this.checkVaultTimeout();
} catch (e) {
2022-02-24 18:14:04 +01:00
// eslint-disable-next-line
2021-12-21 15:43:35 +01:00
console.log("Exception Safari VaultTimeout", e);
}
}
2021-12-21 15:43:35 +01:00
}
}