/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useEffect, useMemo, useState } from 'react'; import i18next from 'i18next'; // 读品牌值:localStorage → window.__WL_BRAND__(index.html 内联脚本写入)→ 空。 // 不用 getSystemName/getLogo —— 它们的终极兜底是 'Weelinking' / '/logo.svg'(老品牌), // 这里要严格白牌,宁可让旋转环单独转,也不能露出老标识。 // 接 window 一层是为了和首屏 splash 对齐:冷启动 + 用户立刻进了懒路由的窗口期, // localStorage 还没被 /api/status 灌满,但 window 已有后端启动注入的品牌。 const readBrand = (key, windowKey) => { try { const v = localStorage.getItem(key); if (v && v !== 'undefined' && v !== 'null') return v; } catch { /* 隐私模式:fall through */ } if (typeof window !== 'undefined' && window.__WL_BRAND__) { return window.__WL_BRAND__[windowKey] || ''; } return ''; }; // 加载文案根据浏览器语言决定,避免 i18n 还没初始化时硬编码中文。 const getLoadingText = () => { if (i18next.isInitialized) return i18next.t('加载中...'); const lang = ( (typeof navigator !== 'undefined' && navigator.language) || 'zh' ).toLowerCase(); return lang.startsWith('zh') ? '加载中...' : 'Loading...'; }; const Loading = () => { const systemName = readBrand('system_name', 'name'); const logo = readBrand('logo', 'logo'); const [logoFailed, setLogoFailed] = useState(false); // 防御性:同实例内 logo URL 变化(罕见,但 /api/status 在同一 Loading 生命周期内回来时可能发生), // 重置失败标志,避免新 URL 也被错判成"已坏" useEffect(() => { setLogoFailed(false); }, [logo]); const loadingText = useMemo(getLoadingText, []); const monogram = useMemo(() => { const s = systemName.trim(); return s ? Array.from(s)[0].toUpperCase() : ''; }, [systemName]); const showImg = logo && !logoFailed; // 没 logo 也没名字:旋转环里留空,避免出现"空着的渐变色方块" const showMono = !showImg && monogram; return (
{showImg && ( {systemName setLogoFailed(true)} /> )} {showMono && {monogram}}
{systemName &&
{systemName}
}
{loadingText}
); }; export default Loading;