2021-06-07 19:25:37 +02:00
|
|
|
import { VaultTimeoutService as BaseVaultTimeoutService } from 'jslib-common/services/vaultTimeout.service';
|
2021-02-20 11:10:33 +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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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() {
|
2021-03-02 19:31:52 +01:00
|
|
|
while (true) {
|
2021-02-20 11:10:33 +01:00
|
|
|
try {
|
|
|
|
await SafariApp.sendMessageToApp('sleep');
|
|
|
|
this.checkVaultTimeout();
|
2021-03-02 19:31:52 +01:00
|
|
|
} catch (e) {
|
|
|
|
// tslint:disable-next-line
|
|
|
|
console.log('Exception Safari VaultTimeout', e);
|
2021-02-20 11:10:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|