mobile: fix app lock on ios

This commit is contained in:
Ammar Ahmed
2024-02-15 19:33:57 +05:00
parent 93d55abb1a
commit 44c38a8598
7 changed files with 46 additions and 22 deletions

View File

@@ -103,6 +103,8 @@ const AppLockedOverlay = () => {
)
return;
biometricUnlockAwaitingUserInput.current = true;
if (Platform.OS === "android") {
const activityName = await NotesnookModule.getActivityName();
if (activityName !== "MainActivity") return;
@@ -118,10 +120,11 @@ const AppLockedOverlay = () => {
enabled(false);
password.current = undefined;
}
biometricUnlockAwaitingUserInput.current = false;
setTimeout(() => {
biometricUnlockAwaitingUserInput.current = false;
if (biometricUnlockAwaitingUserInput.current) return;
useSettingStore.getState().setRequestBiometrics(false);
}, 1);
}, 500);
}, [biometricsAuthEnabled, lockApp]);
const onSubmit = async () => {
@@ -156,7 +159,11 @@ const AppLockedOverlay = () => {
useUserStore.getState().disableAppLockRequests
)
return;
if (appLocked && appState === "active") {
if (
appLocked &&
appState === "active" &&
!useSettingStore.getState().requestBiometrics
) {
biometricUnlockAwaitingUserInput.current = true;
onUnlockAppRequested();
}

View File

@@ -485,7 +485,6 @@ export const useAppEvents = () => {
const onAppStateChanged = async (state: AppStateStatus) => {
if (state === "active") {
if (SettingsService.shouldLockAppOnEnterForeground()) {
console.log("Locked app on enter foreground");
useUserStore.getState().lockApp(true);
}
@@ -497,12 +496,7 @@ export const useAppEvents = () => {
) {
enabled(false);
}
if (SettingsService.canLockAppInBackground()) {
if (useSettingStore.getState().requestBiometrics) {
useSettingStore.getState().setRequestBiometrics(false);
return;
}
}
checkAutoBackup();
await reconnectSSE();
await checkForShareExtensionLaunchedInBackground();
@@ -543,10 +537,11 @@ export const useAppEvents = () => {
}
}
if (
SettingsService.get().privacyScreen ||
SettingsService.canLockAppInBackground()
(SettingsService.get().privacyScreen ||
SettingsService.canLockAppInBackground()) &&
!useSettingStore.getState().requestBiometrics
) {
!useSettingStore.getState().requestBiometrics ? enabled(true) : null;
enabled(true);
}
}
};

View File

@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React, { useRef, useState } from "react";
import { View } from "react-native";
import { TouchableHighlight, View } from "react-native";
import Menu, { MenuItem } from "react-native-reanimated-material-menu";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import { PressableButton } from "../../../components/ui/pressable";
@@ -126,6 +126,7 @@ export function SettingsPicker<T>({
}
>
<Dialog context="local" />
{options.map((item) => (
<MenuItem
key={getItemKey(item)}
@@ -138,9 +139,10 @@ export function SettingsPicker<T>({
onChange(item);
}
}}
underlayColor={colors.primary.hover}
style={{
backgroundColor: compareValue(currentValue, item)
? colors.secondary.background
? colors.selected.background
: "transparent",
width: "100%",
maxWidth: width

View File

@@ -154,7 +154,7 @@ async function updateNextBackupTime() {
* @param {string} context
* @returns {Promise<{path?: string, error?: Error}}>
*/
async function run(progress, context = "global") {
async function run(progress = false, context = "global") {
let androidBackupDirectory = await checkBackupDirExists(false, context);
if (!androidBackupDirectory)
return {

View File

@@ -26,6 +26,7 @@ import { MMKV } from "../common/database/mmkv";
import Storage from "../common/database/storage";
import { useSettingStore } from "../stores/use-setting-store";
import { ToastOptions, ToastManager } from "./event-manager";
import { useUserStore } from "../stores/use-user-store";
const KeychainConfig = Platform.select({
ios: {
@@ -122,6 +123,10 @@ async function getCredentials(title?: string, description?: string) {
async function validateUser(title: string, description?: string) {
try {
useUserStore.setState({
disableAppLockRequests: true
});
useSettingStore.getState().setAppDidEnterBackgroundForAction(true);
await FingerprintScanner.authenticate(
Platform.select({
ios: {
@@ -135,10 +140,18 @@ async function validateUser(title: string, description?: string) {
}
}) as AuthenticateIOS
);
useUserStore.setState({
disableAppLockRequests: false
});
useSettingStore.getState().setAppDidEnterBackgroundForAction(false);
FingerprintScanner.release();
return true;
} catch (error) {
const e = error as { name: string };
useUserStore.setState({
disableAppLockRequests: false
});
useSettingStore.getState().setAppDidEnterBackgroundForAction(false);
FingerprintScanner.release();
if (e.name === "DeviceLocked") {
ToastManager.show({

View File

@@ -28,6 +28,7 @@ import {
import { NotesnookModule } from "../utils/notesnook-module";
import { scale, updateSize } from "../utils/size";
import { DatabaseLogger } from "../common/database";
import { useUserStore } from "../stores/use-user-store";
function reset() {
const settings = get();
if (settings.reminder !== "off" && settings.reminder !== "useroff") {
@@ -195,6 +196,12 @@ function appEnteredBackground() {
}
function shouldLockAppOnEnterForeground() {
if (
useUserStore.getState().disableAppLockRequests ||
useSettingStore.getState().requestBiometrics
)
return false;
const settings = get();
if (!settings.appLockEnabled) return false;
if (settings.appLockTimer === -1) return false;

View File

@@ -1003,7 +1003,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2080;
CURRENT_PROJECT_VERSION = 2081;
DEVELOPMENT_TEAM = 53CWBG3QUC;
ENABLE_BITCODE = NO;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
@@ -1108,7 +1108,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 2080;
CURRENT_PROJECT_VERSION = 2081;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 53CWBG3QUC;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
@@ -1341,7 +1341,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2080;
CURRENT_PROJECT_VERSION = 2081;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 53CWBG3QUC;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
@@ -1384,7 +1384,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 2080;
CURRENT_PROJECT_VERSION = 2081;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 53CWBG3QUC;
@@ -1427,7 +1427,7 @@
CODE_SIGN_ENTITLEMENTS = "Make Note/Make Note.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2080;
CURRENT_PROJECT_VERSION = 2081;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 53CWBG3QUC;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
@@ -1532,7 +1532,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 2080;
CURRENT_PROJECT_VERSION = 2081;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 53CWBG3QUC;