diff --git a/jslib b/jslib index 0951424de7..b0ae1bfa4c 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 0951424de77fbb61a38616d13d6c67f74ee19775 +Subproject commit b0ae1bfa4cb3bc2642e1ecb14c6c1f0eceb06cb6 diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 399b385ebb..f4aacadcb8 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -19,7 +19,6 @@ import { TokenService, TotpService, UserService, - VaultTimeoutService, } from 'jslib/services'; import { ConsoleLogService } from 'jslib/services/consoleLog.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 BrowserStorageService from '../services/browserStorage.service'; import I18nService from '../services/i18n.service'; +import VaultTimeoutService from '../services/vaultTimeout.service'; import { AutofillService as AutofillServiceAbstraction } from '../services/abstractions/autofill.service'; diff --git a/src/safari/safari/SafariWebExtensionHandler.swift b/src/safari/safari/SafariWebExtensionHandler.swift index dca9195ac6..35d7a498a2 100644 --- a/src/safari/safari/SafariWebExtensionHandler.swift +++ b/src/safari/safari/SafariWebExtensionHandler.swift @@ -73,6 +73,11 @@ class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling { } } break + case "sleep": + DispatchQueue.main.asyncAfter(deadline: .now() + 10) { + context.completeRequest(returningItems: [response], completionHandler: nil) + } + return default: return diff --git a/src/services/vaultTimeout.service.ts b/src/services/vaultTimeout.service.ts new file mode 100644 index 0000000000..a36970e0de --- /dev/null +++ b/src/services/vaultTimeout.service.ts @@ -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); + } + } + } +}