fix(ui-services): auto lock service extending tree
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { ApplicationService } from '@standardnotes/snjs'
|
import { AbstractService, ApplicationEvent, ApplicationInterface, InternalEventBusInterface } from '@standardnotes/services'
|
||||||
|
|
||||||
const MILLISECONDS_PER_SECOND = 1000
|
const MILLISECONDS_PER_SECOND = 1000
|
||||||
const POLL_INTERVAL = 50
|
const POLL_INTERVAL = 50
|
||||||
@@ -13,14 +13,23 @@ const LockInterval = {
|
|||||||
|
|
||||||
const STORAGE_KEY_AUTOLOCK_INTERVAL = 'AutoLockIntervalKey'
|
const STORAGE_KEY_AUTOLOCK_INTERVAL = 'AutoLockIntervalKey'
|
||||||
|
|
||||||
export class AutolockService extends ApplicationService {
|
export class AutolockService extends AbstractService {
|
||||||
|
private unsubApp!: () => void
|
||||||
|
|
||||||
private pollInterval: any
|
private pollInterval: any
|
||||||
private lastFocusState?: 'hidden' | 'visible'
|
private lastFocusState?: 'hidden' | 'visible'
|
||||||
private lockAfterDate?: Date
|
private lockAfterDate?: Date
|
||||||
|
|
||||||
override onAppLaunch() {
|
constructor(
|
||||||
|
protected application: ApplicationInterface,
|
||||||
|
protected override internalEventBus: InternalEventBusInterface,
|
||||||
|
) {
|
||||||
|
super(internalEventBus)
|
||||||
|
this.addAppEventObserverAfterSubclassesFinishConstructing()
|
||||||
|
}
|
||||||
|
|
||||||
|
onAppLaunch() {
|
||||||
this.beginPolling()
|
this.beginPolling()
|
||||||
return super.onAppLaunch()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override deinit() {
|
override deinit() {
|
||||||
@@ -28,9 +37,33 @@ export class AutolockService extends ApplicationService {
|
|||||||
if (this.pollInterval) {
|
if (this.pollInterval) {
|
||||||
clearInterval(this.pollInterval)
|
clearInterval(this.pollInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
;(this.application as unknown) = undefined
|
||||||
|
|
||||||
|
this.unsubApp()
|
||||||
|
;(this.unsubApp as unknown) = undefined
|
||||||
|
|
||||||
super.deinit()
|
super.deinit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addAppEventObserverAfterSubclassesFinishConstructing() {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.addAppEventObserver()
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
addAppEventObserver() {
|
||||||
|
if (this.application.isLaunched()) {
|
||||||
|
void this.onAppLaunch()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.unsubApp = this.application.addEventObserver(async (event: ApplicationEvent) => {
|
||||||
|
if (event === ApplicationEvent.Launched) {
|
||||||
|
void this.onAppLaunch()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private lockApplication() {
|
private lockApplication() {
|
||||||
if (!this.application.hasPasscode()) {
|
if (!this.application.hasPasscode()) {
|
||||||
throw Error('Attempting to lock application with no passcode')
|
throw Error('Attempting to lock application with no passcode')
|
||||||
|
|||||||
Reference in New Issue
Block a user