mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
mobile: fix vault biometrics state incorrect on app launch
This commit is contained in:
@@ -21,6 +21,7 @@ import React, { useCallback, useEffect } from "react";
|
||||
import { db } from "../common/database";
|
||||
import BiometricService from "../services/biometrics";
|
||||
import { eSubscribeEvent, eUnSubscribeEvent } from "../services/event-manager";
|
||||
import { useSettingStore } from "../stores/use-setting-store";
|
||||
|
||||
const VaultStatusDefaults = {
|
||||
exists: false,
|
||||
@@ -36,6 +37,7 @@ export type VaultStatusType = {
|
||||
|
||||
export const useVaultStatus = () => {
|
||||
const [vaultStatus, setVaultStatus] = React.useState(VaultStatusDefaults);
|
||||
const isAppLoading = useSettingStore((state) => state.isAppLoading);
|
||||
|
||||
const checkVaultStatus = useCallback(() => {
|
||||
db.vault?.exists().then(async (exists) => {
|
||||
@@ -50,12 +52,13 @@ export const useVaultStatus = () => {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (isAppLoading) return;
|
||||
checkVaultStatus();
|
||||
eSubscribeEvent("vaultUpdated", () => checkVaultStatus());
|
||||
return () => {
|
||||
eUnSubscribeEvent("vaultUpdated", () => checkVaultStatus());
|
||||
};
|
||||
}, [checkVaultStatus]);
|
||||
}, [checkVaultStatus, isAppLoading]);
|
||||
|
||||
return vaultStatus;
|
||||
};
|
||||
|
||||
@@ -61,6 +61,7 @@ import {
|
||||
import { fluidTabsRef } from "../../utils/global-refs";
|
||||
import { strings } from "@notesnook/intl";
|
||||
import { i18n } from "@lingui/core";
|
||||
import { useVaultStatus } from "../../hooks/use-vault-status";
|
||||
|
||||
const style: ViewStyle = {
|
||||
height: "100%",
|
||||
@@ -197,6 +198,7 @@ const Editor = React.memo(
|
||||
export default Editor;
|
||||
|
||||
const useLockedNoteHandler = () => {
|
||||
const vaultStatus = useVaultStatus();
|
||||
const tab = useTabStore((state) => state.getTab(state.currentTab));
|
||||
const tabRef = useRef(tab);
|
||||
tabRef.current = tab;
|
||||
@@ -217,15 +219,13 @@ const useLockedNoteHandler = () => {
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const biometry = await BiometricService.isBiometryAvailable();
|
||||
const fingerprint = await BiometricService.hasInternetCredentials();
|
||||
useTabStore.setState({
|
||||
biometryAvailable: !!biometry,
|
||||
biometryEnrolled: !!fingerprint
|
||||
biometryAvailable: !!vaultStatus.isBiometryAvailable,
|
||||
biometryEnrolled: !!vaultStatus.biometryEnrolled
|
||||
});
|
||||
syncTabs("biometry");
|
||||
})();
|
||||
}, [tab?.id]);
|
||||
}, [tab?.id, vaultStatus.biometryEnrolled, vaultStatus.isBiometryAvailable]);
|
||||
|
||||
useEffect(() => {
|
||||
const unlockWithBiometrics = async () => {
|
||||
|
||||
Reference in New Issue
Block a user