Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): crossfade static and dynamic wallpapers
DavidShen3ce061daf35e
diff --git a/apps/desktop/src/renderer/components/layout/WallpaperVideo.tsx b/apps/desktop/src/renderer/components/layout/WallpaperVideo.tsxindex 69f0819cec..388e3a26e5 100644--- a/apps/desktop/src/renderer/components/layout/WallpaperVideo.tsx+++ b/apps/desktop/src/renderer/components/layout/WallpaperVideo.tsx@@ -1,4 +1,4 @@-import { useEffect, useLayoutEffect, useRef, useState } from 'react';+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';import { createPortal } from 'react-dom';import type { WallpaperId, WallpaperMotion } from '@/../shared/appearanceSettings';import { useReducedMotion } from '@/hooks/useReducedMotion';@@ -16,42 +16,70 @@ export function WallpaperVideo({}) {const reducedMotion = useReducedMotion();const src = getWallpaperVideo(wallpaperId);- if (motion !== 'dynamic' || reducedMotion || !src) return null;+ if (reducedMotion || !src) return null;+ return <WallpaperPlayback key={wallpaperId} wallpaperId={wallpaperId} active={motion === 'dynamic'} />;+}++type PlaybackProps = { active: boolean; onExited: () => void };++function WallpaperPlayback({ wallpaperId, active }: { wallpaperId: WallpaperId; active: boolean }) {+ const [retained, setRetained] = useState(active);+ const onExited = useCallback(() => setRetained(false), []);+ useEffect(() => { if (active) setRetained(true); }, [active]);+ if (!active && !retained) return null;+ const src = getWallpaperVideo(wallpaperId)!;return usesCdnWallpaperVideo(wallpaperId)- ? <AdaptiveWallpaper key={wallpaperId} wallpaperId={wallpaperId} />- : <PlayingWallpaper key={src} src={src} />;+ ? <AdaptiveWallpaper wallpaperId={wallpaperId} active={active} onExited={onExited} />+ : <PlayingWallpaper src={src} active={active} onExited={onExited} />;}-function AdaptiveWallpaper({ wallpaperId }: { wallpaperId: WallpaperId }) {+function AdaptiveWallpaper({ wallpaperId, active, onExited }: { wallpaperId: WallpaperId } & PlaybackProps) {const tier = useWallpaperVideoTier();const [hdFailed, setHdFailed] = useState(false);const [hdSrc, setHdSrc] = useState<string | null>(null);useEffect(() => {- if (tier !== 'hd' || hdFailed || hdSrc) return;+ if (!active || tier !== 'hd' || hdFailed || hdSrc) return;let current = true;void window.electronAPI?.appearanceSettings?.ensureWallpaperVideo?.(wallpaperId).then(url => { if (current) setHdSrc(url); }).catch(() => undefined);return () => { current = false; };- }, [wallpaperId, tier, hdFailed, hdSrc]);+ }, [wallpaperId, tier, hdFailed, hdSrc, active]);const useHd = tier === 'hd' && !hdFailed && !!hdSrc;const src = useHd ? hdSrc : getWallpaperVideo(wallpaperId);return src ? (<PlayingWallpaperkey={src}src={src}+ active={active}+ onExited={onExited}onFailure={useHd ? () => setHdFailed(true) : undefined}/>) : null;}-function PlayingWallpaper({ src, onFailure }: { src: string; onFailure?: () => void }) {+function PlayingWallpaper({ src, onFailure, active, onExited }: { src: string; onFailure?: () => void } & PlaybackProps) {const ref = useRef<HTMLVideoElement>(null);+ const layerRef = useRef<HTMLDivElement>(null);const onFailureRef = useRef(onFailure);onFailureRef.current = onFailure;const [ready, setReady] = useState(false);const [failed, setFailed] = useState(false);+ useEffect(() => {+ if (active) return;+ if (!ready || failed || !layerRef.current) {+ onExited();+ return;+ }+ // Bound decoder retention even when transitionend is suppressed (e.g. hidden+ // windows). Read the CSS token's resolved duration rather than duplicating it.+ const duration = getComputedStyle(layerRef.current).transitionDuration;+ const ms = (parseFloat(duration) || 0) * (duration.endsWith('ms') ? 1 : 1000);+ const timeout = window.setTimeout(onExited, ms);+ return () => window.clearTimeout(timeout);+ }, [active, ready, failed, onExited]);+useLayoutEffect(() => {if (!ready || failed) return;document.documentElement.dataset.wallpaperMotion = 'dynamic';@@ -100,9 +128,13 @@ function PlayingWallpaper({ src, onFailure }: { src: string; onFailure?: () => vif (failed) return null;return createPortal(<div+ ref={layerRef}className="app-wallpaper-video"aria-hidden="true"- style={{ visibility: ready ? 'visible' : 'hidden' }}+ style={{ opacity: ready && active ? 1 : 0 }}+ onTransitionEnd={event => {+ if (event.target === event.currentTarget && event.propertyName === 'opacity' && !active) onExited();+ }}><videoref={ref}diff --git a/apps/desktop/src/renderer/components/layout/__tests__/WallpaperVideo.test.tsx b/apps/desktop/src/renderer/components/layout/__tests__/WallpaperVideo.test.tsxindex e12d5bf0a7..9e5e83c724 100644--- a/apps/desktop/src/renderer/components/layout/__tests__/WallpaperVideo.test.tsx+++ b/apps/desktop/src/renderer/components/layout/__tests__/WallpaperVideo.test.tsx@@ -31,6 +31,7 @@ describe('dynamic wallpaper lifecycle', () => {document.documentElement.removeAttribute(HIDDEN_ANIMATION_ATTR);vi.restoreAllMocks();vi.unstubAllGlobals();+ vi.useRealTimers();});it('does not create a decoder for static, reduced motion or unsupported artwork', () => {state.cdn = false;@@ -56,11 +57,60 @@ describe('dynamic wallpaper lifecycle', () => {await act(async () => document.documentElement.removeAttribute(HIDDEN_ANIMATION_ATTR));expect(video.play).toHaveBeenCalledTimes(2);rerender(<WallpaperVideo wallpaperId="cindy-window" motion="static" />);- expect(document.querySelector('video')).toBeNull();+ await waitFor(() => expect(document.querySelector('video')).toBeNull());expect(video.getAttribute('src')).toBeNull();expect(video.load).toHaveBeenCalled();expect(document.documentElement.dataset.wallpaperMotion).toBeUndefined();});+ it('fades decoded video over the still, retaining it only until the exit finishes', () => {+ vi.useFakeTimers();+ state.cdn = false;+ const { rerender } = render(<WallpaperVideo wallpaperId="cindy-window" motion="dynamic" />);+ const video = document.querySelector('video')!;+ const layer = video.parentElement!;+ layer.style.transitionDuration = '0.2s';+ expect(layer.style.opacity).toBe('0');+ fireEvent.playing(video);+ expect(layer.style.opacity).toBe('1');+ rerender(<WallpaperVideo wallpaperId="cindy-window" motion="static" />);+ expect(layer.style.opacity).toBe('0');+ expect(document.querySelector('video')).toBe(video);+ expect(document.documentElement.dataset.wallpaperMotion).toBe('dynamic');+ act(() => vi.advanceTimersByTime(100));+ expect(video.getAttribute('src')).not.toBeNull();+ fireEvent.transitionEnd(layer, { propertyName: 'opacity' });+ expect(document.querySelector('video')).toBeNull();+ expect(video.getAttribute('src')).toBeNull();+ expect(document.documentElement.dataset.wallpaperMotion).toBeUndefined();+ });+ it('reverses a rapid toggle without replacing the decoder or leaving a stale exit timer', () => {+ vi.useFakeTimers();+ state.cdn = false;+ const { rerender } = render(<WallpaperVideo wallpaperId="cindy-window" motion="dynamic" />);+ const video = document.querySelector('video')!;+ video.parentElement!.style.transitionDuration = '200ms';+ fireEvent.playing(video);+ rerender(<WallpaperVideo wallpaperId="cindy-window" motion="static" />);+ act(() => vi.advanceTimersByTime(100));+ rerender(<WallpaperVideo wallpaperId="cindy-window" motion="dynamic" />);+ act(() => vi.advanceTimersByTime(250));+ expect(document.querySelector('video')).toBe(video);+ expect(video.parentElement!.style.opacity).toBe('1');+ rerender(<WallpaperVideo wallpaperId="cindy-window" motion="static" />);+ act(() => vi.advanceTimersByTime(200));+ expect(document.querySelector('video')).toBeNull();+ expect(video.getAttribute('src')).toBeNull();+ });+ it('releases immediately if reduced motion is enabled during a fade', () => {+ state.cdn = false;+ const { rerender } = render(<WallpaperVideo wallpaperId="cindy-window" motion="dynamic" />);+ const video = document.querySelector('video')!;+ fireEvent.playing(video);+ state.reduced = true;+ rerender(<WallpaperVideo wallpaperId="cindy-window" motion="dynamic" />);+ expect(document.querySelector('video')).toBeNull();+ expect(video.getAttribute('src')).toBeNull();+ });it('keeps the still fallback when decode or playback fails', async () => {state.cdn = false;vi.mocked(HTMLMediaElement.prototype.play).mockRejectedValueOnce(new Error('decode failed'));diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.cssindex 5adb2ca28f..7992e62405 100644--- a/apps/desktop/src/renderer/styles/globals.css+++ b/apps/desktop/src/renderer/styles/globals.css@@ -2318,6 +2318,7 @@ html[data-wallpaper-active='true'] .wallpaper-composer-fade {inset: 0;z-index: -1;pointer-events: none;+ transition: opacity var(--motion-base) var(--motion-ease-move);}.app-wallpaper-video video {width: 100%;diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.mdindex cafd547099..cb18541d4f 100644--- a/docs/design-rules/DESIGN.md+++ b/docs/design-rules/DESIGN.md@@ -111,7 +111,11 @@ those entries can use a bundled fallback while downloading verified HD bytes intthe managed media store. Official scenes never request CDN resources.Decode one local videoper window, suspend playback while hidden/minimized, and use the original still for-reduced motion or playback failure. Switching back to Static releases the video.+reduced motion or playback failure. Static / Dynamic switches crossfade the video+over the retained high-resolution still using base/ease-move (200ms), starting+only after playback is ready. Switching back to Static releases the video after+the fade; rapid toggles reverse it without adding a decoder. Reduced motion+bypasses the transition and releases the video immediately.For moving scenes, fade the message layer above the composer instead of painting astatic duplicate of the wallpaper over it. Check the loop seam and actual Light/Darkchat readability, including collapsed sidebars and resized windows.