diff --git a/frontend/src/router/guard/index.ts b/frontend/src/router/guard/index.ts index a4123e6..11f3dc2 100644 --- a/frontend/src/router/guard/index.ts +++ b/frontend/src/router/guard/index.ts @@ -1,25 +1,52 @@ import type { Router } from 'vue-router' -let installChecked = false -let isInstalled = false +const INSTALL_CACHE_KEY = 'app_installed' +const INSTALL_CACHE_EXPIRY = 24 * 60 * 60 * 1000 + +function getCachedInstallStatus(): boolean | null { + try { + const cached = localStorage.getItem(INSTALL_CACHE_KEY) + if (cached) { + const { installed, timestamp } = JSON.parse(cached) + if (Date.now() - timestamp < INSTALL_CACHE_EXPIRY) { + return installed + } + } + } + catch { + return null + } + return null +} + +function setCachedInstallStatus(installed: boolean) { + try { + localStorage.setItem(INSTALL_CACHE_KEY, JSON.stringify({ + installed, + timestamp: Date.now(), + })) + } + catch { + } +} export function resetInstallCheck() { - installChecked = false - isInstalled = false + localStorage.removeItem(INSTALL_CACHE_KEY) } async function checkInstallStatus(): Promise { - if (installChecked) return isInstalled + const cached = getCachedInstallStatus() + if (cached !== null) return cached + try { const res = await fetch('/api/install/status') const data = await res.json() - isInstalled = data?.data?.installed ?? false - installChecked = true - return isInstalled + const installed = data?.data?.installed ?? false + setCachedInstallStatus(installed) + return installed } catch { - installChecked = true - isInstalled = false + setCachedInstallStatus(false) return false } }