feat: soft biometrics lock (#1793)
This commit is contained in:
@@ -33,7 +33,7 @@ import {
|
||||
ThemeManager,
|
||||
WebAlertService,
|
||||
} from '@standardnotes/ui-services'
|
||||
import { MobileWebReceiver } from './MobileWebReceiver'
|
||||
import { MobileWebReceiver } from '../NativeMobileWeb/MobileWebReceiver'
|
||||
import { AndroidBackHandler } from '@/NativeMobileWeb/AndroidBackHandler'
|
||||
import { PrefDefaults } from '@/Constants/PrefDefaults'
|
||||
import { setViewportHeightWithFallback } from '@/setViewportHeightWithFallback'
|
||||
@@ -289,8 +289,10 @@ export class WebApplication extends SNApplication implements WebApplicationInter
|
||||
const passcodeLockImmediately = hasPasscode && passcodeTiming === MobileUnlockTiming.Immediately
|
||||
const biometricsLockImmediately = hasBiometrics && biometricsTiming === MobileUnlockTiming.Immediately
|
||||
|
||||
if (passcodeLockImmediately || biometricsLockImmediately) {
|
||||
if (passcodeLockImmediately) {
|
||||
await this.lock()
|
||||
} else if (biometricsLockImmediately) {
|
||||
this.softLockBiometrics()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
import { ReactNativeToWebEvent, WebApplicationInterface } from '@standardnotes/snjs'
|
||||
|
||||
export class MobileWebReceiver {
|
||||
constructor(private application: WebApplicationInterface) {
|
||||
this.listenForNativeMobileEvents()
|
||||
}
|
||||
|
||||
deinit() {
|
||||
;(this.application as unknown) = undefined
|
||||
window.removeEventListener('message', this.handleNativeMobileWindowMessage)
|
||||
document.removeEventListener('message', this.handleNativeMobileWindowMessage as never)
|
||||
}
|
||||
|
||||
listenForNativeMobileEvents() {
|
||||
const iOSEventRecipient = window
|
||||
const androidEventRecipient = document
|
||||
iOSEventRecipient.addEventListener('message', this.handleNativeMobileWindowMessage)
|
||||
androidEventRecipient.addEventListener('message', this.handleNativeMobileWindowMessage as never)
|
||||
}
|
||||
|
||||
handleNativeMobileWindowMessage = (event: MessageEvent) => {
|
||||
const nullOrigin = event.origin === '' || event.origin == null
|
||||
if (!nullOrigin) {
|
||||
return
|
||||
}
|
||||
|
||||
const message = (event as MessageEvent).data
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(message)
|
||||
const { messageType, reactNativeEvent } = parsed
|
||||
|
||||
if (messageType === 'event' && reactNativeEvent) {
|
||||
const nativeEvent = reactNativeEvent as ReactNativeToWebEvent
|
||||
this.handleNativeEvent(nativeEvent)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('Error parsing message from React Native', error)
|
||||
}
|
||||
}
|
||||
|
||||
handleNativeEvent(event: ReactNativeToWebEvent) {
|
||||
switch (event) {
|
||||
case ReactNativeToWebEvent.EnteringBackground:
|
||||
void this.application.handleMobileEnteringBackgroundEvent()
|
||||
break
|
||||
case ReactNativeToWebEvent.GainingFocus:
|
||||
void this.application.handleMobileGainingFocusEvent()
|
||||
break
|
||||
case ReactNativeToWebEvent.LosingFocus:
|
||||
void this.application.handleMobileLosingFocusEvent()
|
||||
break
|
||||
case ReactNativeToWebEvent.ResumingFromBackground:
|
||||
void this.application.handleMobileResumingFromBackgroundEvent()
|
||||
break
|
||||
case ReactNativeToWebEvent.AndroidBackButtonPressed:
|
||||
void this.application.handleAndroidBackButtonPressed()
|
||||
break
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user