mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 10:13:31 +00:00
Resolve safari not checking vault timeout every 10s (#1615)
This commit is contained in:
28
src/services/vaultTimeout.service.ts
Normal file
28
src/services/vaultTimeout.service.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { VaultTimeoutService as BaseVaultTimeoutService } from 'jslib/services/vaultTimeout.service';
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
// 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() {
|
||||
while(true) {
|
||||
try {
|
||||
await SafariApp.sendMessageToApp('sleep');
|
||||
this.checkVaultTimeout();
|
||||
} catch(e) {
|
||||
console.log("Exception Safari VaultTimeout", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user