Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): bundle official HD wallpaper videos for offline playback
DavidShen4c934b3f7198
diff --git a/apps/desktop/src/main/__tests__/wallpaperVideo.test.ts b/apps/desktop/src/main/__tests__/wallpaperVideo.test.tsindex d406b5a7df..0c4d8824d5 100644--- a/apps/desktop/src/main/__tests__/wallpaperVideo.test.ts+++ b/apps/desktop/src/main/__tests__/wallpaperVideo.test.ts@@ -7,7 +7,8 @@ const m = vi.hoisted(() => ({fetch: vi.fn(), release: vi.fn(), assert: vi.fn(),}));vi.mock('../../shared/wallpaper-video-manifest.json', () => ({ default: {- 'cindy-window': { bytes: 3, sha256: 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' },+ 'cindy-window': { delivery: 'cdn', bytes: 3, sha256: 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' },+ 'cindy-studio': { delivery: 'bundled', bytes: 3, sha256: 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' },} }));vi.mock('../appSessionState.js', () => ({ activeOwnerScopeKey: () => m.owner, isAppSessionBoundaryPending: () => m.boundary }));vi.mock('../localDb/client/current.js', () => ({ getCurrentDbClientSnapshot: () => m.snapshot }));@@ -32,6 +33,11 @@ beforeEach(() => {});describe('optional CDN wallpaper video', () => {+ it('never accesses the cache or network for bundled official scenes', async () => {+ expect(await ensureWallpaperVideo('cindy-studio')).toBeNull();+ expect(m.cached).not.toHaveBeenCalled();+ expect(m.fetch).not.toHaveBeenCalled();+ });it('rejects arbitrary URLs, paths and prototype keys without network access', async () => {for (const id of ['https://example/a.mp4', '../secret', 'constructor', 'none', null])await expect(ensureWallpaperVideo(id)).rejects.toThrow('Unsupported');diff --git a/apps/desktop/src/main/wallpaper-video.ts b/apps/desktop/src/main/wallpaper-video.tsindex 989b919273..637047ad63 100644--- a/apps/desktop/src/main/wallpaper-video.ts+++ b/apps/desktop/src/main/wallpaper-video.ts@@ -63,6 +63,8 @@ async function download(asset: Asset, assertValid: () => void): Promise<Buffer>/** Optional enhancement: failure never prevents the bundled video from playing. */export async function ensureWallpaperVideo(id: unknown): Promise<string | null> {if (!isWallpaperVideoScene(id)) throwIpcError('INVALID_PARAMS', 'Unsupported wallpaper video');+ // Bundled official scenes must never contact OSS, even through a direct IPC call.+ if (manifest[id].delivery !== 'cdn') return null;const snapshot = getCurrentDbClientSnapshot();if (!snapshot || isAppSessionBoundaryPending()) return null;let state = states.get(snapshot);diff --git a/apps/desktop/src/renderer/assets/wallpapers/cindy-dream.mp4 b/apps/desktop/src/renderer/assets/wallpapers/cindy-dream.mp4index db026ca35b..f94719b013 100644Binary files a/apps/desktop/src/renderer/assets/wallpapers/cindy-dream.mp4 and b/apps/desktop/src/renderer/assets/wallpapers/cindy-dream.mp4 differdiff --git a/apps/desktop/src/renderer/assets/wallpapers/cindy-studio.mp4 b/apps/desktop/src/renderer/assets/wallpapers/cindy-studio.mp4index 541a582b46..cd63d69b78 100644Binary files a/apps/desktop/src/renderer/assets/wallpapers/cindy-studio.mp4 and b/apps/desktop/src/renderer/assets/wallpapers/cindy-studio.mp4 differdiff --git a/apps/desktop/src/renderer/assets/wallpapers/cindy-window.mp4 b/apps/desktop/src/renderer/assets/wallpapers/cindy-window.mp4index 29b2d0b269..1d62dbb5aa 100644Binary files a/apps/desktop/src/renderer/assets/wallpapers/cindy-window.mp4 and b/apps/desktop/src/renderer/assets/wallpapers/cindy-window.mp4 differdiff --git a/apps/desktop/src/renderer/components/layout/WallpaperVideo.tsx b/apps/desktop/src/renderer/components/layout/WallpaperVideo.tsxindex 0dfec854a6..69f0819cec 100644--- a/apps/desktop/src/renderer/components/layout/WallpaperVideo.tsx+++ b/apps/desktop/src/renderer/components/layout/WallpaperVideo.tsx@@ -4,7 +4,7 @@ import type { WallpaperId, WallpaperMotion } from '@/../shared/appearanceSettingimport { useReducedMotion } from '@/hooks/useReducedMotion';import { useWallpaperVideoTier } from '@/hooks/useWallpaperVideoTier';import { HIDDEN_ANIMATION_ATTR } from '@/lib/hiddenAnimationGate';-import { getWallpaperVideo } from '@/lib/wallpaper';+import { getWallpaperVideo, usesCdnWallpaperVideo } from '@/lib/wallpaper';/** One decoder and one viewport canvas. Static mode does not fetch any video. */export function WallpaperVideo({@@ -15,9 +15,11 @@ export function WallpaperVideo({motion: WallpaperMotion;}) {const reducedMotion = useReducedMotion();- return motion === 'dynamic' && !reducedMotion && getWallpaperVideo(wallpaperId)+ const src = getWallpaperVideo(wallpaperId);+ if (motion !== 'dynamic' || reducedMotion || !src) return null;+ return usesCdnWallpaperVideo(wallpaperId)? <AdaptiveWallpaper key={wallpaperId} wallpaperId={wallpaperId} />- : null;+ : <PlayingWallpaper key={src} src={src} />;}function AdaptiveWallpaper({ wallpaperId }: { wallpaperId: WallpaperId }) {diff --git a/apps/desktop/src/renderer/components/layout/__tests__/WallpaperVideo.test.tsx b/apps/desktop/src/renderer/components/layout/__tests__/WallpaperVideo.test.tsxindex d1c0bc122a..e12d5bf0a7 100644--- a/apps/desktop/src/renderer/components/layout/__tests__/WallpaperVideo.test.tsx+++ b/apps/desktop/src/renderer/components/layout/__tests__/WallpaperVideo.test.tsx@@ -5,11 +5,12 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { WallpaperVideo } from '../WallpaperVideo';import { HIDDEN_ANIMATION_ATTR } from '@/lib/hiddenAnimationGate';-const state = vi.hoisted(() => ({ reduced: false, tier: 'standard' }));+const state = vi.hoisted(() => ({ reduced: false, tier: 'standard', cdn: true }));const ensureVideo = vi.fn();vi.mock('@/hooks/useReducedMotion', () => ({ useReducedMotion: () => state.reduced }));vi.mock('@/hooks/useWallpaperVideoTier', () => ({ useWallpaperVideoTier: () => state.tier }));vi.mock('@/lib/wallpaper', () => ({+ usesCdnWallpaperVideo: () => state.cdn,getWallpaperVideo: (id: string, tier = 'standard') =>(id.startsWith('cindy-') ? `/${id}${tier === 'hd' ? '-hd' : ''}.mp4` : undefined),}));@@ -18,6 +19,7 @@ describe('dynamic wallpaper lifecycle', () => {beforeEach(() => {state.reduced = false;state.tier = 'standard';+ state.cdn = true;ensureVideo.mockReset().mockResolvedValue('/cindy-window-hd.mp4');vi.stubGlobal('electronAPI', { appearanceSettings: { ensureWallpaperVideo: ensureVideo } });vi.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue();@@ -31,6 +33,7 @@ describe('dynamic wallpaper lifecycle', () => {vi.unstubAllGlobals();});it('does not create a decoder for static, reduced motion or unsupported artwork', () => {+ state.cdn = false;const { rerender } = render(<WallpaperVideo wallpaperId="cindy-window" motion="static" />);expect(document.querySelector('video')).toBeNull();rerender(<WallpaperVideo wallpaperId="none" motion="dynamic" />);@@ -41,6 +44,7 @@ describe('dynamic wallpaper lifecycle', () => {expect(ensureVideo).not.toHaveBeenCalled();});it('shows only decoded frames, pauses with the shared hidden gate, and releases on static', async () => {+ state.cdn = false;const { rerender } = render(<WallpaperVideo wallpaperId="cindy-window" motion="dynamic" />);const video = document.querySelector('video')!;expect(video.muted && video.loop).toBe(true);@@ -58,12 +62,14 @@ describe('dynamic wallpaper lifecycle', () => {expect(document.documentElement.dataset.wallpaperMotion).toBeUndefined();});it('keeps the still fallback when decode or playback fails', async () => {+ state.cdn = false;vi.mocked(HTMLMediaElement.prototype.play).mockRejectedValueOnce(new Error('decode failed'));render(<WallpaperVideo wallpaperId="cindy-window" motion="dynamic" />);await waitFor(() => expect(document.querySelector('video')).toBeNull());expect(document.documentElement.dataset.wallpaperMotion).toBeUndefined();});it('switches scenes without retaining a second decoder', () => {+ state.cdn = false;const { rerender } = render(<WallpaperVideo wallpaperId="cindy-window" motion="dynamic" />);const old = document.querySelector('video')!;fireEvent.playing(old);@@ -91,6 +97,16 @@ describe('dynamic wallpaper lifecycle', () => {expect(hd.getAttribute('src')).toBeNull();expect(document.querySelector('video')!.src).not.toContain('-hd');});+ it.each(['cindy-window', 'cindy-studio', 'cindy-dream'] as const)('plays bundled %s without requesting CDN or reloading on resize', async id => {+ state.cdn = false;+ const { rerender } = render(<WallpaperVideo wallpaperId={id} motion="dynamic" />);+ const original = document.querySelector('video');+ state.tier = 'hd';+ rerender(<WallpaperVideo wallpaperId={id} motion="dynamic" />);+ await act(async () => {});+ expect(document.querySelector('video')).toBe(original);+ expect(ensureVideo).not.toHaveBeenCalled();+ });it.each(['error', 'rejection'])('falls back from HD once on %s, then to a still if standard fails', async (failure) => {state.tier = 'hd';ensureVideo.mockImplementation(async () => {diff --git a/apps/desktop/src/renderer/lib/wallpaper.ts b/apps/desktop/src/renderer/lib/wallpaper.tsindex a60a46c05a..ef30b21428 100644--- a/apps/desktop/src/renderer/lib/wallpaper.ts+++ b/apps/desktop/src/renderer/lib/wallpaper.ts@@ -1,4 +1,5 @@import type { WallpaperId } from '@/../shared/appearanceSettings';+import videoManifest from '@/../shared/wallpaper-video-manifest.json';import cindyWindow from '@/assets/wallpapers/cindy-window.webp';import cindyStudio from '@/assets/wallpapers/cindy-studio.webp';import cindyDream from '@/assets/wallpapers/cindy-dream.webp';@@ -16,6 +17,12 @@ export function getWallpaperVideo(id: WallpaperId): string | undefined {return SCENE_VIDEOS[id];}+/** Official scenes are fully offline; CDN delivery is opt-in for future catalog entries. */+export function usesCdnWallpaperVideo(id: WallpaperId): boolean {+ return Object.hasOwn(videoManifest, id) &&+ videoManifest[id as keyof typeof videoManifest].delivery === 'cdn';+}+export function isSceneWallpaper(id: WallpaperId): boolean {return id === 'cindy-window' || id === 'cindy-studio' || id === 'cindy-dream';}diff --git a/apps/desktop/src/shared/wallpaper-video-manifest.json b/apps/desktop/src/shared/wallpaper-video-manifest.jsonindex cbda220bc3..20aa927ed3 100644--- a/apps/desktop/src/shared/wallpaper-video-manifest.json+++ b/apps/desktop/src/shared/wallpaper-video-manifest.json@@ -1,5 +1,6 @@{"cindy-window": {+ "delivery": "bundled","sha256": "76844014468e15fe766bf4dd7033eda1e057cf57138e1de1970fcbad2c758701","bytes": 1816940,"width": 2304,@@ -8,6 +9,7 @@"duration": 6},"cindy-studio": {+ "delivery": "bundled","sha256": "12e828824bf0362e6f8a16c49d8e8f3b45165d47a5e3aa1d295cbb232b86799e","bytes": 2661916,"width": 2304,@@ -16,6 +18,7 @@"duration": 6},"cindy-dream": {+ "delivery": "bundled","sha256": "c3e7fea58c8e3feaf06421e95a2f5326c8609813e321c064f70362e491257a39","bytes": 2383299,"width": 2304,@@ -23,4 +26,4 @@"fps": 24,"duration": 6}-}\ No newline at end of file+}diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.mdindex d874f79155..cafd547099 100644--- a/docs/design-rules/DESIGN.md+++ b/docs/design-rules/DESIGN.md@@ -104,11 +104,11 @@ contrast. Validate real long messages, not only empty chat views.The three approved scenes also offer an explicit Static / Dynamic choice (2026-10-01).Static remains the default. Dynamic uses a silent, subtly moving loop with a fixedcamera, preserving the same composition and full-window crop. Built-in static artwork-uses 3584×2240 WebP. Keep the standard videos bundled; request the reviewed 2304×1440-version from the configured CDN only when cover-fit demand exceeds 1920 physical-pixels (window size × DPR), returning to standard below 1680 to avoid resize churn.-Play standard immediately while downloading or if the CDN is missing/offline; cache-verified HD bytes in the managed media store. HD playback failure falls back to standard.+uses 3584×2240 WebP. All three official 2304×1440 videos are bundled, fully offline,+with no duplicate low-resolution assets or resolution switching on window resize.+The CDN mechanism remains opt-in for future catalog entries marked as CDN-delivered;+those entries can use a bundled fallback while downloading verified HD bytes into+the managed media store. Official scenes never request CDN resources.Decode one local videoper window, suspend playback while hidden/minimized, and use the original still forreduced motion or playback failure. Switching back to Static releases the video.diff --git a/docs/dev-rules/media-storage-and-protocols.md b/docs/dev-rules/media-storage-and-protocols.mdindex d6613da65e..6990de1206 100644--- a/docs/dev-rules/media-storage-and-protocols.md+++ b/docs/dev-rules/media-storage-and-protocols.md@@ -45,12 +45,14 @@不可再生用户内容,必须沿用现有 pin/引用流程转为不可按缓存回收。- 零引用入仓只适用于已有草稿或生成结果提交链路。新增零引用窗口时,必须证明内容在消息落库前不会被回收,并用测试覆盖成功、失败、取消和重试。-- 内置高清壁纸视频用 `integration-cache` 引用登记可再生 CDN 缓存,按主机内置清单- 核验字节数与 SHA-256 后入仓;缓存缺失、被回收或下载失败都回退随包标准视频。- 静态高清 WebP 随包,高清 MP4 不进入安装包。发布命令为+- 三款官方壁纸的高清 WebP 与 2304×1440 MP4 均随包,清单标记 `delivery: bundled`,+ 不访问 OSS/CDN,不重复打包低清视频。未来显式标记 `delivery: cdn` 的条目才启用+ `integration-cache` 引用与 CDN 下载,按清单字节数与 SHA-256 校验后入仓;失败回退随包视频。+ 发布脚本只上传 CDN 条目,始终跳过 bundled 条目。发布命令为`node --env-file=<发布配置> scripts/publish-wallpaper-videos.mjs --directory=<视频目录> --region=global`;中国大陆版显式用 `--region=cn`,发布两区时分别执行。可加 `--verify-only` 离线核验。- 视频文件名为 `<壁纸编号>-hd.mp4`,清单见 Desktop 的 `src/shared/wallpaper-video-manifest.json`。+ CDN 文件名为 `<壁纸编号>-hd.mp4`;`--verify-only` 同时校验仓内内置视频。+ 清单见 Desktop 的 `src/shared/wallpaper-video-manifest.json`。- 可再生 HTML 临时快照缓存是独立副本的例外:仅在快照已物化自己的文件、HTTP 服务不依赖媒体仓 blob、且该缓存不作为持久附件提交时,使用 `isCache: true` 和空引用入仓。必须验证媒体仓缓存不可用时快照仍可读取,以及重复打开、失败、取消和重试不新增业务引用;diff --git a/scripts/publish-wallpaper-videos.mjs b/scripts/publish-wallpaper-videos.mjsindex e1441ffadb..6625935e10 100644--- a/scripts/publish-wallpaper-videos.mjs+++ b/scripts/publish-wallpaper-videos.mjs@@ -1,30 +1,35 @@#!/usr/bin/env node-// Videos stay outside the application bundle. Publish exact reviewed bytes only.+// Verify bundled assets; only opt-in CDN entries are published as reviewed bytes.import fs from 'node:fs/promises';import path from 'node:path';import { createHash } from 'node:crypto';+import { fileURLToPath } from 'node:url';import { createOSSClient, resolveOssConfig, uploadToOSS } from './shared/oss.mjs';const args = process.argv.slice(2);const region = args.find(arg => arg.startsWith('--region='))?.slice(9) ?? 'global';const directory = args.find(arg => arg.startsWith('--directory='))?.slice(12);const verifyOnly = args.includes('--verify-only');-if (!directory || !['global', 'cn'].includes(region)) {+if (!['global', 'cn'].includes(region)) {throw new Error('Usage: node [--env-file=...] scripts/publish-wallpaper-videos.mjs --directory=<videos> --region=global|cn [--verify-only]');}const manifest = JSON.parse(await fs.readFile(new URL('../apps/desktop/src/shared/wallpaper-video-manifest.json', import.meta.url), 'utf8'));const assets = [];for (const [id, asset] of Object.entries(manifest)) {- const file = path.resolve(directory, id + '-hd.mp4');+ if (!['bundled', 'cdn'].includes(asset.delivery)) throw new Error('Unknown wallpaper delivery: ' + id);+ if (asset.delivery === 'cdn' && !directory) throw new Error('CDN entries require --directory=<videos>');+ const file = asset.delivery === 'bundled'+ ? fileURLToPath(new URL('../apps/desktop/src/renderer/assets/wallpapers/' + id + '.mp4', import.meta.url))+ : path.resolve(directory, id + '-hd.mp4');const bytes = await fs.readFile(file);if (bytes.length !== asset.bytes || createHash('sha256').update(bytes).digest('hex') !== asset.sha256) {throw new Error('Video differs from reviewed manifest: ' + id);}- assets.push({ file, ...asset });+ if (asset.delivery === 'cdn') assets.push({ file, ...asset });console.log(id + ': ' + asset.width + 'x' + asset.height + ', ' + asset.bytes + ' bytes');}-console.log('Total: ' + assets.reduce((sum, asset) => sum + asset.bytes, 0) + ' bytes');-if (!verifyOnly) {+console.log('CDN upload total: ' + assets.reduce((sum, asset) => sum + asset.bytes, 0) + ' bytes');+if (!verifyOnly && assets.length > 0) {// Missing publication configuration must never redirect to another region.const config = resolveOssConfig(region);const client = createOSSClient(region);