Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 统一登录页面返回入口 (#4190)

Dash6fb23e60796d
diff --git a/apps/desktop/src/renderer/components/login/LoginPage.tsx b/apps/desktop/src/renderer/components/login/LoginPage.tsx
index 2211cfb1a7..0f8d2dc911 100644
--- a/apps/desktop/src/renderer/components/login/LoginPage.tsx
+++ b/apps/desktop/src/renderer/components/login/LoginPage.tsx
@@ -12,7 +12,6 @@ import {
type ReactNode,
} from 'react';
import { useTranslation } from 'react-i18next';
-import { X } from 'lucide-react';
import type {
AccountDeletionStatus,
CaptchaConfig,
@@ -26,7 +25,6 @@ import { createLogger } from '@/lib/logger';
import { setLoginEmailCaptchaGate } from '@/lib/loginCaptchaGate';
import { flashScrollbar } from '@/lib/scrollbarAutoHide';
import { WindowControls } from '@/components/title-bar/WindowControls';
-import { ChromeIconButton } from '@/components/title-bar/ChromeIconButton';
import { useLogin } from '@/hooks/useLogin';
import { endLoginFirstLaunchLightGate, loginFirstLaunchLightActive } from '@/hooks/useTheme';
import { LOGIN_HANDOFF_TIMINGS, useLoginHandoff } from '@/contexts/LoginHandoffContext';
@@ -724,6 +722,9 @@ export function LoginPage({
return (
<>
<LoginPanel testId="login-panel-identifier">
+ {isAddAccount && onClose ? (
+ <LoginBackButton label={t('login.back')} onClick={onClose} />
+ ) : null}
{/* noValidate:关掉浏览器对 type="email" 的原生约束校验气泡(英文系统提示,
不受主题控制),改由下方本地校验渲染设计稿定义的红边+红字错误态。 */}
<form onSubmit={submitIdentifier} noValidate>
@@ -1273,6 +1274,9 @@ export function LoginPage({
ssoOrgGroupY: false,
node: (
<LoginPanel testId="login-panel-preparing">
+ {isAddAccount && onClose ? (
+ <LoginBackButton label={t('login.back')} onClick={onClose} />
+ ) : null}
<LoginTitleBlock title={t('login.preparing')} subtitle={t('login.preparingSubtitle')} />
<LoginLoadingRing y={LOADING_RING.yPreparing} label={t('login.working')} />
</LoginPanel>
@@ -1310,11 +1314,12 @@ export function LoginPage({
ssoOrgGroupY: false,
node: (
<LoginPanel testId="login-panel-browser-redirect">
+ <LoginBackButton
+ label={t('login.cancel')}
+ onClick={() => void dispatch({ type: 'cancel-browser' })}
+ />
<LoginTitleBlock title={t('login.browserWaiting')} subtitle={loginState.label} />
<LoginLoadingRing y={LOADING_RING.yBrowser} label={t('login.working')} />
- <LoginPrimaryButton onClick={() => void dispatch({ type: 'cancel-browser' })}>
- {t('login.cancel')}
- </LoginPrimaryButton>
</LoginPanel>
),
};
@@ -1454,24 +1459,12 @@ export function LoginPage({
className="absolute left-0 top-0 z-40 flex w-full items-center justify-end"
style={{ height: DRAG_BAR_HEIGHT, WebkitAppRegion: 'drag' } as React.CSSProperties}
>
- {(isAddAccount && onClose) || !isMac ? (
+ {!isMac ? (
<div
className="flex h-full items-center"
style={{ WebkitAppRegion: 'no-drag' } as React.CSSProperties}
>
- {isAddAccount && onClose ? (
- <ChromeIconButton
- data-testid="add-account-close"
- className={isMac ? 'mr-2' : 'mr-1'}
- aria-label={t('sidebar.accountSwitcher.close')}
- tooltip={t('sidebar.accountSwitcher.close')}
- tooltipSide="bottom"
- onClick={onClose}
- >
- <X size={14} aria-hidden="true" />
- </ChromeIconButton>
- ) : null}
- {!isMac ? <WindowControls /> : null}
+ <WindowControls />
</div>
) : null}
</div>
diff --git a/apps/desktop/src/renderer/components/login/__tests__/AddAccountLoginPage.test.tsx b/apps/desktop/src/renderer/components/login/__tests__/AddAccountLoginPage.test.tsx
index ee074299f3..f14b988512 100644
--- a/apps/desktop/src/renderer/components/login/__tests__/AddAccountLoginPage.test.tsx
+++ b/apps/desktop/src/renderer/components/login/__tests__/AddAccountLoginPage.test.tsx
@@ -104,6 +104,7 @@ describe('AddAccountLoginPage app-shell cover', () => {
fireEvent.click(screen.getByRole('button', { name: 'close add-account login' }));
await waitFor(() => expect(auth.cancelAddAccount).toHaveBeenCalledOnce());
+ await waitFor(() => expect(screen.getByTestId('location-probe').textContent).toBe('/settings'));
});
it('starts a fresh flow before honoring a stale completed state', async () => {
diff --git a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.browserRedirect.test.tsx b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.browserRedirect.test.tsx
index 3434edf02f..effa7f0f8f 100644
--- a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.browserRedirect.test.tsx
+++ b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.browserRedirect.test.tsx
@@ -84,12 +84,21 @@ describe('LoginPage browser redirect waiting state', () => {
expect(screen.getByText('Google')).toBeTruthy();
});
- it('still lets the user cancel the pending browser login', () => {
- render(<LoginPage />);
-
- fireEvent.click(screen.getByRole('button', { name: 'login.cancel' }));
- expect(loginHook.dispatch).toHaveBeenCalledWith({ type: 'cancel-browser' });
- });
+ it.each([false, true])(
+ 'uses the panel back button to cancel browser login (loading=%s)',
+ (isLoading) => {
+ loginHook.value.isLoading = isLoading;
+ const onClose = vi.fn();
+ render(<LoginPage intent="add-account" onClose={onClose} />);
+
+ const back = screen.getByRole('button', { name: 'login.cancel' });
+ expect(back.dataset.testid).toBe('login-back-button');
+ expect(screen.getByTestId('login-panel-browser-redirect').contains(back)).toBe(true);
+ fireEvent.click(back);
+ expect(onClose).not.toHaveBeenCalled();
+ expect(loginHook.dispatch).toHaveBeenCalledWith({ type: 'cancel-browser' });
+ },
+ );
it('keeps the local-mode entry available on an authentication error screen', () => {
loginHook.value = {
diff --git a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.harness.test.tsx b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.harness.test.tsx
index 0fed375eab..eda100a850 100644
--- a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.harness.test.tsx
+++ b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.harness.test.tsx
@@ -251,24 +251,53 @@ describe('identifier 态(附录 A providers 场景)', () => {
expect(screen.queryByTestId('login-local-mode')).toBeNull();
});
- it.each([
- ['darwin', 'mr-2'],
- ['win32', 'mr-1'],
- ] as const)('登录更多账号在 %s 标题栏右侧提供关闭按钮', async (platform, marginClass) => {
+ it.each([false, true])('登录更多账号首屏返回会退出流程(loading=%s)', async (isLoading) => {
+ const onClose = vi.fn();
+ mount(await identifierState('providers:both'), { isLoading }, 'add-account', onClose);
+
+ const back = screen.getByRole('button', { name: 'login.back' });
+ expect(screen.getByTestId('login-panel-identifier').contains(back)).toBe(true);
+ expect((back as HTMLButtonElement).disabled).toBe(false);
+ fireEvent.click(back);
+ expect(onClose).toHaveBeenCalledOnce();
+ expect(loginHook.value.dispatch).not.toHaveBeenCalled();
+ });
+
+ it('普通登录首屏不提供退出流程的返回按钮', async () => {
+ mount(await identifierState('providers:both'));
+ expect(screen.queryByRole('button', { name: 'login.back' })).toBeNull();
+ });
+
+ it.each(['darwin', 'win32'])('登录更多账号在 %s 仅保留面板返回入口', async (platform) => {
Object.defineProperty(window, 'electronAPI', {
configurable: true,
value: { platform, acceptPrivacyConsent: async () => ({ allowed: true }) },
});
- const onClose = vi.fn();
- mount(await identifierState('providers:both'), undefined, 'add-account', onClose);
+ mount(await identifierState('providers:both'), undefined, 'add-account', vi.fn());
- const dragBar = screen.getByTestId('login-drag-bar');
- const close = screen.getByTestId('add-account-close');
- expect(dragBar.contains(close)).toBe(true);
- expect(close.className).toContain(marginClass);
+ expect(screen.queryByTestId('add-account-close')).toBeNull();
+ expect(screen.getAllByTestId('login-back-button')).toHaveLength(1);
+ expect(
+ screen.getByTestId('login-drag-bar').contains(screen.getByTestId('login-back-button')),
+ ).toBe(false);
+ });
- fireEvent.click(close);
+ it('添加账号准备时可以返回原页面', () => {
+ const onClose = vi.fn();
+ mount(null, { isLoading: true }, 'add-account', onClose);
+ const back = screen.getByTestId('login-back-button');
+ expect(screen.getByTestId('login-panel-preparing').contains(back)).toBe(true);
+ fireEvent.click(back);
expect(onClose).toHaveBeenCalledOnce();
+ expect(loginHook.value.dispatch).not.toHaveBeenCalled();
+ });
+
+ it('添加账号后续步骤返回仍重置登录而不退出', async () => {
+ const onClose = vi.fn();
+ mount(await methodChoiceState('sso:single'), undefined, 'add-account', onClose);
+ fireEvent.click(screen.getByTestId('login-back-button'));
+ expect(loginHook.value.dispatch).toHaveBeenCalledWith({ type: 'reset' });
+ expect(onClose).not.toHaveBeenCalled();
});
it('「跳过登录」槽与错误提示槽首尾相接且不重叠(error 出现不推移跳过入口)', async () => {
@@ -568,6 +597,7 @@ describe('method-choice(附录 A sso 场景)', () => {
describe('preparing 伪态', () => {
it('loginState 未就绪 → preparing 面板 + 64 loading 环 @(308,193)', () => {
mount(null);
+ expect(screen.queryByTestId('login-back-button')).toBeNull();
expect(screen.getByTestId('login-panel-preparing')).toBeTruthy();
expect(screen.getByText('login.preparing')).toBeTruthy();
expect(screen.getByText('login.preparingSubtitle')).toBeTruthy();
diff --git a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.pr2a.harness.test.tsx b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.pr2a.harness.test.tsx
index 25740ba787..f9676959b0 100644
--- a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.pr2a.harness.test.tsx
+++ b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.pr2a.harness.test.tsx
@@ -391,7 +391,9 @@ describe('browser-redirect / error / completed', () => {
const ring = screen.getByRole('status');
expect(ring.style.top).toBe('158px');
expect(ring.style.width).toBe('64px');
- expect(screen.getByText('login.cancel')).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'login.cancel' }).dataset.testid).toBe(
+ 'login-back-button',
+ );
});
it('error 全屏态:暂时无法登录 + 重试钮 + 错误码文案位(380)', () => {
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index e1ff5c13d0..e04e856dd7 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -1615,7 +1615,7 @@ The execution rulebook for subsequent desktop / mobile UI updates. Sources: the
| `account-selection` | 服务端返回 ≥2 membership,用户选一个 | account row + `LoginTitleBlock`(`chooseAccount`) |
| `binding` | 身份未绑 membership,补绑 phone / email(`codeRequested` 两子态;**无重发钮**,桌面 harness 锁定) | `LoginInput` / `LoginSkinPhoneInput` → `LoginInput`(center) + `LoginPrimaryButton` |
| `account-deletion`(状态浮层) | 账号删除**状态展示**(发起流程在 Settings 的 `AccountDeletionSection`;登录页仅在存在删除回执时以**根层浮层气泡**展示 status,非主状态机 step;详见下方「注销状态浮层气泡」) | `AccountDeletionStatusPanel`(**登录皮容器外**的根层浮层,非面板内) |
-| `browser-redirect` | 社交 / SSO 跳浏览器验证,等待回调 | `LoginLoadingRing` + `LoginPrimaryButton`(取消)+ `LoginTitleBlock` |
+| `browser-redirect` | 社交 / SSO 跳浏览器验证,等待回调 | `LoginLoadingRing` + Desktop `LoginBackButton`(`cancel-browser`;Mobile 保留原取消入口)+ `LoginTitleBlock` |
| `completed` / `error` | 登录成功 / 失败(含 browser 回调终态页);`error` 步桌面另有面板下方 footer 的「跳过登录」**逃生入口**(登录服务不可用时仍能进未登录状态,与面板内入口同口径**过协议门**——2026-07-29 拍板) | 成功无面板(进主界面);error = `LoginBackButton`(仅桌面,复用 reset;普通登录与添加账号均重新加载登录入口)+ `LoginTitleBlock` + `LoginPrimaryButton`(重试)+ `LoginErrorText` + footer「跳过登录」按钮(桌面);browser 回调页 `oauthResultPage`(系统浏览器独立 HTML,main 侧内联常量,色值与 `--login-callback-*` token 同源——renderer CSS var 不可达,改值需两处同步) |
**~~配置错误屏同样承载「跳过登录」逃生入口(移动端)~~〔已作废 2026-07-28:手机端整体剥离,配置错误屏无该入口〕**:`getMobileConfigIssues()` 命中(如 auth base URL 非法)时面板切到 config 提示态,该面板内仍渲染同一个 `LoginSkipLoginLink`(同槽 @(0,430)、同 handler、同 in-flight 门)——跳过登录不发任何网络请求,配置坏掉时恰恰最需要这个入口。