Files
Genarrative/src/main.tsx
T
menghao 03a4410272
Project CI / Native shell tests (push) Failing after 11m56s
Project CI / Repository checks (push) Successful in 1m5s
Project CI / Frontend tests (push) Successful in 3m20s
Project CI / Backend tests (push) Successful in 4m1s
game agent无限画布开发 (#136)
主要工作是共享同一套“画布内核与通用 UI 源码”,网站和 Tauri 只分别实现宿主适配层。

---------

Co-authored-by: 段舒康 <kdletters@qq.com>
Co-authored-by: kdletters <kdletters@qq.com>
Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/136
Co-authored-by: menghao <mh18530625731@163.com>
Co-committed-by: menghao <mh18530625731@163.com>
2026-08-12 10:54:16 +08:00

85 lines
2.4 KiB
TypeScript

/* eslint-disable react-refresh/only-export-components */
import '@genarrative/image-canvas-react/styles.css';
import 'overlayscrollbars/styles/overlayscrollbars.css';
import './index.css';
import {StrictMode, Suspense} from 'react';
import {createRoot} from 'react-dom/client';
import {FloatingFeedbackEntry} from './components/common/FloatingFeedbackEntry';
import {getInitialPlatformDesktopLayout} from './components/platform-entry/platformEntryResponsive';
import {stabilizeMobileViewportKeyboardFocus} from './mobileViewportKeyboardFocus';
import {lockMobileViewportZoom} from './mobileViewportZoomLock';
import {
resolveAppRoute,
shouldUseRecommendationRouteLoading,
} from './routing/appRoutes';
import {RouteImageReadyGate} from './routing/RouteImageReadyGate';
import {RouteLoadingScreen} from './routing/RouteLoadingScreen';
import {
getHostRuntime,
refreshNativeAppHostRuntime,
} from './services/host-bridge/hostBridge';
type AppRoot = ReturnType<typeof createRoot>;
declare global {
interface Window {
__tavernRealmsRoot__?: AppRoot;
}
}
const route = resolveAppRoute(window.location.pathname);
const rootElement = document.getElementById('root');
if (!rootElement) {
throw new Error('Missing #root container');
}
function markWechatMiniProgramRuntime() {
if (getHostRuntime().kind === 'wechat_mini_program') {
document.documentElement.dataset.wechatMiniProgramRuntime = 'true';
}
}
const root = window.__tavernRealmsRoot__ ??= createRoot(rootElement);
const RouteComponent = route.Component;
const routeElement = <RouteComponent {...(route.componentProps ?? {})} />;
const shouldGateRouteImages = shouldUseRecommendationRouteLoading(
window.location.pathname,
getInitialPlatformDesktopLayout(),
);
lockMobileViewportZoom();
stabilizeMobileViewportKeyboardFocus();
markWechatMiniProgramRuntime();
void refreshNativeAppHostRuntime();
root.render(
<StrictMode>
<Suspense
fallback={
shouldGateRouteImages ? (
<RouteLoadingScreen
eyebrow={route.loadingEyebrow}
text={route.loadingText}
/>
) : null
}
>
{shouldGateRouteImages ? (
<RouteImageReadyGate
eyebrow={route.loadingEyebrow}
text={route.loadingText}
>
{routeElement}
</RouteImageReadyGate>
) : (
routeElement
)}
</Suspense>
<FloatingFeedbackEntry />
</StrictMode>,
);