bitwarden-estensione-browser/apps/browser/src/services/vaultTimeout.service.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

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
import { SafariApp } from "../browser/safariApp";
export default class VaultTimeoutService extends BaseVaultTimeoutService {
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
}
// 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-03-02 19:31:52 +01:00
while (true) {
try {
await SafariApp.sendMessageToApp("sleep");
this.checkVaultTimeout();
2021-03-02 19:31:52 +01:00
} catch (e) {
2022-02-24 18:14:04 +01:00
// eslint-disable-next-line
2021-03-02 19:31:52 +01:00
console.log("Exception Safari VaultTimeout", e);
}
}
2021-12-21 15:43:35 +01:00
}
}