sudo-archive/src/index.tsx

60 lines
1.6 KiB
TypeScript
Raw Normal View History

import "core-js/stable";
2023-03-19 19:53:44 +00:00
import React, { Suspense } from "react";
2023-09-01 13:37:03 +00:00
import type { ReactNode } from "react";
2022-02-16 20:30:12 +00:00
import ReactDOM from "react-dom";
import { HelmetProvider } from "react-helmet-async";
import { BrowserRouter, HashRouter } from "react-router-dom";
2023-02-24 19:12:20 +00:00
import { registerSW } from "virtual:pwa-register";
2023-01-07 20:36:18 +00:00
import { ErrorBoundary } from "@/components/layout/ErrorBoundary";
2023-01-07 20:36:18 +00:00
import App from "@/setup/App";
2023-10-21 20:14:54 +00:00
import { conf } from "@/setup/config";
2023-06-18 12:10:26 +00:00
import i18n from "@/setup/i18n";
2023-02-21 20:45:14 +00:00
import "@/setup/ga";
2023-01-07 20:36:18 +00:00
import "@/setup/index.css";
2023-01-25 20:44:15 +00:00
import { initializeChromecast } from "./setup/chromecast";
2023-06-18 12:10:26 +00:00
import { SettingsStore } from "./state/settings/store";
import { initializeStores } from "./utils/storage";
2022-12-29 17:25:57 +00:00
// initialize
const key =
(window as any)?.__CONFIG__?.VITE_KEY ?? import.meta.env.VITE_KEY ?? null;
if (key) {
2023-02-22 20:41:13 +00:00
(window as any).initMW(conf().PROXY_URLS, key);
2022-12-29 17:25:57 +00:00
}
2023-01-25 20:44:15 +00:00
initializeChromecast();
2023-02-24 19:12:20 +00:00
registerSW({
immediate: true,
2023-02-24 19:12:20 +00:00
});
2021-07-13 22:31:37 +00:00
const LazyLoadedApp = React.lazy(async () => {
await initializeStores();
2023-06-18 12:10:26 +00:00
i18n.changeLanguage(SettingsStore.get().language ?? "en");
return {
default: App,
};
});
function TheRouter(props: { children: ReactNode }) {
const normalRouter = conf().NORMAL_ROUTER;
if (normalRouter) return <BrowserRouter>{props.children}</BrowserRouter>;
return <HashRouter>{props.children}</HashRouter>;
}
2021-07-13 22:31:37 +00:00
ReactDOM.render(
2022-02-16 20:30:12 +00:00
<React.StrictMode>
<ErrorBoundary>
<HelmetProvider>
<TheRouter>
<Suspense fallback="">
<LazyLoadedApp />
</Suspense>
</TheRouter>
</HelmetProvider>
2022-02-16 20:30:12 +00:00
</ErrorBoundary>
</React.StrictMode>,
document.getElementById("root")
2021-07-13 22:31:37 +00:00
);