Skip to content

armgit / ente

Public Imported from GitHub
0

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

chore(use-app-lock-route):more-verbose-comments-added

Aswin Asok17fbcd8cf888
diff --git a/desktop/src/main/services/store.ts b/desktop/src/main/services/store.ts
index a308f419dc..1123b58a53 100644
--- a/desktop/src/main/services/store.ts
+++ b/desktop/src/main/services/store.ts
@@ -86,6 +86,12 @@ export const appLockConfigFromSafeStorage = ():
| PersistedAppLockConfig
| undefined => {
const config = appLockConfigStringFromSafeStorage();
+
+ /*
+ * if a key is not found then it will naturally return undefined, so
+ * therefore if the config is not present returning undefined
+ */
+
if (!config) return undefined;
return parsePersistedAppLockConfig(config);
diff --git a/web/apps/photos/src/components/utils/use-app-lock-route.ts b/web/apps/photos/src/components/utils/use-app-lock-route.ts
index 6a7992954d..8dd517783b 100644
--- a/web/apps/photos/src/components/utils/use-app-lock-route.ts
+++ b/web/apps/photos/src/components/utils/use-app-lock-route.ts
@@ -11,11 +11,21 @@ interface DesktopAppLockRouteState {
shouldBlockAppLockRouteTransition: boolean;
}
+/**
+ * Since the app lock has its own separate page, when navigating there,
+ * we save the user's current location so they can return to the same
+ * page on unlock.
+ */
const rememberAppLockReturnTo = (path: string) => {
if (path === APP_LOCK_ROUTE) return;
sessionStorage.setItem(APP_LOCK_RETURN_TO_KEY, path);
};
+/**
+ * Once the user has unlocked the application, navigate them back to the page
+ * they were previously on (i.e., the page that was saved when the app locked).
+ */
+
const consumeAppLockReturnTo = (): string | null => {
const returnTo = sessionStorage.getItem(APP_LOCK_RETURN_TO_KEY);
sessionStorage.removeItem(APP_LOCK_RETURN_TO_KEY);
@@ -30,18 +40,33 @@ export const useDesktopAppLockRoute = (
const router = useRouter();
const showLockPage = isDesktop && isLocked && lockScreenMode === "lock";
+ /**
+ * This useEffect runs when you are not in the /lock route,
+ * it saves the current route in sessionStorage
+ * and redirects the app to the /lock page.
+ */
useEffect(() => {
+ /**
+ * Since the app lock is currently available only on desktop,
+ * ensure that it is ready before navigating to the lock page.
+ */
if (!isDesktop || !isAppLockReady || !showLockPage) return;
+ // if the current page is not of the applock then saving it before navigation.
if (router.asPath !== APP_LOCK_ROUTE) {
rememberAppLockReturnTo(router.asPath);
}
+ // if the current page is not applock, then navgiating to the applock page.
if (router.pathname !== APP_LOCK_ROUTE) {
void router.replace(APP_LOCK_ROUTE);
}
}, [isAppLockReady, showLockPage, router, router.asPath, router.pathname]);
+ /**
+ * This useEffect is just returning you to the page in which you where before
+ * the app lock happened.
+ */
useEffect(() => {
if (
!isDesktop ||