mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
fix: ForceTheme
This commit is contained in:
parent
5138a054f0
commit
8248d11ad0
13
src/App.tsx
13
src/App.tsx
@ -6,6 +6,7 @@ import { Route, BrowserRouter as Router, Routes } from "react-router-dom"
|
|||||||
import ErrorBoundary from "./components/ErrorBoundary"
|
import ErrorBoundary from "./components/ErrorBoundary"
|
||||||
import Footer from "./components/Footer"
|
import Footer from "./components/Footer"
|
||||||
import Header from "./components/Header"
|
import Header from "./components/Header"
|
||||||
|
import { useTheme } from "./hooks/use-theme"
|
||||||
import { InjectContext } from "./lib/inject"
|
import { InjectContext } from "./lib/inject"
|
||||||
import { fetchSetting } from "./lib/nezha-api"
|
import { fetchSetting } from "./lib/nezha-api"
|
||||||
import { cn } from "./lib/utils"
|
import { cn } from "./lib/utils"
|
||||||
@ -22,8 +23,14 @@ const App: React.FC = () => {
|
|||||||
refetchOnWindowFocus: true,
|
refetchOnWindowFocus: true,
|
||||||
})
|
})
|
||||||
const { i18n } = useTranslation()
|
const { i18n } = useTranslation()
|
||||||
|
const { setTheme } = useTheme()
|
||||||
const [isCustomCodeInjected, setIsCustomCodeInjected] = useState(false)
|
const [isCustomCodeInjected, setIsCustomCodeInjected] = useState(false)
|
||||||
|
|
||||||
|
// 检测是否强制指定了主题颜色
|
||||||
|
const forceTheme =
|
||||||
|
// @ts-expect-error ForceTheme is a global variable
|
||||||
|
(window.ForceTheme as string) !== "" ? window.ForceTheme : undefined
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (settingData?.data?.custom_code) {
|
if (settingData?.data?.custom_code) {
|
||||||
InjectContext(settingData?.data?.custom_code)
|
InjectContext(settingData?.data?.custom_code)
|
||||||
@ -31,6 +38,12 @@ const App: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [settingData?.data?.custom_code])
|
}, [settingData?.data?.custom_code])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (forceTheme === "dark" || forceTheme === "light") {
|
||||||
|
setTheme(forceTheme)
|
||||||
|
}
|
||||||
|
}, [forceTheme])
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return <ErrorPage code={500} message={error.message} />
|
return <ErrorPage code={500} message={error.message} />
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user