diff --git a/apps/web/src/views/app-lock.tsx b/apps/web/src/views/app-lock.tsx index a5d439ea5..3c0645759 100644 --- a/apps/web/src/views/app-lock.tsx +++ b/apps/web/src/views/app-lock.tsx @@ -17,7 +17,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { PropsWithChildren, useEffect, useState } from "react"; +import { + PropsWithChildren, + useCallback, + useEffect, + useRef, + useState +} from "react"; import { useStore as useSettingStore } from "../stores/setting-store"; import { usePromise } from "@notesnook/common"; import { KeyChain } from "../interfaces/key-store"; @@ -29,6 +35,7 @@ import { startIdleDetection } from "../utils/idle-detection"; import { onPageVisibilityChanged } from "../utils/page-visibility"; import { closeOpenedDialog } from "../common/dialog-controller"; import { WebAuthn } from "../utils/webauthn"; +import { setDocumentTitle } from "../utils/dom"; export default function AppLock(props: PropsWithChildren) { const keychain = usePromise(async () => ({ @@ -38,6 +45,17 @@ export default function AppLock(props: PropsWithChildren) { const [error, setError] = useState(); const [isUnlocking, setIsUnlocking] = useState(false); const appLockSettings = useSettingStore((store) => store.appLockSettings); + const windowTitle = useRef(document.title); + + const lockApp = useCallback(() => { + if (keychain.status !== "fulfilled" || keychain.value.isLocked) return; + + windowTitle.current = document.title; + KeyChain.relock(); + closeOpenedDialog(); + setDocumentTitle(); + keychain.refresh(); + }, [keychain]); useEffect(() => { const { lockAfter, enabled } = appLockSettings; @@ -52,25 +70,17 @@ export default function AppLock(props: PropsWithChildren) { if (lockAfter > 0) { const stop = startIdleDetection( appLockSettings.lockAfter * 60 * 1000, - () => { - KeyChain.relock(); - closeOpenedDialog(); - keychain.refresh(); - } + lockApp ); return () => stop(); } else if (lockAfter === 0) { const stop = onPageVisibilityChanged((_, hidden) => { - if (hidden) { - KeyChain.relock(); - closeOpenedDialog(); - keychain.refresh(); - } + if (hidden) lockApp(); }); return () => stop(); } - }, [appLockSettings, keychain]); + }, [appLockSettings, lockApp, keychain]); if (keychain.status === "fulfilled" && !keychain.value.isLocked) return <>{props.children}; @@ -101,7 +111,10 @@ export default function AppLock(props: PropsWithChildren) { } await KeyChain.unlock({ type: "password", id: "primary", password }) - .then(() => keychain.refresh()) + .then(() => { + setDocumentTitle(windowTitle.current); + keychain.refresh(); + }) .catch((e) => { setError( typeof e === "string"