Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
48 changes: 27 additions & 21 deletions src/AccountIntake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<number | undefined>(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 (
<button aria-live="polite" className="button button-secondary copy-button" data-copy={state} onClick={() => void copy()} type="button">
<Icon size={16} />{state === "idle" ? label : t(state === "copied" ? "oauth.copied" : "oauth.copyFailed")}
</button>
);
}

function fileFilters(t: Translator) { return [{ name: t("file.accountExports"), extensions: ["json"] }]; }
function migrationSourceLabel(candidate: MigrationCandidate, t: Translator) {
return candidate.source === "official_codex"
Expand Down Expand Up @@ -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 ?? "";
Expand Down Expand Up @@ -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<typeof useAccountIntake>; busy: string | null; onCopyEmail: (account: AccountView) => Promise<void>; t: Translator;
export function AccountIntakeDialog({ flow, busy, t }: {
flow: ReturnType<typeof useAccountIntake>; 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 (
<Modal dismissible={!runningAny("import", "migration-scan", "migration-import", "oauth", "oauth-cancel", "oauth-retry", "import-json", "import-key")} onClose={closeAddDialog} t={t} title={t(oauthTarget ? "oauth.reauthenticateTitle" : "add.title", oauthTarget ? { name: accountPrimaryName(oauthTarget) } : undefined)} wide>
Expand Down Expand Up @@ -517,9 +524,8 @@ export function AccountIntakeDialog({ flow, busy, onCopyEmail, t }: {
{addMethod === "oauth" && oauth ? (
<div className="oauth-flow">
{oauthTarget ? <div className="oauth-target">
<span>{t("oauth.targetEmail", { email: oauthTarget.email || accountPrimaryName(oauthTarget) })}</span>
{oauthTarget.workspace_name ? <span>{t("oauth.targetWorkspace", { workspace: oauthTarget.workspace_name })}</span> : null}
{oauthTarget.email ? <button className="text-button" onClick={() => void copyAccountEmail(oauthTarget)} type="button">{t("account.copyEmail")}</button> : null}
<span>{t("oauth.targetEmail")}<strong>{oauthTarget.email || accountPrimaryName(oauthTarget)}</strong></span>
{oauthTarget.email ? <CopyButton label={t("account.copyEmail")} t={t} text={oauthTarget.email} /> : null}
</div> : null}
{oauth.status.status === "pending" ? (
<>
Expand All @@ -531,7 +537,7 @@ export function AccountIntakeDialog({ flow, busy, onCopyEmail, t }: {
<label className="field-label" htmlFor="oauth-link">{t("oauth.link")}</label>
<div className="copy-field">
<input id="oauth-link" readOnly value={oauth.auth_url} />
<button aria-label={t("oauth.copyLink")} className="icon-button" onClick={() => void copyOAuthUrl()} type="button"><Copy size={17} /></button>
<CopyButton label={t("oauth.copyLink")} t={t} text={oauth.auth_url} />
</div>
<div className="modal-actions">
<button className="button button-secondary" onClick={() => void cancelOAuth()} type="button">{t("oauth.cancel")}</button>
Expand Down
38 changes: 36 additions & 2 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<App />);
Expand All @@ -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(<App />);
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 () => {
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ export default function App() {
</section>
</div>

{dialog === "add" ? <AccountIntakeDialog flow={intake} busy={busy} onCopyEmail={copyAccountEmail} t={t} /> : null}
{dialog === "add" ? <AccountIntakeDialog flow={intake} busy={busy} t={t} /> : null}

{dialog === "export" ? (
<Modal
Expand Down
22 changes: 10 additions & 12 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ const en = {
"notice.migration": "Import results — added: {imported}; already present or duplicate: {duplicates}; unsupported or failed: {skipped}.",
"notice.exported": "Export complete: {count} selected. Keep this unencrypted file private.",
"notice.oauthReady": "Your sign-in link is ready. Copy it and open it in your preferred browser.",
"notice.oauthCopied": "Sign-in link copied.",
"notice.copyManually": "Select the sign-in link below and copy it manually.",
"notice.pasteAuth": "Paste a complete auth JSON document before adding it.",
"notice.enterApiKey": "Enter an API key before adding it.",
"notice.importedAccount": "{name} was imported safely.",
Expand Down Expand Up @@ -237,15 +235,14 @@ const en = {
"oauth.finishTitle": "Finish sign-in in your browser",
"oauth.finishBody": "GSwitch adds the verified account when Codex confirms the sign-in.",
"oauth.reauthenticateTitle": "Sign in again · {name}",
"oauth.reauthenticateBody": "Sign in to the same email and workspace. GSwitch will update only this saved account.",
"oauth.reauthenticateBody": "Sign in with the same email. GSwitch will update only this saved account.",
"oauth.reauthenticated": "{name} was signed in again",
"oauth.finishing": "Finishing sign-in…",
"oauth.finishingBody": "Your browser sign-in is complete. GSwitch is saving this account.",
"oauth.pendingApplyCurrent": "Sign-in saved. Close Codex, then choose Apply on this card.",
"oauth.pendingApplyOther": "Sign-in saved. Switch to this account when you need it.",
"oauth.cleanupWarning": "Sign-in was saved. GSwitch could not remove a temporary login file; please restart GSwitch.",
"oauth.targetEmail": "Account: {email}",
"oauth.targetWorkspace": "Workspace: {workspace}",
"oauth.targetEmail": "Account: ",
"oauth.retrySave": "Retry saving",
"oauth.openFailed": "The browser did not open. Copy the sign-in link and paste it into your browser.",
"oauth.failureNotCompleted": "Browser sign-in did not finish. Try the link again.",
Expand All @@ -258,7 +255,9 @@ const en = {
"oauth.failureSave": "Sign-in was verified, but GSwitch could not save the account. Follow any recovery prompt.",
"oauth.failureUnavailable": "GSwitch could not confirm the sign-in result. Check this account's status before trying again.",
"oauth.link": "Sign-in link",
"oauth.copyLink": "Copy sign-in link",
"oauth.copyLink": "Copy link",
"oauth.copied": "Copied",
"oauth.copyFailed": "Copy failed",
"oauth.cancel": "Cancel sign-in",
"oauth.openBrowser": "Open browser",
"oauth.added": "{name} was added",
Expand Down Expand Up @@ -491,8 +490,6 @@ const zhCN: Record<keyof typeof en, string> = {
"notice.migration": "已导入 {imported} 个账户;{duplicates} 个已存在或重复;{skipped} 个不受支持或失败。",
"notice.exported": "已导出 {count} 个所选账户。请妥善保管未加密文件。",
"notice.oauthReady": "登录链接已就绪。请复制后在你常用的浏览器中打开。",
"notice.oauthCopied": "登录链接已复制。",
"notice.copyManually": "请选中下方登录链接并手动复制。",
"notice.pasteAuth": "请先粘贴完整的 auth JSON 文档。",
"notice.enterApiKey": "请先输入 API 密钥。",
"notice.importedAccount": "已安全导入 {name}。",
Expand Down Expand Up @@ -585,15 +582,14 @@ const zhCN: Record<keyof typeof en, string> = {
"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": "浏览器登录未完成,请重新打开链接。",
Expand All @@ -606,7 +602,9 @@ const zhCN: Record<keyof typeof en, string> = {
"oauth.failureSave": "登录已验证,但 GSwitch 无法保存账户。若出现恢复提示,请按提示处理。",
"oauth.failureUnavailable": "GSwitch 无法确认登录结果。请先检查该账户状态,再决定是否重试。",
"oauth.link": "登录链接",
"oauth.copyLink": "复制登录链接",
"oauth.copyLink": "复制链接",
"oauth.copied": "已复制",
"oauth.copyFailed": "复制失败",
"oauth.cancel": "取消登录",
"oauth.openBrowser": "打开浏览器",
"oauth.added": "已添加 {name}",
Expand Down
44 changes: 35 additions & 9 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Loading