Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
perf(desktop): shorten returning startup splash
ficowang3142f7aa6f7b
diff --git a/apps/desktop/src/renderer/components/splash/SplashScreen.tsx b/apps/desktop/src/renderer/components/splash/SplashScreen.tsxindex e685a496e6..71b59f30f7 100644--- a/apps/desktop/src/renderer/components/splash/SplashScreen.tsx+++ b/apps/desktop/src/renderer/components/splash/SplashScreen.tsx@@ -51,9 +51,9 @@ import {* manifest_failed/download_failed = 各自重试动作(checkEnvironment);* spawn_failed 的 CTA =「前往下载」打开现网下载页(onSpawnFailedDownload),禁 retry。*- * 不透明白底全盖 + 最短停留 3s 地板(+热更重启守地板)机制不变:前者由+ * 不透明白底全盖 + 首启/热更 3s、已有会话返回启动 2s 的最短停留机制:前者由* LoginBrandStage 背景子层承载(var(--surface) token),后者仍在 useSplash- * (MIN_DISPLAY_MS,fake-timer 用例保留)。+ * (fake-timer 用例覆盖)。加载安全门不变;返回启动淡出复用标准 motion-enter。** dev-only 状态遍历:VITE_SPLASH_PHASE_FIXTURE(readSplashPhaseFixture,DEV 短路)* 只覆盖**显示** phase,生命周期(fade/卸载/data-splash-active)仍跟真实 phase。@@ -175,6 +175,7 @@ export function SplashScreen() {: realPhase;const {+ isReturningSession,isDownloading: realIsDownloading,downloadProgress,downloadInfo,@@ -353,7 +354,9 @@ export function SplashScreen() {{// 根透明:不透明白底全盖由 LoginBrandStage 背景子层(var(--surface))承载,// 品牌五要素从下层透出——本层只叠状态面板与窗口 chrome。- transition: 'opacity var(--splash-fade-duration) var(--splash-fade-easing)',+ transition: `opacity ${+ isReturningSession ? 'var(--motion-enter)' : 'var(--splash-fade-duration)'+ } var(--splash-fade-easing)`,WebkitAppRegion: 'drag',} as React.CSSProperties}diff --git a/apps/desktop/src/renderer/components/splash/__tests__/SplashScreen.test.tsx b/apps/desktop/src/renderer/components/splash/__tests__/SplashScreen.test.tsxindex 3f42c3cdce..0ad9a182e7 100644--- a/apps/desktop/src/renderer/components/splash/__tests__/SplashScreen.test.tsx+++ b/apps/desktop/src/renderer/components/splash/__tests__/SplashScreen.test.tsx@@ -20,6 +20,7 @@ import type { DbSlimmingStartupProgress } from '../../../../shared/localDbMainteconst mocks = vi.hoisted(() => ({splash: {phase: 'splash_checking' as string,+ isReturningSession: false,isDownloading: false,downloadProgress: 0,downloadInfo: { progress: 0 } as {@@ -176,6 +177,7 @@ beforeEach(() => {mocks.splash.downloadProgress = 0;mocks.splash.downloadInfo = { progress: 0 };mocks.splash.resetSignal = 0;+ mocks.splash.isReturningSession = false;mocks.coverHeld = false;setPhase('splash_checking');document.documentElement.removeAttribute('data-splash-active');@@ -414,6 +416,14 @@ describe('SplashScreen wave4 统一面板', () => {expect(root.className).toContain('opacity-100');});+ it('已有会话返回启动用标准较短过渡,首启仍保留 splash 淡出时长', () => {+ mocks.splash.isReturningSession = true;+ const { container } = renderSplash('splash_checking');+ expect((container.firstElementChild as HTMLElement).style.transition).toContain(+ 'var(--motion-enter)',+ );+ });+it('marks the document as splash-active only before fade out', () => {const view = renderSplash('splash_checking');expect(document.documentElement.getAttribute('data-splash-active')).toBe('1');diff --git a/apps/desktop/src/renderer/hooks/__tests__/useSplashPhases.test.tsx b/apps/desktop/src/renderer/hooks/__tests__/useSplashPhases.test.tsxindex b75c6d11ac..e8261d36ef 100644--- a/apps/desktop/src/renderer/hooks/__tests__/useSplashPhases.test.tsx+++ b/apps/desktop/src/renderer/hooks/__tests__/useSplashPhases.test.tsx@@ -19,6 +19,7 @@ const mocks = vi.hoisted(() => ({authInitializing: false,coverHeld: false,updateErrorCode: undefined as string | undefined,+ hasPersistedSession: false,}));vi.mock('react-i18next', () => ({@@ -61,13 +62,20 @@ describe('useSplash phase 表', () => {mocks.authInitializing = false;mocks.coverHeld = false;mocks.updateErrorCode = undefined;+ mocks.hasPersistedSession = false;mocks.checkEnvironment.mockClear();(window as unknown as {- electronAPI: { clientEndpoints: { websiteUrl: string } };+ electronAPI: {+ clientEndpoints: { websiteUrl: string };+ authHasPersistedSessionHintSync: () => boolean;+ };open: typeof window.open;}- ).electronAPI = { clientEndpoints: { websiteUrl: 'https://cindy.example/download' } };+ ).electronAPI = {+ clientEndpoints: { websiteUrl: 'https://cindy.example/download' },+ authHasPersistedSessionHintSync: () => mocks.hasPersistedSession,+ };window.matchMedia = vi.fn().mockReturnValue({matches: false,addEventListener: () => {},@@ -133,6 +141,32 @@ describe('useSplash phase 表', () => {expect(result.current.phase).toBe('splash_done');});+ it('已有持久会话的返回启动使用 2s 地板,仍等待真实就绪条件', () => {+ mocks.envStatus = 'passed';+ mocks.hasPersistedSession = true;+ const { result } = renderHook(() => useSplash());++ act(() => {+ vi.advanceTimersByTime(1_999);+ });+ expect(result.current.phase).toBe('splash_passed');++ act(() => {+ vi.advanceTimersByTime(1);+ });+ expect(result.current.phase).toBe('fading_out');+ expect(result.current.isReturningSession).toBe(true);++ act(() => {+ vi.advanceTimersByTime(349);+ });+ expect(result.current.phase).toBe('fading_out');+ act(() => {+ vi.advanceTimersByTime(1);+ });+ expect(result.current.phase).toBe('splash_done');+ });+it('auth 初始化未完成时 passed 不淡出(推进锚含 authInitializing)', () => {mocks.envStatus = 'passed';mocks.authInitializing = true;diff --git a/apps/desktop/src/renderer/hooks/useSplash.ts b/apps/desktop/src/renderer/hooks/useSplash.tsindex 37e95bd0a3..99aa7bd06c 100644--- a/apps/desktop/src/renderer/hooks/useSplash.ts+++ b/apps/desktop/src/renderer/hooks/useSplash.ts@@ -69,23 +69,34 @@ export function readSplashPhaseFixture(): SplashPhaseFixtureValue | null {if (!env.DEV) return null;const raw =- typeof env.VITE_SPLASH_PHASE_FIXTURE === 'string'- ? env.VITE_SPLASH_PHASE_FIXTURE.trim()- : '';+ typeof env.VITE_SPLASH_PHASE_FIXTURE === 'string' ? env.VITE_SPLASH_PHASE_FIXTURE.trim() : '';if (!raw) return null;return (SPLASH_PHASE_FIXTURE_VALUES as readonly string[]).includes(raw)? (raw as SplashPhaseFixtureValue): null;}-// 2026-07-19 用户拍板:1500 → 3000,splash 立绘一闪而过看不清,最短停留延长到 3s-// (淡出仍需"加载完成 && 满足地板时长"双条件,慢加载时不叠加额外等待)。-const MIN_DISPLAY_MS = 3000;+// 2026-07-19 用户拍板:1500 → 3000,splash 立绘一闪而过看不清,首次打开与+// 热更重启仍保留 3s。已有持久会话的返回启动用 2s:品牌展示仍可见,+// 但不再在 env/auth/LocalDb 全部就绪后因纯展示地板多等 1s。慢加载仍由+// "加载完成 && 满足地板时长"双条件保护,不会提前放行。+const FIRST_LAUNCH_MIN_DISPLAY_MS = 3000;+const RETURNING_SESSION_MIN_DISPLAY_MS = 2000;const FADE_FALLBACK_MS = 500;+const RETURNING_SESSION_FADE_FALLBACK_MS = 350;// splash_update_done 阶段先让 "更新完成,等待自动重启..." 这段提示文案显示 1.5s,// 再自动触发 relaunch,避免下载条刚到 100% 用户还没看清就直接整个窗口黑掉。const AUTO_RELAUNCH_DELAY_MS = 1_500;+function resolveReturningSession(): boolean {+ try {+ return window.electronAPI?.authHasPersistedSessionHintSync?.() === true;+ } catch {+ // 只读提示不可用时按首启保守处理,不因优化缩短未知启动。+ return false;+ }+}+export function useSplash() {const { t } = useTranslation();const {@@ -104,20 +115,24 @@ export function useSplash() {const [phase, setPhase] = useState<SplashPhase>('init');const [minTimeElapsed, setMinTimeElapsed] = useState(false);+ const [isReturningSession] = useState(resolveReturningSession);+ const minDisplayMs = isReturningSession+ ? RETURNING_SESSION_MIN_DISPLAY_MS+ : FIRST_LAUNCH_MIN_DISPLAY_MS;const fallbackTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);const minTimeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);// ── Effect 1: minimum display timer ──useEffect(() => {- minTimeTimerRef.current = setTimeout(() => setMinTimeElapsed(true), MIN_DISPLAY_MS);+ minTimeTimerRef.current = setTimeout(() => setMinTimeElapsed(true), minDisplayMs);return () => {if (minTimeTimerRef.current !== null) {clearTimeout(minTimeTimerRef.current);minTimeTimerRef.current = null;}};- }, []);+ }, [minDisplayMs]);// ── Effect 2: envStatus drives phase ──useEffect(() => {@@ -173,7 +188,11 @@ export function useSplash() {if (phase !== 'fading_out') return;const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;- const delay = reducedMotion ? 10 : FADE_FALLBACK_MS;+ const delay = reducedMotion+ ? 10+ : isReturningSession+ ? RETURNING_SESSION_FADE_FALLBACK_MS+ : FADE_FALLBACK_MS;fallbackTimerRef.current = setTimeout(() => {setPhase('splash_done');@@ -185,7 +204,7 @@ export function useSplash() {fallbackTimerRef.current = null;}};- }, [phase]);+ }, [phase, isReturningSession]);// ── Tips derivation ──const tips: TipsInfo = useMemo<TipsInfo>(() => {@@ -259,8 +278,8 @@ export function useSplash() {// 自动触发 relaunch。用 ref 保证同一会话只触发一次;若期间 spawn 失败,Effect 2b// 会把 phase 切到 splash_spawn_failed,这里依然只是已经发过一次 IPC,由 spawn 失败// dialog 接管。- // 重启时机同时守两条契约(2026-07-19 review 收口):挂载累计 ≥ MIN_DISPLAY_MS- // (3s 地板对所有启动路径生效,热更路径不许提前销毁 renderer) 且 更新完成提示+ // 重启时机同时守两条契约(2026-07-19 review 收口):挂载累计 ≥ 3s+ // (热更路径仍守 3s,不许提前销毁 renderer) 且 更新完成提示// 至少展示 AUTO_RELAUNCH_DELAY_MS——取两者剩余量的较大者作为延时。const mountedAtRef = useRef(Date.now());const autoRelaunchFiredRef = useRef(false);@@ -271,7 +290,10 @@ export function useSplash() {}if (autoRelaunchFiredRef.current) return;- const minDisplayRemaining = Math.max(0, MIN_DISPLAY_MS - (Date.now() - mountedAtRef.current));+ const minDisplayRemaining = Math.max(+ 0,+ FIRST_LAUNCH_MIN_DISPLAY_MS - (Date.now() - mountedAtRef.current),+ );const relaunchDelay = Math.max(AUTO_RELAUNCH_DELAY_MS, minDisplayRemaining);const timer = setTimeout(() => {autoRelaunchFiredRef.current = true;@@ -332,6 +354,7 @@ export function useSplash() {return {phase,+ isReturningSession,isDownloading,downloadProgress,downloadInfo,diff --git a/docs/design-rules/design-inventory.md b/docs/design-rules/design-inventory.mdindex 857a86c945..d3d93946d0 100644--- a/docs/design-rules/design-inventory.md+++ b/docs/design-rules/design-inventory.md@@ -34,7 +34,7 @@| `desktop.overlay.interaction-portal` | desktop | 交互提问卡片 | components/interaction-portal(AskUser / 权限类卡片出口) | InteractionPromptCardShell, InteractionPromptHost | apps/desktop/src/renderer/components/interaction-portal/InteractionPromptCardShell.tsx, apps/desktop/src/renderer/components/interaction-portal/InteractionPromptHost.tsx, apps/desktop/src/renderer/components/interaction-portal/InteractionPromptSlot.tsx, apps/desktop/src/renderer/components/interaction-portal/index.ts, apps/desktop/src/renderer/components/interaction-portal/store.ts | 10 | 0 | 4 || `desktop.overlay.permission-prompt` | desktop | 权限询问 | PermissionPrompt(会话内权限卡;DS-9 迁移前置) | AskUserQuestionPrompt, PermissionPrompt, PermissionSelector | apps/desktop/src/renderer/components/new-chat/AskUserQuestionPrompt.tsx, apps/desktop/src/renderer/components/new-chat/PermissionPrompt.tsx, apps/desktop/src/renderer/components/new-chat/PermissionSelector.tsx | 52 | 2 | 22 || `desktop.overlay.route-error` | desktop | 路由错误页 | router errorElement → RouteErrorFallback / TopLevelErrorBoundary | AppCrashScreen, RouteErrorFallback, TopLevelErrorBoundary | apps/desktop/src/renderer/components/error/AppCrashScreen.tsx, apps/desktop/src/renderer/components/error/LocalDbFatalScreen.tsx, apps/desktop/src/renderer/components/error/RouteErrorFallback.tsx, apps/desktop/src/renderer/components/error/TopLevelErrorBoundary.tsx, apps/desktop/src/renderer/components/error/localDbFatalView.ts | 6 | 0 | 1 |-| `desktop.overlay.splash` | desktop | 启动遮罩 | App → SplashScreen;同源 gating 下并挂 LoginBrandStage(z-9980 品牌画布,启动期即可见、Splash(z-9999) 之下) | LoginBrandStage, SplashScreen | apps/desktop/src/renderer/components/login/LoginBrandStage.tsx, apps/desktop/src/renderer/components/splash/SplashScreen.tsx | 3 | 0 | 5 |+| `desktop.overlay.splash` | desktop | 启动遮罩 | App → SplashScreen;同源 gating 下并挂 LoginBrandStage(z-9980 品牌画布,启动期即可见、Splash(z-9999) 之下) | LoginBrandStage, SplashScreen | apps/desktop/src/renderer/components/login/LoginBrandStage.tsx, apps/desktop/src/renderer/components/splash/SplashScreen.tsx | 4 | 0 | 5 || `desktop.overlay.toast` | desktop | Toast | App 常驻 ToastContainer(用户可见出口,不展开业务逻辑) | Toast, ToastContainer | apps/desktop/src/renderer/components/ui/toast/DownloadToast.tsx, apps/desktop/src/renderer/components/ui/toast/Toast.tsx, apps/desktop/src/renderer/components/ui/toast/ToastContainer.tsx, apps/desktop/src/renderer/components/ui/toast/index.ts | 7 | 4 | 3 || `desktop.plugins.app-main` | desktop | 插件主视图 | hash `/apps/:ghostId`(GhostMainViewFeatureLayout) | GhostMainViewFeatureLayout, GhostMainViewHost | apps/desktop/src/renderer/features/plugin/GhostMainViewFeatureLayout.tsx, apps/desktop/src/renderer/features/plugin/GhostMainViewHost.tsx | 0 | 0 | 0 || `desktop.plugins.installed` | desktop | 已装插件 | hash `/plugins`(GhostPluginPage) | AddMarketplaceDialog, GhostPluginActions, GhostPluginDetailView, GhostPluginPage, MarketPluginDetailView, MyPublishesSection, PluginDevicePicker, PluginManagementLayout, PluginProjectMenu, RemotePluginConfiguration, RemotePluginPage, RemotePluginReadOnlyDetail, UpdateAllDialog | apps/desktop/src/renderer/features/plugin/AddMarketplaceDialog.tsx, apps/desktop/src/renderer/features/plugin/GhostPluginActions.tsx, apps/desktop/src/renderer/features/plugin/GhostPluginDetailView.tsx, apps/desktop/src/renderer/features/plugin/GhostPluginPage.tsx, apps/desktop/src/renderer/features/plugin/MarketPluginDetailView.tsx, apps/desktop/src/renderer/features/plugin/MyPublishesSection.tsx, apps/desktop/src/renderer/features/plugin/PluginDevicePicker.tsx, apps/desktop/src/renderer/features/plugin/PluginManagementLayout.tsx, apps/desktop/src/renderer/features/plugin/PluginScopePicker.tsx, apps/desktop/src/renderer/features/plugin/RemotePluginConfiguration.tsx, apps/desktop/src/renderer/features/plugin/RemotePluginPage.tsx, apps/desktop/src/renderer/features/plugin/RemotePluginReadOnlyDetail.tsx, apps/desktop/src/renderer/features/plugin/UpdateAllDialog.tsx, apps/desktop/src/renderer/features/plugin/plugin-motion.css | 28 | 0 | 48 |