Skip to content

Commit

Permalink
feat: limit auto lock from bg not in web version
Browse files Browse the repository at this point in the history
  • Loading branch information
jimcase committed May 8, 2024
1 parent 9986555 commit 48fa8fa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
34 changes: 19 additions & 15 deletions src/ui/components/AppWrapper/hooks/useActivityTimer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from "react";
import { App } from "@capacitor/app";
import { getPlatforms } from "@ionic/react";
import { useAppDispatch } from "../../../../store/hooks";
import { logout } from "../../../../store/reducers/stateCache";

Expand Down Expand Up @@ -28,23 +29,26 @@ const useActivityTimer = () => {
};

useEffect(() => {
const pauseListener = App.addListener("pause", () => {
const now = new Date().getTime();
setPauseTimestamp(now);
});
const platforms = getPlatforms();
if (!platforms.includes("mobileweb")) {
const pauseListener = App.addListener("pause", () => {
const now = new Date().getTime();
setPauseTimestamp(now);
});

const resumeListener = App.addListener("resume", () => {
const now = new Date().getTime();
if (now - pauseTimestamp > pauseTimeout) {
dispatch(logout());
}
});
const resumeListener = App.addListener("resume", () => {
const now = new Date().getTime();
if (now - pauseTimestamp > pauseTimeout) {
dispatch(logout());
}
});

return () => {
pauseListener.remove();
resumeListener.remove();
clearTimer();
};
return () => {
pauseListener.remove();
resumeListener.remove();
clearTimer();
};
}
}, [pauseTimestamp]);

useEffect(() => {
Expand Down
33 changes: 19 additions & 14 deletions src/ui/components/PasscodeModule/PasscodeModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { backspaceSharp, fingerPrintSharp } from "ionicons/icons";
import { PasscodeModuleProps } from "./PasscodeModule.types";
import "./PasscodeModule.scss";
import { PASSCODE_MAPPING } from "../../globals/types";
import { useBiometricAuth } from "../../hooks/useBiometrics";

const PasscodeModule = ({
error,
Expand All @@ -11,6 +12,7 @@ const PasscodeModule = ({
handleRemove,
handleBiometricButtonClick,
}: PasscodeModuleProps) => {
const { biometricInfo } = useBiometricAuth();
const numbers = PASSCODE_MAPPING.numbers;
const labels = PASSCODE_MAPPING.labels;
const rows = [];
Expand Down Expand Up @@ -49,20 +51,23 @@ const PasscodeModule = ({
>
{rowIndex === rows.length - 1 && (
<IonCol>
<IonButton
data-testid={"passcode-button-#"}
className="passcode-module-number-button"
onClick={() =>
handleBiometricButtonClick &&
handleBiometricButtonClick()
}
>
<IonIcon
slot="icon-only"
className="passcode-module-fingerprint-icon"
icon={fingerPrintSharp}
/>
</IonButton>
{handleBiometricButtonClick &&
biometricInfo?.isAvailable ? (
<IonButton
data-testid={"passcode-button-#"}
className="passcode-module-number-button"
onClick={() =>
handleBiometricButtonClick &&
handleBiometricButtonClick()
}
>
<IonIcon
slot="icon-only"
className="passcode-module-fingerprint-icon"
icon={fingerPrintSharp}
/>
</IonButton>
) : null}
</IonCol>
)}

Expand Down
1 change: 0 additions & 1 deletion src/ui/hooks/useBiometrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useActivityTimer } from "../components/AppWrapper/hooks/useActivityTime

const useBiometricAuth = () => {
const [biometricInfo, setBiometricInfo] = useState<any>();
const dispatch = useDispatch();
const { setPauseTimestamp } = useActivityTimer();

const checkBiometry = async () => {
Expand Down

0 comments on commit 48fa8fa

Please sign in to comment.