From 70569945997db650a2eb81bb0aa2bd415f5291fe Mon Sep 17 00:00:00 2001 From: SquarePots <46488165+squarepots@users.noreply.github.com> Date: Thu, 5 Nov 2026 18:03:01 +0800 Subject: [PATCH] Make the email and link copy actions clear when signing in again --- docs/design.md | 10 +++++---- src/AccountIntake.tsx | 48 ++++++++++++++++++++++++------------------- src/App.test.tsx | 38 ++++++++++++++++++++++++++++++++-- src/App.tsx | 2 +- src/i18n.ts | 22 +++++++++----------- src/styles.css | 44 +++++++++++++++++++++++++++++++-------- 6 files changed, 115 insertions(+), 49 deletions(-) diff --git a/docs/design.md b/docs/design.md index ca69419..a723188 100644 --- a/docs/design.md +++ b/docs/design.md @@ -93,7 +93,8 @@ it says nothing was changed, and its recovery dialog offers **Get GSwitch the account grid or reload the whole workspace before showing it. Other brief success and information messages use one compact floating notice without moving the grid and dismiss themselves. Errors stay until dismissed. Focused - dialogs cover this notice; recovery and update actions use their own surfaces. + dialogs cover this notice; recovery and update actions use their own surfaces, + and a copy action inside a dialog reports its result on its own button. - Opening a dialog moves keyboard focus inside it. Tab stays inside, and closing restores focus to the launching control. A dialog cannot be dismissed while its non-cancellable action is in progress. @@ -153,9 +154,10 @@ it says nothing was changed, and its recovery dialog offers **Get GSwitch also keeps **Sign in again** in that menu, so recovery never depends on GSwitch diagnosing a failure correctly. After a confirmed authentication failure, the card additionally shows **Sign in required** and makes - **Sign in again** its primary action. The focused dialog shows the saved - email and workspace, offers Copy email, and updates the original record only - after verifying the returning identity. A saved login for the current account + **Sign in again** its primary action. The focused dialog names the saved + email without its workspace, offers Copy email and Copy link as equally + visible buttons, and updates the original record only after verifying the + returning identity. A saved login for the current account that could not be applied shows **Apply**. The current badge identifies the selected local Codex account without claiming that its remote sign-in is valid. - After Wake, sign-in, or refresh, update affected cards in place. Preserve diff --git a/src/AccountIntake.tsx b/src/AccountIntake.tsx index c4b580a..b923bfb 100644 --- a/src/AccountIntake.tsx +++ b/src/AccountIntake.tsx @@ -23,6 +23,26 @@ interface OAuthFlow extends OAuthLoginStart { status: OAuthLoginStatus; } +// A focused dialog covers the floating notice, so a copy reports on its own button. +function CopyButton({ label, text, t }: { label: string; text: string; t: Translator }) { + const [state, setState] = useState<"idle" | "copied" | "failed">("idle"); + const timer = useRef(undefined); + useEffect(() => () => window.clearTimeout(timer.current), []); + const copy = async () => { + let outcome: "copied" | "failed" = "copied"; + try { await navigator.clipboard.writeText(text); } catch { outcome = "failed"; } + setState(outcome); + window.clearTimeout(timer.current); + timer.current = window.setTimeout(() => setState("idle"), 2000); + }; + const Icon = state === "copied" ? Check : state === "failed" ? CircleAlert : Copy; + return ( + + ); +} + function fileFilters(t: Translator) { return [{ name: t("file.accountExports"), extensions: ["json"] }]; } function migrationSourceLabel(candidate: MigrationCandidate, t: Translator) { return candidate.source === "official_codex" @@ -361,18 +381,6 @@ export function useAccountIntake(input: Input) { } }; - const copyOAuthUrl = async () => { - if (!oauth) { - return; - } - try { - await navigator.clipboard.writeText(oauth.auth_url); - setNotice({ kind: "success", text: t("notice.oauthCopied") }); - } catch { - setNotice({ kind: "info", text: t("notice.copyManually") }); - } - }; - const submitJson = async (event: FormEvent) => { event.preventDefault(); const rawJson = jsonRef.current?.value ?? ""; @@ -415,15 +423,14 @@ export function useAccountIntake(input: Input) { catch { setNotice({ kind: "error", text: t("oauth.openFailed") }); } }; return { busy, addMethod, setAddMethod, migrationPreview, migrationRoot, migrationSelection, setMigrationSelection, migrationScanned, oauth, oauthTarget, oauthStatusUnavailable, label, setLabel, jsonRef, apiKeyRef, - startOAuth, openAddDialog, closeAddDialog, chooseImportFile, chooseMigrationFolder, scanMigration, confirmMigration, cancelOAuth, retryOAuthSave, copyOAuthUrl, submitJson, submitApiKey, openBrowser }; + startOAuth, openAddDialog, closeAddDialog, chooseImportFile, chooseMigrationFolder, scanMigration, confirmMigration, cancelOAuth, retryOAuthSave, submitJson, submitApiKey, openBrowser }; } -export function AccountIntakeDialog({ flow, busy, onCopyEmail, t }: { - flow: ReturnType; busy: string | null; onCopyEmail: (account: AccountView) => Promise; t: Translator; +export function AccountIntakeDialog({ flow, busy, t }: { + flow: ReturnType; busy: string | null; t: Translator; }) { const { addMethod, setAddMethod, migrationPreview, migrationRoot, migrationSelection, setMigrationSelection, migrationScanned, oauth, oauthTarget, oauthStatusUnavailable, label, setLabel, jsonRef, apiKeyRef, - startOAuth, openAddDialog, closeAddDialog, chooseImportFile, chooseMigrationFolder, scanMigration, confirmMigration, cancelOAuth, retryOAuthSave, copyOAuthUrl, submitJson, submitApiKey } = flow; - const copyAccountEmail = onCopyEmail; + startOAuth, openAddDialog, closeAddDialog, chooseImportFile, chooseMigrationFolder, scanMigration, confirmMigration, cancelOAuth, retryOAuthSave, submitJson, submitApiKey } = flow; const runningAny = (...keys: string[]) => busy !== null && keys.includes(busy); return ( @@ -517,9 +524,8 @@ export function AccountIntakeDialog({ flow, busy, onCopyEmail, t }: { {addMethod === "oauth" && oauth ? (
{oauthTarget ?
- {t("oauth.targetEmail", { email: oauthTarget.email || accountPrimaryName(oauthTarget) })} - {oauthTarget.workspace_name ? {t("oauth.targetWorkspace", { workspace: oauthTarget.workspace_name })} : null} - {oauthTarget.email ? : null} + {t("oauth.targetEmail")}{oauthTarget.email || accountPrimaryName(oauthTarget)} + {oauthTarget.email ? : null}
: null} {oauth.status.status === "pending" ? ( <> @@ -531,7 +537,7 @@ export function AccountIntakeDialog({ flow, busy, onCopyEmail, t }: {
- +
diff --git a/src/App.test.tsx b/src/App.test.tsx index 083423d..a317301 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -1615,7 +1615,7 @@ describe("GSwitch account workspace", () => { expect(mocks.refreshAccountQuota).not.toHaveBeenCalled(); }); - it("shows a direct recovery action with the saved email and workspace", async () => { + it("shows a direct recovery action with the saved email and without its workspace", async () => { mocks.listAccounts.mockResolvedValue([{ ...chatAccount, sign_in_required: true }]); mocks.accountQuota.mockResolvedValue(staleQuota); render(); @@ -1625,7 +1625,41 @@ describe("GSwitch account workspace", () => { expect(mocks.startOAuth).toHaveBeenCalledWith("account-1"); const dialog = await screen.findByRole("dialog", { name: "Sign in again · person@example.com" }); expect(dialog).toHaveTextContent("Account: person@example.com"); - expect(dialog).toHaveTextContent("Workspace: Personal"); + expect(dialog).not.toHaveTextContent("Workspace"); + expect(dialog).not.toHaveTextContent("Personal"); + }); + + it("reports sign-in copies on their own buttons because the dialog covers the notice", async () => { + vi.useFakeTimers({ shouldAdvanceTime: true }); + try { + const writeText = vi.fn().mockResolvedValue(undefined); + Object.defineProperty(window.navigator, "clipboard", { configurable: true, value: { writeText } }); + mocks.listAccounts.mockResolvedValue([{ ...chatAccount, sign_in_required: true }]); + render(); + const card = (await screen.findByRole("heading", { name: "person@example.com" })).closest("article"); + await act(async () => { fireEvent.click(within(card as HTMLElement).getByRole("button", { name: "Sign in again" })); }); + const dialog = await screen.findByRole("dialog", { name: "Sign in again · person@example.com" }); + + await act(async () => { fireEvent.click(within(dialog).getByRole("button", { name: "Copy email" })); }); + expect(writeText).toHaveBeenLastCalledWith("person@example.com"); + expect(within(dialog).getByRole("button", { name: "Copied" })).toBeInTheDocument(); + expect(screen.queryByText("Email copied.")).not.toBeInTheDocument(); + await act(async () => { vi.advanceTimersByTime(2000); }); + expect(within(dialog).getByRole("button", { name: "Copy email" })).toBeInTheDocument(); + + await act(async () => { fireEvent.click(within(dialog).getByRole("button", { name: "Copy link" })); }); + expect(writeText).toHaveBeenLastCalledWith("https://auth.openai.com/example"); + expect(within(dialog).getByRole("button", { name: "Copied" })).toBeInTheDocument(); + await act(async () => { vi.advanceTimersByTime(2000); }); + expect(within(dialog).getByRole("button", { name: "Copy link" })).toBeInTheDocument(); + + writeText.mockRejectedValueOnce(new Error("denied")); + await act(async () => { fireEvent.click(within(dialog).getByRole("button", { name: "Copy email" })); }); + expect(within(dialog).getByRole("button", { name: "Copy failed" })).toBeInTheDocument(); + } finally { + cleanup(); + vi.useRealTimers(); + } }); it("updates one account quota without reloading the account workspace", async () => { diff --git a/src/App.tsx b/src/App.tsx index c631385..2edc886 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -882,7 +882,7 @@ export default function App() {
- {dialog === "add" ? : null} + {dialog === "add" ? : null} {dialog === "export" ? ( = { "notice.migration": "已导入 {imported} 个账户;{duplicates} 个已存在或重复;{skipped} 个不受支持或失败。", "notice.exported": "已导出 {count} 个所选账户。请妥善保管未加密文件。", "notice.oauthReady": "登录链接已就绪。请复制后在你常用的浏览器中打开。", - "notice.oauthCopied": "登录链接已复制。", - "notice.copyManually": "请选中下方登录链接并手动复制。", "notice.pasteAuth": "请先粘贴完整的 auth JSON 文档。", "notice.enterApiKey": "请先输入 API 密钥。", "notice.importedAccount": "已安全导入 {name}。", @@ -585,15 +582,14 @@ const zhCN: Record = { "oauth.finishTitle": "请在浏览器中完成登录", "oauth.finishBody": "Codex 确认登录后,GSwitch 会添加已验证的账户。", "oauth.reauthenticateTitle": "重新登录 · {name}", - "oauth.reauthenticateBody": "请登录同一邮箱和工作区。GSwitch 只会更新这个已保存账户。", + "oauth.reauthenticateBody": "请登录同一邮箱。GSwitch 只会更新这个已保存账户。", "oauth.reauthenticated": "已重新登录 {name}", "oauth.finishing": "正在完成登录…", "oauth.finishingBody": "浏览器登录已完成,GSwitch 正在保存账户。", "oauth.pendingApplyCurrent": "登录已保存。关闭 Codex 后,在卡片上点击“应用”。", "oauth.pendingApplyOther": "登录已保存。需要使用时切换到此账户。", "oauth.cleanupWarning": "登录已保存,但临时登录文件未能清理。请重启 GSwitch。", - "oauth.targetEmail": "账户:{email}", - "oauth.targetWorkspace": "工作区:{workspace}", + "oauth.targetEmail": "账户:", "oauth.retrySave": "重试保存", "oauth.openFailed": "浏览器未能打开。请复制登录链接并粘贴到浏览器。", "oauth.failureNotCompleted": "浏览器登录未完成,请重新打开链接。", @@ -606,7 +602,9 @@ const zhCN: Record = { "oauth.failureSave": "登录已验证,但 GSwitch 无法保存账户。若出现恢复提示,请按提示处理。", "oauth.failureUnavailable": "GSwitch 无法确认登录结果。请先检查该账户状态,再决定是否重试。", "oauth.link": "登录链接", - "oauth.copyLink": "复制登录链接", + "oauth.copyLink": "复制链接", + "oauth.copied": "已复制", + "oauth.copyFailed": "复制失败", "oauth.cancel": "取消登录", "oauth.openBrowser": "打开浏览器", "oauth.added": "已添加 {name}", diff --git a/src/styles.css b/src/styles.css index 32dd6d7..77a78f9 100644 --- a/src/styles.css +++ b/src/styles.css @@ -1393,11 +1393,42 @@ summary:focus-visible { .oauth-target { display: flex; align-items: center; - flex-wrap: wrap; - gap: 7px 14px; + justify-content: space-between; + gap: 14px; margin-bottom: 18px; color: var(--muted); - font-size: 12px; + font-size: 14px; +} + +.oauth-target > span { + min-width: 0; + overflow-wrap: anywhere; +} + +.oauth-target strong { + color: var(--text); + font-weight: 560; +} + +.copy-button { + flex: 0 0 auto; + min-width: 118px; + border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); + color: var(--accent); +} + +.copy-button:hover:not(:disabled) { + border-color: color-mix(in srgb, var(--accent) 65%, var(--border)); +} + +.copy-button[data-copy="copied"]:not(:disabled) { + border-color: color-mix(in srgb, var(--success) 45%, var(--border)); + color: var(--success); +} + +.copy-button[data-copy="failed"]:not(:disabled) { + border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); + color: var(--danger); } .oauth-hero > svg { @@ -1455,16 +1486,11 @@ textarea { .copy-field input { min-width: 0; + min-height: 35px; color: var(--muted); font-size: 11.5px; } -.copy-field .icon-button { - width: 38px; - height: 38px; - min-height: 38px; -} - .modal-actions { justify-content: flex-end; gap: 8px;