Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(login): 迁移弹窗按新设计稿换肤——标准亮/暗底+统一卡片三态 (#239)
Lizi64175b9ae991
diff --git a/apps/desktop/src/renderer/components/auth/LegacyMigrationDialog.tsx b/apps/desktop/src/renderer/components/auth/LegacyMigrationDialog.tsxindex 6f6783ac39..1c1afb47d6 100644--- a/apps/desktop/src/renderer/components/auth/LegacyMigrationDialog.tsx+++ b/apps/desktop/src/renderer/components/auth/LegacyMigrationDialog.tsx@@ -1,29 +1,32 @@import { useEffect, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';-import chibiFailureUrl from '@/assets/login/chibi/[email protected]?url';import { Spinner } from '@/components/ui/spinner';type LegacyMigrationPhase = 'confirm' | 'running' | 'done' | 'failed' | null;/**- * LegacyMigrationDialog — 首登轻量数据迁移(mToc)的全局确认 / 进度弹窗。+ * LegacyMigrationDialog — 首登轻量数据迁移(mToc)的全局确认 / 进度界面。** main 在首次登录成功、db 打开前检测到老版本 userData 时,经* `legacy-migration:state` 推送阶段;本组件挂在 App 顶层(与 Toast 同层),- * 按阶段渲染(状态机与交互与皮肤化前完全一致,PR3 仅换视觉):- * - confirm:标题 + 说明 + 唯一的「确定」按钮(不可关闭 / 不可取消);- * - running:说明切「正在迁移…」,按钮进 loading(compositor-only Spinner,- * 禁用;ESC / 外点本就无监听,天然拦截);- * - failed:回调卡形式 + 失败表情包(design.md §7.4 条 2 唯一 App 内例外;- * demo legacyOverlay:680×680 卡 scale(0.72) 落进 490×490 盒),点「继续」- * 关闭(main 侧同步清态);- * - done:直接关闭,登录流程继续。+ * 按阶段渲染(状态机与 IPC 交互与皮肤化前完全一致,本轮仅换视觉):+ * - confirm:标题 + 说明 + 唯一的「继续」按钮(不可关闭 / 不可取消);+ * - running:说明保留不变,按钮进 loading(文案居中 + 右侧 compositor-only+ * Spinner,禁用;confirm/running 期间无任何关闭监听,天然拦截);+ * - failed:同一张卡换失败文案,无按钮(figma 567:819/567:776),点击页面+ * 任意处或按 Escape/Enter/Space 关闭(main 侧同步清态——设计稿删除按钮+ * 后必须保留等价的解除路径,否则迁移失败会把用户永久锁在此屏);+ * - done:直接关闭,登录流程继续(有意不做完成确认,遵循既有行为)。*- * 视觉参数权威:confirm/running = demo `.legacy-modal`(520px r12 面板);- * failed = callback-pages-classification.md 卡片共用参数(680×680 r36,立绘- * 280×280@200,60,标题 32/352,副文案 20/396,CTA 540×80@70,529)。颜色全部走- * `--login-callback-*` component token(colors.ts,规则 16),几何为设计稿+ * 视觉参数权威:figma CINDY 文件「迁移旧版本数据_white/_dark」六帧+ * (567:599/802/819 与 567:684/759/776):卡 680×500 r36、标题 32、正文 26/40+ * (左对齐 600 宽)、CTA 540×80 r40 文字 24、spinner 24 右置。App 内沿用+ * PR3 对 680 卡族的 0.72 落码系数 → 490×360 r26 / 23 / 19·29 / 389×58 r29·17。+ * 页面底不再用半透明遮罩压登录页,直接铺登录链路同族画布底+ * (`--login-bg-base`,亮 #EDEDED / 暗随 #525 token 二态接管;迁移设计帧+ * 567:684/759/776 画布即登录族);卡片颜色全部走+ * `--login-callback-*` component token(colors.ts 品牌豁免族),几何为设计稿* 冻结值走内联常量。仅 cn 构建触发(main 侧既有逻辑,本组件不感知区域)。** 挂载时经 get-state 补拉一次,兜住「main 先推送、组件后挂载」的时序。@@ -52,192 +55,150 @@ export function LegacyMigrationDialog() {const open = phase === 'confirm' || phase === 'running' || phase === 'failed';const failed = phase === 'failed';const running = phase === 'running';- // 唯一可聚焦元素;Tab/Shift+Tab 一律圈回按钮(最小 focus trap,对齐旧版- // Radix AlertDialog 的焦点圈——迁移期间禁止键盘走出弹窗触达底层 UI)。+ // confirm/running 期间唯一可聚焦元素;Tab/Shift+Tab 一律圈回按钮(最小+ // focus trap——迁移期间禁止键盘走出本屏触达底层 UI)。failed 无按钮,+ // 焦点圈到容器自身,点击任意处或 Escape/Enter/Space 关闭。const buttonRef = useRef<HTMLButtonElement | null>(null);+ const containerRef = useRef<HTMLDivElement | null>(null);++ useEffect(() => {+ if (failed || running) containerRef.current?.focus();+ }, [failed, running]);if (!open) return null;- const trapFocus = (event: React.KeyboardEvent) => {+ const dismissFailed = () => {+ if (!failed) return;+ setPhase(null);+ // 同一通道让 main 清掉 failed 态,避免重挂载后 get-state 再弹+ // (与旧版「继续」按钮完全相同的解除逻辑,仅触发方式换成点击任意处)。+ void window.electronAPI.legacyMigration.confirm();+ };++ const onKeyDown = (event: React.KeyboardEvent) => {if (event.key === 'Tab') {event.preventDefault();- buttonRef.current?.focus();+ ((!running && buttonRef.current) || containerRef.current)?.focus();+ return;+ }+ if (failed && (event.key === 'Escape' || event.key === 'Enter' || event.key === ' ')) {+ event.preventDefault();+ dismissFailed();}};const onConfirm = () => {- if (phase === 'confirm') {- // 乐观切 loading;main 收到确认后会紧接着推 running(幂等)。- setPhase('running');- void window.electronAPI.legacyMigration.confirm();- } else if (failed) {- setPhase(null);- // 同一通道让 main 清掉 failed 态,避免重挂载后 get-state 再弹。- void window.electronAPI.legacyMigration.confirm();- }+ if (phase !== 'confirm') return;+ // 乐观切 loading;main 收到确认后会紧接着推 running(幂等)。+ setPhase('running');+ void window.electronAPI.legacyMigration.confirm();};return (- // 状态完全由 main 推送 + 按钮点击驱动;confirm/running/failed 期间不允许- // ESC / 外点关闭(overlay 无任何关闭监听,与皮肤化前行为一致)。+ // 状态完全由 main 推送 + 用户交互驱动;confirm/running 期间不允许任何+ // 方式关闭(容器点击只在 failed 态生效)。<div+ ref={containerRef}role="dialog"aria-modal="true"+ aria-labelledby="legacy-migration-title"+ aria-describedby="legacy-migration-desc"+ tabIndex={-1}// z-[10000] = 本仓模态层约定(confirm-dialog 同层);低于 Toast(10100)。- className="fixed inset-0 z-[10000] flex items-center justify-center"- style={{ background: 'var(--overlay-modal)' }}- onKeyDown={trapFocus}+ className="fixed inset-0 z-[10000] flex items-center justify-center outline-none"+ style={{ background: 'var(--login-bg-base)' }}+ onKeyDown={onKeyDown}+ onClick={dismissFailed}>- {failed ? (- <div style={{ position: 'relative', width: 490, height: 490 }}>- <div- style={{- position: 'absolute',- left: 0,- top: 0,- width: 680,- height: 680,- transform: 'scale(0.72)',- transformOrigin: 'top left',- borderRadius: 36,- border: '1px solid var(--login-callback-card-border)',- background: 'var(--login-callback-card-bg)',- overflow: 'clip',- }}- >- <img- src={chibiFailureUrl}- alt=""- style={{- position: 'absolute',- left: 200,- top: 60,- width: 280,- height: 280,- objectFit: 'contain',- }}- />- <h2- style={{- position: 'absolute',- left: 42,- top: 352,- width: 598,- margin: 0,- fontSize: 32,- lineHeight: '38px',- fontWeight: 700,- color: 'var(--login-callback-title)',- textAlign: 'center',- whiteSpace: 'nowrap',- overflow: 'hidden',- textOverflow: 'ellipsis',- }}- >- {t('legacyMigration.failedTitle')}- </h2>- {/* demo:failed 副文案多行展开(white-space normal / height auto / lh 1.5) */}- <p- style={{- position: 'absolute',- left: 41,- top: 396,- width: 599,- margin: 0,- fontSize: 20,- lineHeight: 1.5,- color: 'var(--login-callback-body)',- textAlign: 'center',- }}- >- {t('legacyMigration.failedDescription')}- </p>- <button- ref={buttonRef}- type="button"- autoFocus- onClick={onConfirm}- style={{- position: 'absolute',- left: 70,- top: 529,- width: 540,- height: 80,- borderRadius: 40,- background: 'var(--login-callback-cta-bg)',- border: '1px solid var(--login-callback-cta-border)',- color: 'var(--login-callback-cta-text)',- fontSize: 24,- fontWeight: 700,- cursor: 'pointer',- }}- >- {t('legacyMigration.continue')}- </button>- </div>- </div>- ) : (- <div+ <div+ style={{+ display: 'flex',+ flexDirection: 'column',+ width: 490,+ maxWidth: 'calc(100% - 48px)',+ minHeight: 360,+ maxHeight: 'calc(100% - 48px)',+ overflowY: 'auto',+ borderRadius: 26,+ background: 'var(--login-callback-card-bg)',+ border: '1px solid var(--login-callback-card-border)',+ padding: '22px 29px 28px',+ }}+ >+ <h2+ id="legacy-migration-title"style={{- width: 520,- maxWidth: 'calc(100% - 48px)',- borderRadius: 12,- background: 'var(--login-callback-card-bg)',- border: '1px solid var(--login-callback-card-border)',- boxShadow: 'var(--confirm-shadow)',- padding: 28,+ margin: 0,+ fontSize: 23,+ lineHeight: 1.25,+ fontWeight: 700,+ color: 'var(--login-callback-title)',+ textAlign: 'center',}}>- <h2- style={{- margin: '0 0 12px',- fontSize: 22,- lineHeight: 1.25,- fontWeight: 600,- color: 'var(--login-callback-title)',- }}- >- {t('legacyMigration.title')}- </h2>- <p- style={{- margin: '0 0 22px',- fontSize: 14,- lineHeight: 1.6,- color: 'var(--login-callback-body)',- }}- >- {running ? t('legacyMigration.migrating') : t('legacyMigration.description')}- </p>+ {t(failed ? 'legacyMigration.failedTitle' : 'legacyMigration.title')}+ </h2>+ <p+ id="legacy-migration-desc"+ style={{+ margin: '22px 0 0',+ fontSize: 19,+ lineHeight: '29px',+ color: 'var(--login-callback-body)',+ }}+ >+ {t(failed ? 'legacyMigration.failedDescription' : 'legacyMigration.description')}+ </p>+ {/* 设计稿按钮钉在卡底(bottom 39/680 卡);文案更长的语言把卡撑高时保底 24px 间距 */}+ <div style={{ flexGrow: 1, minHeight: 24 }} />+ {!failed && (<buttonref={buttonRef}type="button"autoFocusdisabled={running}onClick={onConfirm}- className="flex w-full items-center justify-center gap-2"style={{- height: 48,- borderRadius: 24,+ position: 'relative',+ alignSelf: 'center',+ width: 389,+ maxWidth: '100%',+ minHeight: 58,+ // 设计稿 r40/h80 = 半高真 pill;用 9999 表达 pill 语义,长文案把+ // 按钮撑高时圆角跟随保持胶囊形(codex review P1)。+ borderRadius: 9999,background: 'var(--login-callback-cta-bg)',border: '1px solid var(--login-callback-cta-border)',color: 'var(--login-callback-cta-text)',- fontSize: 16,- fontWeight: 600,+ fontSize: 17,+ fontWeight: 700,+ padding: '0 46px',cursor: running ? 'default' : 'pointer',}}>{running ? (<>- <Spinner size={16} />{t('legacyMigration.migrating')}+ {/* spinner 右置(figma 567:802:24px,距右缘 29/680 卡);外层+ static wrapper 定位,旋转只发生在 Spinner 自身 wrapper 上 */}+ <span+ style={{+ position: 'absolute',+ right: 21,+ top: '50%',+ marginTop: -9,+ display: 'inline-flex',+ }}+ >+ <Spinner size={17} />+ </span></>) : (t('legacyMigration.confirm'))}</button>- </div>- )}+ )}+ </div></div>);}diff --git a/apps/desktop/src/renderer/components/auth/__tests__/LegacyMigrationDialog.test.tsx b/apps/desktop/src/renderer/components/auth/__tests__/LegacyMigrationDialog.test.tsxindex 4f211d9a11..4b1092604c 100644--- a/apps/desktop/src/renderer/components/auth/__tests__/LegacyMigrationDialog.test.tsx+++ b/apps/desktop/src/renderer/components/auth/__tests__/LegacyMigrationDialog.test.tsx@@ -1,5 +1,5 @@// @vitest-environment jsdom-import { cleanup, render, screen } from '@testing-library/react';+import { cleanup, fireEvent, render, screen } from '@testing-library/react';import { afterEach, describe, expect, it, vi } from 'vitest';import { LegacyMigrationDialog } from '../LegacyMigrationDialog';@@ -42,7 +42,17 @@ describe('LegacyMigrationDialog states', () => {expect(api.onState).toHaveBeenCalled();});- it('legacy-running:运行态显示禁用 loading 按钮', async () => {+ it('legacy-confirm:点击容器不关闭(仅 failed 态可解除)', async () => {+ const api = installLegacyMigrationApi('confirm');+ render(<LegacyMigrationDialog />);++ const dialog = await screen.findByRole('dialog');+ fireEvent.click(dialog);+ expect(api.confirm).not.toHaveBeenCalled();+ expect(screen.getByRole('dialog')).toBeTruthy();+ });++ it('legacy-running:运行态说明保留,按钮进禁用 loading', async () => {installLegacyMigrationApi('running');render(<LegacyMigrationDialog />);@@ -51,19 +61,52 @@ describe('LegacyMigrationDialog states', () => {name: /legacyMigration.migrating/,});expect((button as HTMLButtonElement).disabled).toBe(true);- expect(screen.queryByText('legacyMigration.description')).toBeNull();+ // figma 567:802:running 期间说明文案保留不变,只有按钮切 loading。+ expect(screen.getByText('legacyMigration.description')).toBeTruthy();});- it('legacy-failed:失败态使用回调卡样式和继续按钮', async () => {- installLegacyMigrationApi('failed');+ it('legacy-failed:失败态无按钮,点击任意处关闭并清 main 态', async () => {+ const api = installLegacyMigrationApi('failed');render(<LegacyMigrationDialog />);- expect(await screen.findByRole('dialog')).toBeTruthy();- const button = await screen.findByRole('button', {- name: 'legacyMigration.continue',- });- expect((button as HTMLButtonElement).disabled).toBe(false);+ const dialog = await screen.findByRole('dialog');+ // figma 567:819/567:776:失败卡没有按钮。+ expect(screen.queryByRole('button')).toBeNull();expect(screen.getByText('legacyMigration.failedTitle')).toBeTruthy();expect(screen.getByText('legacyMigration.failedDescription')).toBeTruthy();++ fireEvent.click(dialog);+ expect(api.confirm).toHaveBeenCalledTimes(1);+ expect(screen.queryByRole('dialog')).toBeNull();+ });++ it('legacy-failed:Escape 关闭并清 main 态', async () => {+ const api = installLegacyMigrationApi('failed');+ render(<LegacyMigrationDialog />);++ const dialog = await screen.findByRole('dialog');+ fireEvent.keyDown(dialog, { key: 'Escape' });+ expect(api.confirm).toHaveBeenCalledTimes(1);+ expect(screen.queryByRole('dialog')).toBeNull();+ });++ it('legacy-failed:Enter 关闭并清 main 态', async () => {+ const api = installLegacyMigrationApi('failed');+ render(<LegacyMigrationDialog />);++ const dialog = await screen.findByRole('dialog');+ fireEvent.keyDown(dialog, { key: 'Enter' });+ expect(api.confirm).toHaveBeenCalledTimes(1);+ expect(screen.queryByRole('dialog')).toBeNull();+ });++ it('legacy-failed:Space 关闭并清 main 态', async () => {+ const api = installLegacyMigrationApi('failed');+ render(<LegacyMigrationDialog />);++ const dialog = await screen.findByRole('dialog');+ fireEvent.keyDown(dialog, { key: ' ' });+ expect(api.confirm).toHaveBeenCalledTimes(1);+ expect(screen.queryByRole('dialog')).toBeNull();});});diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 6fb4897219..73d5eb7171 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -2815,11 +2815,10 @@"legacyMigration": {"title": "Migrate data from the previous version","description": "Data from a previous version was found on this device. Your chat history and media files will be migrated to the new data location. If the old app is still running, please quit it completely first, and keep {{appName}} open during the migration. Note: authorized third-party keys and credentials cannot be migrated — after the migration you will need to re-authorize or re-enter them in Settings.",- "confirm": "OK",+ "confirm": "Continue","migrating": "Migrating data, please wait…","failedTitle": "Migration incomplete",- "failedDescription": "The data migration could not be completed this time. You can keep using {{appName}} — it will retry automatically the next time you sign in.",- "continue": "Continue"+ "failedDescription": "The data migration could not be completed this time. You can keep using {{appName}} — it will retry automatically the next time you sign in."},"splash": {"tips": {diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex b4033d99d8..33e33e3044 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -2814,11 +2814,10 @@"legacyMigration": {"title": "旧バージョンのデータを移行","description": "このデバイスに旧バージョンのデータが見つかりました。チャット履歴とメディアファイルを新しいデータ保存先に移行します。旧バージョンのアプリが起動中の場合は、先に完全に終了してください。移行中は {{appName}} を閉じないでください。ご注意:認証済みのサードパーティのキーや資格情報は移行できません。移行完了後、設定で再認証または再入力が必要です。",- "confirm": "OK",+ "confirm": "続行","migrating": "データを移行しています。しばらくお待ちください…","failedTitle": "移行が完了しませんでした",- "failedDescription": "今回はデータ移行を完了できませんでした。{{appName}} はそのまま利用できます。次回のログイン時に自動的に再試行されます。",- "continue": "続行"+ "failedDescription": "今回はデータ移行を完了できませんでした。{{appName}} はそのまま利用できます。次回のログイン時に自動的に再試行されます。"},"splash": {"tips": {diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 6ab927b573..d7a8249b9b 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -2814,11 +2814,10 @@"legacyMigration": {"title": "이전 버전 데이터 마이그레이션","description": "이 기기에서 이전 버전의 데이터가 발견되었습니다. 채팅 기록과 미디어 파일을 새 데이터 위치로 마이그레이션합니다. 이전 버전 앱이 실행 중이라면 먼저 완전히 종료해 주세요. 마이그레이션 중에는 {{appName}}을(를) 닫지 마세요.참고: 승인된 서드파티 키와 자격 증명은 마이그레이션할 수 없습니다. 마이그레이션 완료 후 설정에서 다시 승인하거나 다시 입력해야 합니다.",- "confirm": "확인",+ "confirm": "계속","migrating": "데이터를 마이그레이션하는 중입니다. 잠시 기다려 주세요…","failedTitle": "마이그레이션이 완료되지 않았습니다",- "failedDescription": "이번에는 데이터 마이그레이션을 완료하지 못했습니다. {{appName}}은(는) 계속 사용할 수 있으며, 다음 로그인 시 자동으로 다시 시도합니다.",- "continue": "계속"+ "failedDescription": "이번에는 데이터 마이그레이션을 완료하지 못했습니다. {{appName}}은(는) 계속 사용할 수 있으며, 다음 로그인 시 자동으로 다시 시도합니다."},"splash": {"tips": {diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 46d45921ee..75b31c4e68 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -2814,11 +2814,10 @@"legacyMigration": {"title": "迁移旧版本数据","description": "检测到本机存有旧版本的数据。历史会话和媒体文件将迁移到新的数据位置。若旧版应用正在运行,请先完全退出它;迁移期间请保持 {{appName}} 打开。注意:已授权的第三方密钥与凭证无法随数据迁移,迁移完成后需要在设置中重新授权或重新填写。",- "confirm": "确定",+ "confirm": "继续","migrating": "正在迁移数据,请稍候…","failedTitle": "迁移未完成",- "failedDescription": "本次数据迁移未能完成。你可以继续使用 {{appName}},下次登录时会自动重试。",- "continue": "继续"+ "failedDescription": "本次数据迁移未能完成。你可以继续使用 {{appName}},下次登录时会自动重试。"},"splash": {"tips": {