Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

feat(appLock):auto-trigger-device-lock

Aswin Asok71bba36837b1
diff --git a/web/packages/new/photos/components/AppLockOverlay.tsx b/web/packages/new/photos/components/AppLockOverlay.tsx
index 717fa8a9aa..c94a94f30d 100644
--- a/web/packages/new/photos/components/AppLockOverlay.tsx
+++ b/web/packages/new/photos/components/AppLockOverlay.tsx
@@ -1072,6 +1072,7 @@ const DeviceLockUnlockForm: React.FC<{
const [error, setError] = useState<string>();
const [loading, setLoading] = useState(false);
const isUnlockInProgress = useRef(false);
+ const hasAutoTriggeredUnlock = useRef(false);
const handleDeviceLockUnlock = useCallback(async () => {
if (isUnlockInProgress.current) return;
@@ -1092,6 +1093,37 @@ const DeviceLockUnlockForm: React.FC<{
}
}, []);
+ useEffect(() => {
+ const maybeAutoTriggerUnlock = () => {
+ if (hasAutoTriggeredUnlock.current) return;
+ if (
+ typeof document == "undefined" ||
+ document.visibilityState !== "visible" ||
+ !document.hasFocus()
+ ) {
+ return;
+ }
+
+ hasAutoTriggeredUnlock.current = true;
+ void handleDeviceLockUnlock();
+ };
+
+ maybeAutoTriggerUnlock();
+ if (hasAutoTriggeredUnlock.current || typeof window == "undefined") {
+ return;
+ }
+
+ window.addEventListener("focus", maybeAutoTriggerUnlock);
+ document.addEventListener("visibilitychange", maybeAutoTriggerUnlock);
+ return () => {
+ window.removeEventListener("focus", maybeAutoTriggerUnlock);
+ document.removeEventListener(
+ "visibilitychange",
+ maybeAutoTriggerUnlock,
+ );
+ };
+ }, [handleDeviceLockUnlock]);
+
return (
<Stack spacing={0} useFlexGap alignItems="center">
<AppLockCard closeAction={closeAction}>