import "core-js/stable"; import "./stores/__old/imports"; import "@/setup/ga"; import "@/setup/index.css"; import React, { Suspense } from "react"; import type { ReactNode } from "react"; import ReactDOM from "react-dom"; import { HelmetProvider } from "react-helmet-async"; import { BrowserRouter, HashRouter } from "react-router-dom"; import { useAsync } from "react-use"; import { registerSW } from "virtual:pwa-register"; import { useAuthRestore } from "@/hooks/auth/useAuthRestore"; import { ErrorBoundary } from "@/pages/errors/ErrorBoundary"; import { MigrationPart } from "@/pages/parts/migrations/MigrationPart"; import App from "@/setup/App"; import { conf } from "@/setup/config"; import i18n from "@/setup/i18n"; import { BookmarkSyncer } from "@/stores/bookmarks/BookmarkSyncer"; import { useLanguageStore } from "@/stores/language"; import { ProgressSyncer } from "@/stores/progress/ProgressSyncer"; import { useThemeStore } from "@/stores/theme"; import { initializeChromecast } from "./setup/chromecast"; import { initializeOldStores } from "./stores/__old/migrations"; // initialize const key = (window as any)?.__CONFIG__?.VITE_KEY ?? import.meta.env.VITE_KEY ?? null; if (key) { (window as any).initMW(conf().PROXY_URLS, key); } initializeChromecast(); registerSW({ immediate: true, }); function LoadingScreen(props: { type: "user" | "lazy" }) { return

Loading: {props.type}

; } function AuthWrapper() { const status = useAuthRestore(); // TODO what to do when failing to load user data? if (status.loading) return ; if (status.error) return

Failed to fetch user data

; return ; } function MigrationRunner() { const status = useAsync(async () => { i18n.changeLanguage(useLanguageStore.getState().language); await initializeOldStores(); }, []); if (status.loading) return ; if (status.error) return

Failed to migrate

; return ; } function TheRouter(props: { children: ReactNode }) { const normalRouter = conf().NORMAL_ROUTER; if (normalRouter) return {props.children}; return {props.children}; } function ThemeProvider(props: { children: ReactNode }) { const theme = useThemeStore((s) => s.theme); const themeSelector = theme ? `theme-${theme}` : undefined; return
{props.children}
; } ReactDOM.render( }> , document.getElementById("root") );