import React, {useEffect, useState} from 'react'; import ReactDOM from 'react-dom/client'; import {BrowserRouter, Routes, Route, Outlet} from 'react-router-dom'; import '@/app/globals.css'; import '@/lib/i18n'; import {listen} from '@tauri-apps/api/event'; import * as tauri from '@/lib/tauri'; import PulseLoader from '@/components/ui/PulseLoader'; import {useTranslations} from '@/lib/i18n'; listen('auth-success', () => window.location.reload()); type MigrationState = 'pending' | 'error' | 'done'; function AppInitializer({children}: { children: React.ReactNode }) { const t = useTranslations(); const [state, setState] = useState('pending'); const [retryCount, setRetryCount] = useState(0); useEffect(function (): void { setState('pending'); tauri.autoMigrateElectron().then(function (result): void { if (result.migrated) { window.location.reload(); } else if (result.error) { setState('error'); } else { setState('done'); } }).catch(function (): void { setState('error'); }); }, [retryCount]); if (state === 'pending') { return (
); } if (state === 'error') { return (

{t('migration.autoErrorTitle')}

{t('migration.autoErrorText')}

{t('migration.autoErrorContinueWarning')}

); } return <>{children}; } import ScribeShell from '@/components/layout/ScribeShell'; import LoginWrapper from '@/app/login/LoginWrapper'; import HomePage from '@/app/HomePage'; import BookPage from '@/app/book/BookPage'; import ChapterPage from '@/app/book/ChapterPage'; import BookLayout from '@/app/book/BookLayout'; import LoginPage from '@/app/login/login/page'; import RegisterPage from '@/app/login/register/page'; import ResetPasswordPage from '@/app/login/reset-password/page'; import OfflineLoginPage from '@/app/login/offline/page'; function LoginShell() { return ( ); } function MainShell() { return ( ); } function BookShell() { return ( ); } ReactDOM.createRoot(document.getElementById('root')!).render( {/* Login routes — dedicated window, no ScribeShell */} }> }/> }/> }/> }/> }/> {/* Main app routes — with ScribeShell */} }> }/> }> }/> }/> );