From ace8e7d6917ebad08e2d6aed01d0703ce31eff0d Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Sun, 15 Dec 2024 13:35:43 +0800 Subject: [PATCH] feat: custom bg - window.CustomBackgroundImage --- src/App.tsx | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c4da0e3..e647c21 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,10 +1,11 @@ import { useQuery } from "@tanstack/react-query" -import React, { useCallback, useEffect } from "react" +import React, { useCallback } from "react" import { Route, BrowserRouter as Router, Routes } from "react-router-dom" import Footer from "./components/Footer" import Header from "./components/Header" import { fetchSetting } from "./lib/nezha-api" +import { cn } from "./lib/utils" import ErrorPage from "./pages/ErrorPage" import NotFound from "./pages/NotFound" import Server from "./pages/Server" @@ -52,12 +53,6 @@ const App: React.FC = () => { }) }, []) - useEffect(() => { - if (settingData?.data?.custom_code) { - InjectContext(settingData?.data?.custom_code) - } - }, [settingData?.data?.custom_code]) - if (error) { return } @@ -66,10 +61,28 @@ const App: React.FC = () => { return null } + if (settingData?.data?.custom_code) { + InjectContext(settingData?.data?.custom_code) + } + + const customBackgroundImage = + // @ts-expect-error ShowNetTransfer is a global variable + (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined + return ( -
-
+
+
} />