echoes/frontend/app/root.tsx

80 lines
1.9 KiB
TypeScript
Raw Normal View History

import {
Links,
Meta,
Outlet,
2024-11-27 19:52:49 +08:00
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import { HubProvider } from "core/hub";
import { MessageProvider, MessageContainer } from "hooks/message";
2024-11-27 19:52:49 +08:00
import "~/index.css";
export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1"
/>
<meta
name="generator"
content="echoes"
/>
<Meta />
<Links />
</head>
2024-11-27 19:52:49 +08:00
<body suppressHydrationWarning={true}>
<HubProvider>
<MessageProvider>
<MessageContainer />
<Outlet />
</MessageProvider>
</HubProvider>
<ScrollRestoration />
<script
dangerouslySetInnerHTML={{
__html: `
(function() {
// 立即应用系统主题
function applyTheme(isDark) {
document.documentElement.classList.toggle('dark', isDark);
}
// 获取系统主题并立即应用
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
applyTheme(darkModeMediaQuery.matches);
// 添加主题变化监听
try {
// 现代浏览器的方式
darkModeMediaQuery.addEventListener('change', (e) => {
applyTheme(e.matches);
});
} catch (e) {
// 兼容旧版浏览器
darkModeMediaQuery.addListener((e) => {
applyTheme(e.matches);
});
}
})()
`,
}}
/>
<Scripts />
</body>
</html>
);
}
export default function App() {
return (
2024-11-27 19:52:49 +08:00
<Layout>
<Outlet />
</Layout>
);
}