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): 跳过登录后界面状态跟上未登录模式 (#3201)

Dashed7ca44e559c
diff --git a/apps/desktop/src/renderer/__tests__/authContextRace.test.ts b/apps/desktop/src/renderer/__tests__/authContextRace.test.ts
index f33b582591..4338aad98d 100644
--- a/apps/desktop/src/renderer/__tests__/authContextRace.test.ts
+++ b/apps/desktop/src/renderer/__tests__/authContextRace.test.ts
@@ -45,16 +45,16 @@ describe('AuthContext auth-state races', () => {
}
});
- it('repartitions the unified-picker stores on local-mode boundaries too', () => {
- // 本地模式进出同样是一次 dataOwnerId 切换,而它们不经 applyIncomingState ——
- // 漏接两个新 setter 会让本地模式读写上一个身份的收藏 / 引擎 override(2026-08-17
- // review 第五轮 M5)。行为断言在 authContextSessionBoundary.test.tsx。
+ it('applies the complete owner transition on local-mode boundaries', () => {
+ // 本地模式进出同样是一次 dataOwnerId 切换。自己拼半套 setter 会漏草稿 /
+ // prompt / 模型可见性 / 记忆分区(2026-08-21 #3201 Codex P1)。行为断言在
+ // authContextSessionBoundary.test.tsx。
for (const entry of ['const enterLocalMode = useCallback', 'const exitLocalMode = useCallback']) {
const start = source.indexOf(entry);
expect(start).toBeGreaterThan(-1);
- const block = source.slice(start, source.indexOf('[runDataOwnerBoundary]', start));
- expect(block).toContain('setModelEnginePrefsOwner(state.dataOwnerId);');
- expect(block).toContain('setModelFavoritesOwner(state.dataOwnerId);');
+ const block = source.slice(start, source.indexOf('[applyIncomingState, runDataOwnerBoundary]', start));
+ expect(block).toContain('applyIncomingState(state);');
+ expect(block).not.toContain('setModelEnginePrefsOwner(state.dataOwnerId);');
}
});
@@ -84,18 +84,8 @@ describe('AuthContext auth-state races', () => {
);
const enterLocal = source.indexOf('const enterLocalMode = useCallback');
const exitLocal = source.indexOf('const exitLocalMode = useCallback');
- expect(
- source.indexOf(
- 'publishDataOwnerGeneration(state.dataOwnerId, state.ownerGeneration);',
- enterLocal,
- ),
- ).toBeLessThan(exitLocal);
- expect(
- source.indexOf(
- 'publishDataOwnerGeneration(state.dataOwnerId, state.ownerGeneration);',
- exitLocal,
- ),
- ).toBeGreaterThan(exitLocal);
+ expect(source.indexOf('applyIncomingState(state);', enterLocal)).toBeLessThan(exitLocal);
+ expect(source.indexOf('applyIncomingState(state);', exitLocal)).toBeGreaterThan(exitLocal);
expect(source).toContain('activeDataOwnerGenerationRef.current');
expect(source).toContain('setDataOwnerRecoveryEpoch((epoch) => epoch + 1);');
expect(appSource).toContain("`${dataOwnerId ?? 'signed-out'}:${dataOwnerRecoveryEpoch}`");
diff --git a/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx b/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx
index 99ce6ac884..de90cae559 100644
--- a/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/authContextSessionBoundary.test.tsx
@@ -376,10 +376,9 @@ describe('AuthContext session cache boundaries', () => {
});
/**
- * 本地模式也是一次 dataOwnerId 切换(2026-08-17 review 第五轮 M5)。enterLocalMode /
- * exitLocalMode 此前只更新了 dataOwnerId 与另外几个 owner 分区 setter,漏掉统一模型选择器
- * 新增的两根轴 —— 于是本地模式下读写的是**上一个身份**的收藏 / 引擎 override:跨身份可见,
- * 还会把改动写进别人的账号。
+ * 本地模式也是一次 dataOwnerId 切换。enterLocalMode / exitLocalMode 必须走完整
+ * applyIncomingState,不能自己拼半套 setter —— 漏接任一 owner 分区都会让本地模式
+ * 读写上一个身份的数据:跨身份可见,还会把改动写进别人的账号。
*/
it('repartitions unified-picker favorites and engine overrides across local mode', async () => {
resetFavorites();
diff --git a/apps/desktop/src/renderer/components/auth/__tests__/GuestRoute.test.tsx b/apps/desktop/src/renderer/components/auth/__tests__/GuestRoute.test.tsx
new file mode 100644
index 0000000000..d1c74b2db4
--- /dev/null
+++ b/apps/desktop/src/renderer/components/auth/__tests__/GuestRoute.test.tsx
@@ -0,0 +1,67 @@
+// @vitest-environment jsdom
+
+import { cleanup, render, screen } from '@testing-library/react';
+import { MemoryRouter, Route, Routes } from 'react-router-dom';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+const authState = vi.hoisted(() => ({
+ current: {
+ mode: 'signed-out' as 'signed-out' | 'local' | 'cloud',
+ isInitializing: false,
+ },
+}));
+
+vi.mock('@/contexts/AuthContext', () => ({
+ useAuth: () => authState.current,
+}));
+
+import { GuestRoute } from '../GuestRoute';
+
+function renderAt(path: string) {
+ return render(
+ <MemoryRouter initialEntries={[path]}>
+ <Routes>
+ <Route path="/" element={<div data-testid="app-shell" />} />
+ <Route path="/login" element={<GuestRoute />}>
+ <Route index element={<div data-testid="login-page" />} />
+ </Route>
+ </Routes>
+ </MemoryRouter>,
+ );
+}
+
+describe('GuestRoute', () => {
+ afterEach(() => {
+ cleanup();
+ authState.current = {
+ mode: 'signed-out',
+ isInitializing: false,
+ };
+ });
+
+ it('keeps the login page for a real signed-out session', () => {
+ renderAt('/login');
+ expect(screen.getByTestId('login-page')).toBeTruthy();
+ expect(screen.queryByTestId('app-shell')).toBeNull();
+ });
+
+ it('leaves login once skip-sign-in has committed local mode', () => {
+ authState.current = {
+ mode: 'local',
+ isInitializing: false,
+ };
+ renderAt('/login');
+ expect(screen.getByTestId('app-shell')).toBeTruthy();
+ expect(screen.queryByTestId('login-page')).toBeNull();
+ });
+
+ it('leaves login for a cloud session', () => {
+ authState.current = {
+ mode: 'cloud',
+ isInitializing: false,
+ };
+ renderAt('/login');
+ expect(screen.getByTestId('app-shell')).toBeTruthy();
+ expect(screen.queryByTestId('login-page')).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/renderer/components/login/LoginPage.tsx b/apps/desktop/src/renderer/components/login/LoginPage.tsx
index 35f17b53cd..aa21d771f2 100644
--- a/apps/desktop/src/renderer/components/login/LoginPage.tsx
+++ b/apps/desktop/src/renderer/components/login/LoginPage.tsx
@@ -119,6 +119,7 @@ export function LoginPage() {
dispatch,
dispatchWithResult,
clearError,
+ enterLocalMode,
} = useLogin();
const { t } = useTranslation();
const handoff = useLoginHandoff();
@@ -154,17 +155,19 @@ export function LoginPage() {
* 在会话切过去之后落,不能由 requireConsent 提前落(竞态原因见那里的注释)。
*/
const openLocalMode = async () => {
- if (isLoading || localModePendingRef.current || !window.electronAPI?.authEnterLocal) return;
+ if (isLoading || localModePendingRef.current || !enterLocalMode) return;
markLocalModeTransition(true);
try {
- await window.electronAPI.authEnterLocal();
+ // 必须走 AuthContext.enterLocalMode():它调同一条 IPC,并用返回值立刻改
+ // mode / canEnterApp。登录页自己调 authEnterLocal 只改主进程会话,界面
+ // 仍当自己没进来;广播一旦没赶上,再点一次也不会重播,登录页就钉死。
+ // GuestRoute 看到 mode === 'local' 后自己切走,不要在这里改 hash——
+ // canEnterApp 还是 false 时冲进受保护路由会被踢回 /login。
+ await enterLocalMode();
// 顺序是硬要求:先 enter-local(main 侧 isLocalMode() 转真)再落同意,这样
// acceptPrivacyConsent 广播出来的 allowed 恒为 false,TapDB 不会被拉起来发
// device_login。反过来会开出一个真实的上报窗口(codex 审查 P1,#907)。
persistPrivacyConsent();
- // The auth state event normally redirects through GuestRoute. Keep the
- // transition deterministic when the IPC response wins that race.
- window.location.hash = '#/';
} catch (error) {
// 两个调用点都是 requireConsent(() => void openLocalMode()):抛出去没人接,
// 会变成 unhandled rejection。IPC 失败(main 未就绪/通道异常)时停在登录页
diff --git a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx
index 8be08c8f89..bf1a17922d 100644
--- a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx
+++ b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx
@@ -22,6 +22,7 @@ const loginHook = vi.hoisted(() => ({
dispatch: vi.fn(async () => true),
dispatchWithResult: vi.fn(async () => ({ success: true, code: null })),
clearError: vi.fn(),
+ enterLocalMode: vi.fn(async (): Promise<void> => undefined),
},
}));
@@ -61,6 +62,16 @@ async function identifierState(scenario: string): Promise<AuthFlowState> {
return reduceAuthFlow(null, { type: 'providers-loaded', providers });
}
+const openExternal = vi.fn(async () => ({ success: true }));
+const enterLocalMode = vi.fn(async (): Promise<void> => undefined);
+// 协议门放行时会把「已同意」落到 main(TapDB 采集的前置条件,见
+// main/analytics-settings-store.ts)。它是 fire-and-forget,不参与登录派发时序。
+const acceptPrivacyConsent = vi.fn(async () => ({
+ privacyConsentAccepted: true,
+ analyticsEnabled: true,
+ allowed: true,
+}));
+
function mount(state: AuthFlowState | null, extra?: Partial<typeof loginHook.value>) {
loginHook.value = {
isLoading: false,
@@ -69,28 +80,19 @@ function mount(state: AuthFlowState | null, extra?: Partial<typeof loginHook.val
dispatch: vi.fn(async () => true),
dispatchWithResult: vi.fn(async () => ({ success: true, code: null })),
clearError: vi.fn(),
+ enterLocalMode,
...extra,
};
return render(<LoginPage />);
}
-const openExternal = vi.fn(async () => ({ success: true }));
-const authEnterLocal = vi.fn(async () => ({ mode: 'local' }));
-// 协议门放行时会把「已同意」落到 main(TapDB 采集的前置条件,见
-// main/analytics-settings-store.ts)。它是 fire-and-forget,不参与登录派发时序。
-const acceptPrivacyConsent = vi.fn(async () => ({
- privacyConsentAccepted: true,
- analyticsEnabled: true,
- allowed: true,
-}));
-
beforeEach(() => {
openExternal.mockClear();
- authEnterLocal.mockClear();
+ enterLocalMode.mockClear();
acceptPrivacyConsent.mockClear();
Object.defineProperty(window, 'electronAPI', {
configurable: true,
- value: { platform: 'darwin', openExternal, authEnterLocal, acceptPrivacyConsent },
+ value: { platform: 'darwin', openExternal, acceptPrivacyConsent },
});
});
@@ -243,18 +245,18 @@ describe('consent guard(未勾选拦截个人登录链路)', () => {
// 2026-07-29 拍板(推翻同年 07-27「跳过登录免协议门」):不登录账号也是在用 Cindy
// 客户端,跳过登录与个人账号登录同口径先过协议门。旧游客圆钮入口已删除。
- it('「跳过登录」未勾选 → 弹窗且不进本地模式;同意 → 续接 authEnterLocal', async () => {
+ it('「跳过登录」未勾选 → 弹窗且不进本地模式;同意 → 续接 enterLocalMode', async () => {
mount(await identifierState('providers:cn-social'));
expect(screen.getByTestId('login-consent-radio').getAttribute('aria-checked')).toBe('false');
await act(async () => {
fireEvent.click(screen.getByTestId('login-skip-entry'));
});
expect(screen.getByTestId('login-consent-dialog')).toBeTruthy();
- expect(authEnterLocal).not.toHaveBeenCalled();
+ expect(enterLocalMode).not.toHaveBeenCalled();
await act(async () => {
fireEvent.click(screen.getByTestId('login-consent-agree'));
});
- expect(authEnterLocal).toHaveBeenCalledTimes(1);
+ expect(enterLocalMode).toHaveBeenCalledTimes(1);
});
it('「跳过登录」不同意 → 停在登录页,不进本地模式', async () => {
@@ -264,7 +266,7 @@ describe('consent guard(未勾选拦截个人登录链路)', () => {
});
fireEvent.click(screen.getByTestId('login-consent-disagree'));
expect(screen.queryByTestId('login-consent-dialog')).toBeNull();
- expect(authEnterLocal).not.toHaveBeenCalled();
+ expect(enterLocalMode).not.toHaveBeenCalled();
expect(screen.getByTestId('login-consent-radio').getAttribute('aria-checked')).toBe('false');
});
@@ -275,19 +277,19 @@ describe('consent guard(未勾选拦截个人登录链路)', () => {
fireEvent.click(screen.getByTestId('login-skip-entry'));
});
expect(screen.queryByTestId('login-consent-dialog')).toBeNull();
- expect(authEnterLocal).toHaveBeenCalledTimes(1);
+ expect(enterLocalMode).toHaveBeenCalledTimes(1);
expect(acceptPrivacyConsent).toHaveBeenCalled();
});
- /* 顺序回归(codex 审查 P1,#907):同意记录必须落在 auth:enter-local **之后**。
+ /* 顺序回归(codex 审查 P1,#907):同意记录必须落在 enterLocalMode **之后**。
acceptPrivacyConsent 的 handler 会同步广播 allowed,而 allowed 的算式是
isAnalyticsAllowed() && !isLocalMode() —— 提前落同意时 isLocalMode() 还是
false,广播 allowed:true 会让 tapdbClient 当场 initSdk() 并发出 device_login,
与「未登录态不上报」直接冲突。两个入口、勾选与弹窗两条路径都要锁。 */
const expectConsentPersistedAfterEnterLocal = () => {
- expect(authEnterLocal).toHaveBeenCalledTimes(1);
+ expect(enterLocalMode).toHaveBeenCalledTimes(1);
expect(acceptPrivacyConsent).toHaveBeenCalledTimes(1);
- expect(authEnterLocal.mock.invocationCallOrder[0]).toBeLessThan(
+ expect(enterLocalMode.mock.invocationCallOrder[0]).toBeLessThan(
acceptPrivacyConsent.mock.invocationCallOrder[0],
);
};
@@ -312,24 +314,24 @@ describe('consent guard(未勾选拦截个人登录链路)', () => {
expectConsentPersistedAfterEnterLocal();
});
- /* 并发窗口回归(codex 审查 P1 第二条,#907):auth:enter-local 的 handler 要 await
+ /* 并发窗口回归(codex 审查 P1 第二条,#907):enterLocalMode 最终仍要 await
waitForSessionInvalidation() + teardownAuthAccountBoundary(),这段窗口里 isLoading
仍是 false、弹窗已关、consentAccepted 已为 true,于是邮箱 / 社交等入口仍可点。
它们走 deferConsentPersist=false 分支,会在 main 还没转成 local 时立刻 persist,
把 allowed:true 广播给 TapDB —— 必须一个都不放过。 */
it('会话切换窗口内点社交圆钮 → 不派发、不落同意;切换完成后只落 skip 自己那一次', async () => {
let releaseEnterLocal: () => void = () => undefined;
- authEnterLocal.mockImplementationOnce(
+ enterLocalMode.mockImplementationOnce(
() =>
- new Promise((resolve) => {
- releaseEnterLocal = () => resolve({ mode: 'local' });
+ new Promise<void>((resolve) => {
+ releaseEnterLocal = () => resolve();
}),
);
mount(await identifierState('providers:cn-social'));
fireEvent.click(screen.getByTestId('login-consent-radio'));
// 不 await:enter-local 故意悬挂在窗口里
fireEvent.click(screen.getByTestId('login-skip-entry'));
- expect(authEnterLocal).toHaveBeenCalledTimes(1);
+ expect(enterLocalMode).toHaveBeenCalledTimes(1);
expect(acceptPrivacyConsent).not.toHaveBeenCalled();
// 窗口内点其它过门入口:一律作废
@@ -345,7 +347,7 @@ describe('consent guard(未勾选拦截个人登录链路)', () => {
});
// 只有 skip 自己那一次同意记录,且它落在 enter-local 之后
expect(acceptPrivacyConsent).toHaveBeenCalledTimes(1);
- expect(authEnterLocal.mock.invocationCallOrder[0]).toBeLessThan(
+ expect(enterLocalMode.mock.invocationCallOrder[0]).toBeLessThan(
acceptPrivacyConsent.mock.invocationCallOrder[0],
);
});
@@ -360,7 +362,7 @@ describe('consent guard(未勾选拦截个人登录链路)', () => {
});
// 账号登录链路登录后 isLocalMode() 为 false、allowed 本就该为真,顺序无需延后
expect(acceptPrivacyConsent).toHaveBeenCalledTimes(1);
- expect(authEnterLocal).not.toHaveBeenCalled();
+ expect(enterLocalMode).not.toHaveBeenCalled();
});
/* error 步 footer 的逃生入口(login-local-mode)与面板内入口共用 openLocalMode,
@@ -378,14 +380,14 @@ describe('consent guard(未勾选拦截个人登录链路)', () => {
fireEvent.click(screen.getByTestId('login-local-mode'));
});
expect(screen.getByTestId('login-consent-dialog')).toBeTruthy();
- expect(authEnterLocal).not.toHaveBeenCalled();
+ expect(enterLocalMode).not.toHaveBeenCalled();
await act(async () => {
fireEvent.click(screen.getByTestId('login-consent-agree'));
});
- expect(authEnterLocal).toHaveBeenCalledTimes(1);
+ expect(enterLocalMode).toHaveBeenCalledTimes(1);
expect(acceptPrivacyConsent).toHaveBeenCalledTimes(1);
// 顺序同面板内入口:先切会话再落同意(见下方顺序回归组的注释)
- expect(authEnterLocal.mock.invocationCallOrder[0]).toBeLessThan(
+ expect(enterLocalMode.mock.invocationCallOrder[0]).toBeLessThan(
acceptPrivacyConsent.mock.invocationCallOrder[0],
);
});
@@ -397,7 +399,7 @@ describe('consent guard(未勾选拦截个人登录链路)', () => {
});
fireEvent.click(screen.getByTestId('login-consent-disagree'));
expect(screen.queryByTestId('login-consent-dialog')).toBeNull();
- expect(authEnterLocal).not.toHaveBeenCalled();
+ expect(enterLocalMode).not.toHaveBeenCalled();
// 逃生入口本身必须还在(不同意不等于把这条唯一出路关掉)
expect(screen.getByTestId('login-local-mode')).toBeTruthy();
});
diff --git a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.region.harness.test.tsx b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.region.harness.test.tsx
index ccdcd359f2..a3822eeaf6 100644
--- a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.region.harness.test.tsx
+++ b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.region.harness.test.tsx
@@ -27,6 +27,7 @@ const loginHook = vi.hoisted(() => ({
dispatch: vi.fn(async () => true),
dispatchWithResult: vi.fn(async () => ({ success: true, code: null })),
clearError: vi.fn(),
+ enterLocalMode: vi.fn(async (): Promise<void> => undefined),
},
}));
@@ -64,6 +65,14 @@ async function globalIdentifierState(scenario = 'providers:global-social'): Prom
return reduceAuthFlow(null, { type: 'providers-loaded', providers });
}
+const openExternal = vi.fn(async () => ({ success: true }));
+const enterLocalMode = vi.fn(async (): Promise<void> => undefined);
+const acceptPrivacyConsent = vi.fn(async () => ({
+ privacyConsentAccepted: true,
+ analyticsEnabled: true,
+ allowed: true,
+}));
+
function mount(state: AuthFlowState | null, extra?: Partial<typeof loginHook.value>) {
loginHook.value = {
isLoading: false,
@@ -72,28 +81,21 @@ function mount(state: AuthFlowState | null, extra?: Partial<typeof loginHook.val
dispatch: vi.fn(async () => true),
dispatchWithResult: vi.fn(async () => ({ success: true, code: null })),
clearError: vi.fn(),
+ enterLocalMode,
...extra,
};
return render(<LoginPage />);
}
-const openExternal = vi.fn(async () => ({ success: true }));
-const authEnterLocal = vi.fn(async () => ({ mode: 'local' }));
-const acceptPrivacyConsent = vi.fn(async () => ({
- privacyConsentAccepted: true,
- analyticsEnabled: true,
- allowed: true,
-}));
-
beforeEach(() => {
// isGlobalBuild 在渲染时读 import.meta.env,必须在 render 前置好
vi.stubEnv('VITE_CINDY_AUTH_REGION', 'global');
openExternal.mockClear();
- authEnterLocal.mockClear();
+ enterLocalMode.mockClear();
acceptPrivacyConsent.mockClear();
Object.defineProperty(window, 'electronAPI', {
configurable: true,
- value: { platform: 'darwin', openExternal, authEnterLocal, acceptPrivacyConsent },
+ value: { platform: 'darwin', openExternal, acceptPrivacyConsent },
});
});
@@ -160,12 +162,12 @@ describe('Global 构建变体:登录改版四件事同样生效', () => {
fireEvent.click(screen.getByTestId('login-skip-entry'));
});
expect(screen.getByTestId('login-consent-dialog')).toBeTruthy();
- expect(authEnterLocal).not.toHaveBeenCalled();
+ expect(enterLocalMode).not.toHaveBeenCalled();
expect(acceptPrivacyConsent).not.toHaveBeenCalled();
await act(async () => {
fireEvent.click(screen.getByTestId('login-consent-agree'));
});
- expect(authEnterLocal).toHaveBeenCalledTimes(1);
+ expect(enterLocalMode).toHaveBeenCalledTimes(1);
expect(acceptPrivacyConsent).toHaveBeenCalled();
});
diff --git a/apps/desktop/src/renderer/contexts/AuthContext.tsx b/apps/desktop/src/renderer/contexts/AuthContext.tsx
index bdde609986..de3dd90ad5 100644
--- a/apps/desktop/src/renderer/contexts/AuthContext.tsx
+++ b/apps/desktop/src/renderer/contexts/AuthContext.tsx
@@ -391,46 +391,17 @@ export function AuthProvider({
}, [runDataOwnerBoundary]);
const enterLocalMode = useCallback(async () => {
+ // 本地模式也是一次 dataOwnerId 切换。必须走 applyIncomingState,不能自己拼半套
+ // setter:漏接草稿 / prompt / 模型可见性 / 记忆分区会让跳过登录进主界面后仍读写
+ // signed-out 槽(2026-08-21 #3201 Codex P1)。
const state = await runDataOwnerBoundary(() => authServiceRef.current!.enterLocalMode());
- publishDataOwnerGeneration(state.dataOwnerId, state.ownerGeneration);
- activeDataOwnerIdRef.current = state.dataOwnerId;
- activeDataOwnerGenerationRef.current = state.ownerGeneration;
- // 统一模型选择器的两根轴与本地模式的其它 owner 分区同待遇(2026-08-17 review 第五轮 M5):
- // 本地模式也是一次 dataOwnerId 切换,漏接这两个 setter 会让本地模式下的收藏 / 引擎 override
- // 继续读写**上一个身份**的分区 —— 跨身份可见,还会把改动写进别人的账号。
- setModelEnginePrefsOwner(state.dataOwnerId);
- setModelFavoritesOwner(state.dataOwnerId);
- // 收藏**锚点**记忆(面板上哪一行打勾)与收藏本体同分区:漏接同样是多账号串号。
- setFavoriteAnchorMemoryOwner(state.dataOwnerId);
- setComposerDraftOwner(state.dataOwnerId);
- setPendingHandoffOwner(state.dataOwnerId);
- setDeferredUiAssignmentOwner(state.dataOwnerId);
- setMode(state.mode);
- setDataOwnerId(state.dataOwnerId);
- setCanEnterApp(state.canEnterApp);
- setIsAuthenticated(state.isAuthenticated);
- setUser(state.user);
- }, [runDataOwnerBoundary]);
+ applyIncomingState(state);
+ }, [applyIncomingState, runDataOwnerBoundary]);
const exitLocalMode = useCallback(async () => {
const state = await runDataOwnerBoundary(() => authServiceRef.current!.exitLocalMode());
- publishDataOwnerGeneration(state.dataOwnerId, state.ownerGeneration);
- activeDataOwnerIdRef.current = state.dataOwnerId;
- activeDataOwnerGenerationRef.current = state.ownerGeneration;
- // 退出本地模式同样是一次 owner 切换:两根轴必须一起跟过去(见 enterLocalMode 的注释)。
- setModelEnginePrefsOwner(state.dataOwnerId);
- setModelFavoritesOwner(state.dataOwnerId);
- // 收藏**锚点**记忆(面板上哪一行打勾)与收藏本体同分区:漏接同样是多账号串号。
- setFavoriteAnchorMemoryOwner(state.dataOwnerId);
- setComposerDraftOwner(state.dataOwnerId);
- setPendingHandoffOwner(state.dataOwnerId);
- setDeferredUiAssignmentOwner(state.dataOwnerId);
- setMode(state.mode);
- setDataOwnerId(state.dataOwnerId);
- setCanEnterApp(state.canEnterApp);
- setIsAuthenticated(state.isAuthenticated);
- setUser(state.user);
- }, [runDataOwnerBoundary]);
+ applyIncomingState(state);
+ }, [applyIncomingState, runDataOwnerBoundary]);
const getAccountDeletionAvailability = useCallback(
() => authServiceRef.current!.getAccountDeletionAvailability(),
diff --git a/apps/desktop/src/renderer/hooks/useLogin.ts b/apps/desktop/src/renderer/hooks/useLogin.ts
index 8088cefeb9..eb7662854c 100644
--- a/apps/desktop/src/renderer/hooks/useLogin.ts
+++ b/apps/desktop/src/renderer/hooks/useLogin.ts
@@ -21,6 +21,12 @@ interface UseLoginReturn {
action: DesktopLoginAction,
) => Promise<{ success: boolean; code: string | null }>;
clearError: () => void;
+ /**
+ * 「跳过登录」必须走这里,不能直接调 `authEnterLocal` IPC。
+ * AuthContext 会用返回值立刻改 `mode` / `canEnterApp`;绕过它只改主进程会话,
+ * 界面仍停在登录页,再点一次也不会重播状态。
+ */
+ enterLocalMode: ReturnType<typeof useAuth>['enterLocalMode'];
}
/** Coordinates presentation state while all credentials and tickets stay in main. */
@@ -32,6 +38,7 @@ export function useLogin(): UseLoginReturn {
hasAccountDeletionReceipt,
getAccountDeletionStatus,
clearAccountDeletionReceipt,
+ enterLocalMode,
} = useAuth();
const [isLoading, setIsLoading] = useState(false);
const [errorCode, setErrorCode] = useState<string | null>(null);
@@ -94,5 +101,6 @@ export function useLogin(): UseLoginReturn {
dispatch,
dispatchWithResult,
clearError: () => setErrorCode(null),
+ enterLocalMode,
};
}