feat(webui): appearance customization — theme/accent/background/fonts/a11y (phase 2)
Wires the Phase 1 store into a full appearance layer. ThemeContext is rewritten to load/save UiAppearance from the server (with a localStorage anti-flash cache + a one-time migration of the legacy per-browser theme keys), apply ~12 dimensions to <html>, and theme the login page pre-auth. New Settings controls (外观 / 数据与格式): free-hex accent (+ presets + apply scope), dark intensity (soft / OLED black), sidebar style, background (solid / gradient / uploaded image with opacity + blur), font presets, UI scale, reduce-motion, high-contrast, default-collapsed sidebar, 12h/24h time format (wired into logs + overview timestamps). - index.html gains a pre-paint bootstrap script that applies the cached theme before the bundle mounts, eliminating the dark/OLED/scale FOUC. - server saveUiConfig is now a section-level merge so appearance-only and layout-only saves never clobber each other. - reduce-motion uses Framer MotionConfig; the background renders on a fixed layer revealed by transparent app roots; custom-accent hex and ui-scale are validated/clamped before use (localStorage-tamper hardening). Verified across 2 adversarial review rounds (FOUC + CSS-injection + impure state-updater + ref-staleness all fixed).
This commit is contained in:
9 files changed
+1028
-308
No files matched your search
@@ -6,6 +6,7 @@ import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Sidebar } from '@/components/layout/sidebar';
|
||||
import { TopBar } from '@/components/layout/top-bar';
|
||||
import { useMediaQuery } from '@/hooks/use-media-query';
|
||||
import { useTheme } from '@/contexts/ThemeContext';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface MainLayoutProps {
|
||||
@@ -16,9 +17,16 @@ interface MainLayoutProps {
|
||||
|
||||
export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
||||
const isMobile = !useMediaQuery('(min-width: 768px)');
|
||||
const { appearance } = useTheme();
|
||||
const [collapsed, setCollapsed] = useState(() => {
|
||||
return localStorage.getItem('snowluma_sidebar_collapsed') === '1';
|
||||
// An explicit per-browser toggle wins; otherwise fall back to the
|
||||
// operator's `sidebarDefaultCollapsed` appearance preference.
|
||||
const explicit = localStorage.getItem('snowluma_sidebar_collapsed');
|
||||
if (explicit === '1') return true;
|
||||
if (explicit === '0') return false;
|
||||
return appearance.sidebarDefaultCollapsed;
|
||||
});
|
||||
const customBg = appearance.background.type !== 'none';
|
||||
const [mobileOpen, setMobileOpen] = useState(false);
|
||||
const pathname = useRouterState({ select: (s) => s.location.pathname });
|
||||
|
||||
@@ -27,7 +35,7 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
||||
}, [collapsed]);
|
||||
|
||||
return (
|
||||
<div className="flex h-screen w-screen overflow-hidden bg-background text-foreground">
|
||||
<div className={cn('flex h-screen w-screen overflow-hidden text-foreground', customBg ? 'bg-transparent' : 'bg-background')}>
|
||||
{/* Desktop sidebar */}
|
||||
{!isMobile && (
|
||||
<motion.aside
|
||||
|
||||
Reference in new issue
Block a user