Resolve safari not checking vault timeout every 10s (#1615)

This commit is contained in:
Oscar Hinton 2021-02-20 11:10:33 +01:00 committed by GitHub
parent ca6078e6e8
commit 2ac9f92267
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 2 deletions

2
jslib

@ -1 +1 @@
Subproject commit 0951424de77fbb61a38616d13d6c67f74ee19775 Subproject commit b0ae1bfa4cb3bc2642e1ecb14c6c1f0eceb06cb6

View File

@ -19,7 +19,6 @@ import {
TokenService, TokenService,
TotpService, TotpService,
UserService, UserService,
VaultTimeoutService,
} from 'jslib/services'; } from 'jslib/services';
import { ConsoleLogService } from 'jslib/services/consoleLog.service'; import { ConsoleLogService } from 'jslib/services/consoleLog.service';
import { EventService } from 'jslib/services/event.service'; import { EventService } from 'jslib/services/event.service';
@ -84,6 +83,7 @@ import BrowserMessagingService from '../services/browserMessaging.service';
import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service'; import BrowserPlatformUtilsService from '../services/browserPlatformUtils.service';
import BrowserStorageService from '../services/browserStorage.service'; import BrowserStorageService from '../services/browserStorage.service';
import I18nService from '../services/i18n.service'; import I18nService from '../services/i18n.service';
import VaultTimeoutService from '../services/vaultTimeout.service';
import { AutofillService as AutofillServiceAbstraction } from '../services/abstractions/autofill.service'; import { AutofillService as AutofillServiceAbstraction } from '../services/abstractions/autofill.service';

View File

@ -73,6 +73,11 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
} }
} }
break break
case "sleep":
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
context.completeRequest(returningItems: [response], completionHandler: nil)
}
return
default: default:
return return

View 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);
}
}
}
}