diff --git a/app/providers.tsx b/app/providers.tsx index e2363c0..eeef9c7 100755 --- a/app/providers.tsx +++ b/app/providers.tsx @@ -5,23 +5,44 @@ import { ThemeProvider } from '@/components/ThemeToggle' import { ToastProvider } from '@/hooks/use-toast' import { SplashScreen } from '@/components/SplashScreen' +const SPLASH_SESSION_KEY = 'offlineacademy:splash-seen' + export function Providers({ children }: { children: React.ReactNode }) { const [showSplash, setShowSplash] = React.useState(true) - // Safety fallback: force hide after 5 seconds max + React.useLayoutEffect(() => { + try { + if (sessionStorage.getItem(SPLASH_SESSION_KEY) === 'true') { + setShowSplash(false) + } + } catch { + setShowSplash(false) + } + }, []) + React.useEffect(() => { - const timer = setTimeout(() => setShowSplash(false), 5000) - return () => clearTimeout(timer) + if (!showSplash) return + const timer = window.setTimeout(() => setShowSplash(false), 2500) + return () => window.clearTimeout(timer) + }, [showSplash]) + + const completeSplash = React.useCallback(() => { + try { + sessionStorage.setItem(SPLASH_SESSION_KEY, 'true') + } catch { + // Storage can be unavailable in hardened/private browser modes. + } + setShowSplash(false) }, []) return ( + {children} {showSplash && ( - setShowSplash(false)} minDuration={1500} /> + )} - {!showSplash && children} ) -} \ No newline at end of file +}