Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Antigravity sign-in: Cancel waits for the start and holds every control; no Rename while signing in

laijsg1f79502183688
diff --git a/src/components/EngineAccounts.tsx b/src/components/EngineAccounts.tsx
index c093bafb78..9d846e59fd 100644
--- a/src/components/EngineAccounts.tsx
+++ b/src/components/EngineAccounts.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useId, useRef, useState, type ReactNode } from "react";
+import { useCallback, useEffect, useId, useRef, useState, type ReactNode } from "react";
import { Check, Loader2, MoreHorizontal, Plus } from "lucide-react";
import { api, useStore, type InstanceInfo } from "@/state/store";
import { useShowInstances } from "@/state/use-show-instances";
@@ -77,7 +77,7 @@ function summaryFor(group: AccountGroup, accounts: InstanceInfo[]): EngineCardSu
};
}
-function AccountMenu({ group, instance, onRename }: { group: AccountGroup; instance: InstanceInfo; onRename: () => void }) {
+function AccountMenu({ group, instance, signingIn, onRename }: { group: AccountGroup; instance: InstanceInfo; signingIn: boolean; onRename: () => void }) {
const { state } = useStore();
const showInstances = useShowInstances();
const [open, setOpen] = useState(false);
@@ -133,7 +133,7 @@ function AccountMenu({ group, instance, onRename }: { group: AccountGroup; insta
</button>
{open && (
<div role="menu" className={cn("absolute right-0 top-full z-40 mt-1 w-[220px] overflow-hidden text-[13px]", MENU_SHEET)}>
- <button type="button" role="menuitem" className={cn(item, "text-ink")} onClick={() => { setOpen(false); onRename(); }}>{t("accounts.rename")}</button>
+ <button type="button" role="menuitem" disabled={signingIn} className={cn(item, "text-ink")} onClick={() => { setOpen(false); onRename(); }}>{t("accounts.rename")}</button>
{canSignOut && <button type="button" role="menuitem" className={cn(item, "text-ink")} onClick={() => { setOpen(false); setConfirm("signOut"); }}>{t("accounts.signOut")}</button>}
{canHide && <button type="button" role="menuitem" disabled={usedBy > 0} title={t("engines.hideHint")} className={cn(item, "text-ink")} onClick={() => { setOpen(false); void run("hide"); }}>{t("engines.hide")}</button>}
{(canRemove || canHide) && usedBy > 0 && <p className="px-3 pb-1 pt-0.5 text-[11px] leading-snug text-ink-secondary">{t("accounts.inUse", { count: String(usedBy) })}</p>}
@@ -209,7 +209,13 @@ function AccountRow({ group, instance, several, signingIn, onSignIn, onSignInDon
}) {
const [renaming, setRenaming] = useState(false);
const signInButton = useRef<HTMLButtonElement>(null);
- const signInPanel = useRef<HTMLDivElement>(null);
+ const signInPanel = useRef<HTMLDivElement | null>(null);
+ const focusWasInPanel = useRef(false);
+ const panelRef = useCallback((node: HTMLDivElement | null) => {
+ signInPanel.current = node;
+ if (!node) return;
+ return () => { focusWasInPanel.current = node.contains(document.activeElement); };
+ }, []);
const wasSigningIn = useRef(false);
const state = accountState(instance);
const account = instance.snapshot.account;
@@ -228,7 +234,7 @@ function AccountRow({ group, instance, several, signingIn, onSignIn, onSignInDon
useEffect(() => {
const opened = signingIn && !wasSigningIn.current, closed = !signingIn && wasSigningIn.current;
wasSigningIn.current = signingIn;
- if (closed && document.activeElement === document.body) signInButton.current?.focus();
+ if (closed && focusWasInPanel.current) signInButton.current?.focus();
if (opened) requestAnimationFrame(() => signInPanel.current?.querySelector<HTMLButtonElement>("button:not(:disabled)")?.focus());
}, [signingIn]);
@@ -251,13 +257,13 @@ function AccountRow({ group, instance, several, signingIn, onSignIn, onSignInDon
{t("accounts.signIn")}
</button>
)}
- <AccountMenu group={group} instance={instance} onRename={() => setRenaming(true)} />
+ <AccountMenu group={group} instance={instance} signingIn={signingIn} onRename={() => setRenaming(true)} />
</>
)}
</div>
{setsUp && <div data-account-setup={instance.instanceId} className="pl-9"><EngineSetup instance={instance} unframed /></div>}
{signingIn && !setsUp && (
- <div ref={signInPanel} className="pl-9">
+ <div ref={panelRef} className="pl-9">
{group === "claude"
? <>
<ClaudeSignIn instanceId={instance.instanceId} autoStart onDone={onSignInDone} />
diff --git a/src/components/EngineSetup.tsx b/src/components/EngineSetup.tsx
index c0cfec2837..2127a938c0 100644
--- a/src/components/EngineSetup.tsx
+++ b/src/components/EngineSetup.tsx
@@ -289,6 +289,11 @@ export function AntigravitySignIn({ instance, onDone }: { instance: InstanceInfo
return instance.install?.managed ? <ManagedEngineSetup instance={instance} signInOnly autoStart onDone={onDone} /> : <EngineSetup instance={instance} unframed />;
}
+type GoogleStart = { auth: { phase: string; flowId?: string; authorizationUrl?: string; kind?: string } };
+type GoogleFlow = { flowId: string; authorizationUrl: string; pastedCode: boolean };
+const googleFlow = (auth: GoogleStart["auth"]): GoogleFlow | null =>
+ auth.flowId && auth.authorizationUrl ? { flowId: auth.flowId, authorizationUrl: auth.authorizationUrl, pastedCode: auth.kind === "pasted-code" } : null;
+
function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }: {
instance: InstanceInfo;
signInOnly: boolean;
@@ -298,9 +303,10 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
}) {
const { state, refreshInstances, refreshModels } = useStore();
const signInStarted = useSignInStarted(instance.instanceId);
- const [busy, setBusy] = useState<"install" | "signin" | "complete" | "check" | "cancel" | null>(null);
+ const [busy, setBusy] = useState<"install" | "signin" | "complete" | "check" | null>(null);
+ const [cancelling, setCancelling] = useState(false);
const [error, setError] = useState<string | null>(null);
- const [flow, setFlow] = useState<{ flowId: string; authorizationUrl: string; pastedCode: boolean } | null>(null);
+ const [flow, setFlow] = useState<GoogleFlow | null>(null);
const [callbackUrl, setCallbackUrl] = useState("");
const managed = instance.install!.managed!;
const done = useRef(onDone);
@@ -374,37 +380,37 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
void refreshModels(instance.instanceId).catch(() => {});
};
- const cancelled = useRef(false);
+ const starting = useRef<Promise<GoogleStart> | null>(null);
+ const cancelledStart = useRef<Promise<GoogleStart> | null>(null);
const cancelFlow = (id: string) => api(`/api/instances/${encodeURIComponent(instance.instanceId)}/auth/cancel`, { method: "POST", body: JSON.stringify({ flowId: id }) });
const cancel = async () => {
- cancelled.current = true;
- if (flow) {
- setBusy("cancel");
- setError(null);
- try {
- await cancelFlow(flow.flowId);
- } catch (cause) {
- cancelled.current = false;
- setBusy(null);
- setError(cause instanceof Error ? cause.message : String(cause));
- return;
- }
+ setCancelling(true);
+ setError(null);
+ cancelledStart.current = starting.current;
+ const started = flow ?? await cancelledStart.current?.then(({ auth }) => googleFlow(auth), () => null) ?? null;
+ try {
+ if (started) await cancelFlow(started.flowId);
+ } catch (cause) {
+ setFlow(started);
+ setCancelling(false);
+ setError(cause instanceof Error ? cause.message : String(cause));
+ return;
}
- onDone?.();
+ done.current?.();
};
const signIn = () => run("signin", async () => {
if (flow) return openLink(flow.authorizationUrl);
signInStarted();
- const { auth } = await api(`/api/instances/${encodeURIComponent(instance.instanceId)}/auth/start`, { method: "POST" });
- if (cancelled.current) {
- if (auth.flowId) await cancelFlow(auth.flowId).catch(() => {});
- return;
- }
+ const start: Promise<GoogleStart> = api(`/api/instances/${encodeURIComponent(instance.instanceId)}/auth/start`, { method: "POST" });
+ starting.current = start;
+ const { auth } = await start.finally(() => { starting.current = null; });
+ if (cancelledStart.current === start) return;
if (auth.phase === "succeeded") return signedIn();
- if (!auth.flowId || !auth.authorizationUrl) throw new Error(t("engineSetup.googleNoLink"));
- setFlow({ flowId: auth.flowId, authorizationUrl: auth.authorizationUrl, pastedCode: auth.kind === "pasted-code" });
- await openLink(auth.authorizationUrl);
+ const started = googleFlow(auth);
+ if (!started) throw new Error(t("engineSetup.googleNoLink"));
+ setFlow(started);
+ await openLink(started.authorizationUrl);
});
const complete = () => run("complete", async () => {
@@ -455,12 +461,13 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
}
const cloudHome = state.config?.cloudHome === true;
+ const waiting = busy !== null || cancelling;
return (
<div className="mt-3 space-y-2">
{cloudHome && !flow?.pastedCode && <p className="text-[12px] leading-relaxed text-ink-secondary">{t("engineSetup.cloudPasteHint")}</p>}
<button
type="button"
- disabled={busy !== null}
+ disabled={waiting}
onClick={() => void signIn()}
className="flex w-full items-center justify-center gap-2 rounded-lg bg-accent px-3 py-2 text-[13px] font-semibold text-white hover:brightness-110 disabled:cursor-wait disabled:opacity-70"
>
@@ -478,15 +485,16 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
<input
value={callbackUrl}
onChange={(event) => setCallbackUrl(event.target.value)}
+ disabled={cancelling}
aria-label={t("engineSetup.pasteCodeLabel")}
placeholder={t("engineSetup.pasteCodePlaceholder")}
autoComplete="off"
spellCheck={false}
- className="mt-2 w-full rounded-md border border-hairline bg-inset px-2 py-1.5 text-[11px] text-ink outline-none focus:border-accent"
+ className="mt-2 w-full rounded-md border border-hairline bg-inset px-2 py-1.5 text-[11px] text-ink outline-none focus:border-accent disabled:opacity-50"
/>
<button
type="button"
- disabled={!callbackUrl.trim() || busy !== null}
+ disabled={!callbackUrl.trim() || waiting}
onClick={() => void complete()}
className="mt-2 w-full rounded-md bg-control px-2 py-1.5 font-medium text-ink disabled:opacity-50"
>
@@ -496,7 +504,7 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
)}
{flow && !flow.pastedCode && (
<>
- <button type="button" disabled={busy !== null} onClick={() => void check()} className="w-full rounded-lg bg-control px-3 py-2 text-[12px] font-semibold text-ink hover:bg-raised-hover disabled:opacity-50">
+ <button type="button" disabled={waiting} onClick={() => void check()} className="w-full rounded-lg bg-control px-3 py-2 text-[12px] font-semibold text-ink hover:bg-raised-hover disabled:opacity-50">
{busy === "check" ? t("common.checking") : t("engineSetup.finishedSignIn")}
</button>
<div data-redirect-paste className="rounded-lg border border-hairline/50 bg-app px-2.5 py-2 text-[12px] text-ink-secondary">
@@ -505,13 +513,14 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
<input
value={callbackUrl}
onChange={(event) => setCallbackUrl(event.target.value)}
+ disabled={cancelling}
aria-label={t("engineSetup.otherComputerUrl")}
placeholder="http://127.0.0.1:…/?code=…"
- className="mt-2 w-full rounded-md border border-hairline bg-inset px-2 py-1.5 text-[11px] text-ink outline-none focus:border-accent"
+ className="mt-2 w-full rounded-md border border-hairline bg-inset px-2 py-1.5 text-[11px] text-ink outline-none focus:border-accent disabled:opacity-50"
/>
<button
type="button"
- disabled={!callbackUrl.trim() || busy !== null}
+ disabled={!callbackUrl.trim() || waiting}
onClick={() => void complete()}
className="mt-2 w-full rounded-md bg-control px-2 py-1.5 font-medium text-ink disabled:opacity-50"
>
@@ -521,7 +530,9 @@ function ManagedEngineSetup({ instance, signInOnly, autoStart = false, onDone }:
</>
)}
{error && <p role="alert" className="text-[12px] text-danger">{error}</p>}
- {onDone && <button type="button" disabled={busy === "complete" || busy === "cancel"} onClick={() => void cancel()} className="rounded-lg disabled:opacity-50 px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control">{t("common.cancel")}</button>}
+ {onDone && <button type="button" aria-disabled={busy === "complete" || cancelling || undefined} aria-busy={cancelling || undefined}
+ onClick={busy === "complete" || cancelling ? undefined : () => void cancel()}
+ className="rounded-lg px-2.5 py-1.5 text-[12px] text-ink-secondary hover:bg-control aria-disabled:opacity-50">{t("common.cancel")}</button>}
</div>
);
}
diff --git a/src/components/EnginesSettings.antigravity.dom.test.ts b/src/components/EnginesSettings.antigravity.dom.test.ts
index ecd41fd737..f9dced5ac9 100644
--- a/src/components/EnginesSettings.antigravity.dom.test.ts
+++ b/src/components/EnginesSettings.antigravity.dom.test.ts
@@ -11,6 +11,7 @@ const fixture = vi.hoisted(() => ({
startGate: null as Promise<void> | null,
completeGate: null as Promise<void> | null,
cancelGate: null as Promise<void> | null,
+ refreshGate: null as Promise<void> | null,
opened: [] as string[],
cancelFails: false,
modelsFail: false,
@@ -20,7 +21,7 @@ vi.mock("@/state/store", async (original) => ({
useStore: () => ({
state: fixture.state,
dispatch: (action: { type: string; instances?: InstanceInfo[] }) => { if (action.type === "instances" && action.instances) fixture.state = { ...fixture.state, instances: action.instances }; },
- refreshInstances: async () => {}, refreshModels: async () => { if (fixture.modelsFail) throw new Error("Could not read the models."); },
+ refreshInstances: async () => { if (fixture.refreshGate) await fixture.refreshGate; }, refreshModels: async () => { if (fixture.modelsFail) throw new Error("Could not read the models."); },
}),
api: async (path: string, init?: { method?: string; body?: string }) => {
if (init?.method) fixture.calls.push({ path, method: init.method, body: init.body ? JSON.parse(init.body) : undefined });
@@ -64,6 +65,7 @@ beforeEach(() => {
fixture.startGate = null;
fixture.completeGate = null;
fixture.cancelGate = null;
+ fixture.refreshGate = null;
fixture.opened = [];
fixture.cancelFails = false;
fixture.modelsFail = false;
@@ -82,6 +84,9 @@ const buttons = (scope: ParentNode, label: string) => [...scope.querySelectorAll
const click = async (target: Element | undefined) => { expect(target).toBeTruthy(); await act(async () => { (target as HTMLElement).click(); }); };
const row = (instanceId: string) => container.querySelector(`[data-account="${instanceId}"]`)!;
const rows = () => [...container.querySelectorAll('[data-accounts="antigravity"] [data-account]')].map((item) => item.getAttribute("data-account"));
+const usable = (scope: ParentNode) => [...scope.querySelectorAll<HTMLButtonElement | HTMLInputElement>("button, input")]
+ .filter((item) => !item.disabled && item.getAttribute("aria-disabled") !== "true").map((item) => item.textContent || item.getAttribute("aria-label"));
+const gate = () => { let open!: () => void; const promise = new Promise<void>((resolve) => { open = resolve; }); return { promise, open: () => act(async () => { open(); await promise; }) }; };
const startCalls = () => fixture.calls.filter((call) => call.path.endsWith("/auth/start")).map((call) => call.path);
async function pasteRedirect(instanceId: string) {
const input = row(instanceId).querySelector<HTMLInputElement>("[data-redirect-paste] input")!;
@@ -158,16 +163,61 @@ describe("Google Gemini (Antigravity) accounts share one card", () => {
expect(buttons(row("antigravity"), "Sign in")).toHaveLength(1);
});
- it("opens no Google page for a sign-in cancelled before it started, and ends that flow", async () => {
+ it("opens no Google page for a sign-in cancelled before it started, and keeps it until that flow is ended", async () => {
fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];
- let start!: () => void;
- fixture.startGate = new Promise((resolve) => { start = resolve; });
+ const start = gate();
+ fixture.startGate = start.promise;
await render();
await click(buttons(row("antigravity"), "Sign in")[0]);
await click(buttons(row("antigravity"), "Cancel")[0]);
- await act(async () => { start(); await fixture.startGate; });
+ expect(row("antigravity").querySelector("[data-account-sign-in]")).toBeTruthy();
+ expect(usable(row("antigravity").querySelector("[data-account-sign-in]")!)).toEqual([]);
+ await start.open();
expect(fixture.opened).toEqual([]);
expect(fixture.calls.at(-1)).toEqual({ path: "/api/instances/antigravity/auth/cancel", method: "POST", body: { flowId: "flow-antigravity" } });
+ expect(row("antigravity").querySelector("[data-account-sign-in]")).toBeNull();
+ });
+
+ it("keeps a sign-in cancelled before it started open with its Google link when the server refuses the cancel", async () => {
+ fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];
+ fixture.cancelFails = true;
+ const start = gate();
+ fixture.startGate = start.promise;
+ await render();
+ await click(buttons(row("antigravity"), "Sign in")[0]);
+ await click(buttons(row("antigravity"), "Cancel")[0]);
+ await start.open();
+ const panel = row("antigravity").querySelector("[data-account-sign-in]")!;
+ expect(panel.textContent).toContain("The sign-in is finishing. Try again in a moment.");
+ expect(usable(panel)).toContain("Open Google sign-in again");
+ expect(usable(panel)).toContain("Cancel");
+ expect(fixture.opened).toEqual([]);
+ });
+
+ it("keeps the sign-in's controls held until the cancel answers, even when a status check ends first", async () => {
+ fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];
+ await render();
+ await click(buttons(row("antigravity"), "Sign in")[0]);
+ const refresh = gate(), cancel = gate();
+ fixture.refreshGate = refresh.promise;
+ fixture.cancelGate = cancel.promise;
+ await click(buttons(row("antigravity"), "I finished signing in")[0]);
+ await click(buttons(row("antigravity"), "Cancel")[0]);
+ await refresh.open();
+ expect(usable(row("antigravity").querySelector("[data-account-sign-in]")!)).toEqual([]);
+ await cancel.open();
+ expect(row("antigravity").querySelector("[data-account-sign-in]")).toBeNull();
+ });
+
+ it("offers no Rename while the account is signing in", async () => {
+ fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];
+ await render();
+ await click(container.querySelector('[aria-label="Options for Personal"]') ?? undefined);
+ expect(row("antigravity").querySelector<HTMLButtonElement>('[role="menuitem"]')?.disabled).toBe(false);
+ await click(container.querySelector('[aria-label="Options for Personal"]') ?? undefined);
+ await click(buttons(row("antigravity"), "Sign in")[0]);
+ await click(container.querySelector('[aria-label="Options for Personal"]') ?? undefined);
+ expect(buttons(row("antigravity"), "Rename")[0]?.disabled).toBe(true);
});
it("closes the panel once the pasted redirect signs the account in, before its status is read again", async () => {
@@ -186,10 +236,29 @@ describe("Google Gemini (Antigravity) accounts share one card", () => {
await click(buttons(row("antigravity"), "Sign in")[0]);
await act(async () => { await new Promise<void>((resolve) => requestAnimationFrame(() => resolve())); });
expect(row("antigravity").querySelector("[data-account-sign-in]")?.contains(document.activeElement)).toBe(true);
+ const cancel = gate();
+ fixture.cancelGate = cancel.promise;
+ buttons(row("antigravity"), "Cancel")[0]!.focus();
await click(buttons(row("antigravity"), "Cancel")[0]);
+ expect(document.activeElement).toBe(buttons(row("antigravity"), "Cancel")[0]);
+ await cancel.open();
expect(document.activeElement).toBe(buttons(row("antigravity"), "Sign in")[0]);
});
+ it("leaves focus on the page when it left the sign-in before the cancel answered", async () => {
+ fixture.state.instances = [google("antigravity", "Personal", { authenticated: false })];
+ await render();
+ await click(buttons(row("antigravity"), "Sign in")[0]);
+ await nextFrame();
+ const cancel = gate();
+ fixture.cancelGate = cancel.promise;
+ await click(buttons(row("antigravity"), "Cancel")[0]);
+ (document.activeElement as HTMLElement).blur();
+ await cancel.open();
+ expect(row("antigravity").querySelector("[data-account-sign-in]")).toBeNull();
+ expect(document.activeElement).toBe(document.body);
+ });
+
it("leaves focus where it is when another account's sign-in finishes", async () => {
fixture.state.instances = [google("antigravity", "Personal", { authenticated: false }), google("antigravity-work", "Work", { authenticated: false })];
await render();
@@ -228,7 +297,7 @@ describe("Google Gemini (Antigravity) accounts share one card", () => {
await pasteRedirect("antigravity");
await click(buttons(row("antigravity"), "Cancel")[0]);
const panel = row("antigravity").querySelector("[data-account-sign-in]")!;
- expect([...panel.querySelectorAll("button")].filter((button) => !button.disabled).map((button) => button.textContent)).toEqual([]);
+ expect(usable(panel)).toEqual([]);
await act(async () => { cancelled(); await fixture.cancelGate; });
expect(row("antigravity").querySelector("[data-account-sign-in]")).toBeNull();
});
@@ -250,8 +319,8 @@ describe("Google Gemini (Antigravity) accounts share one card", () => {
await click(buttons(row("antigravity"), "Sign in")[0]);
await pasteRedirect("antigravity");
await click(buttons(row("antigravity"), "Send redirect")[0]);
- expect(buttons(row("antigravity"), "Cancel")[0]?.disabled).toBe(true);
- expect(buttons(row("antigravity"), "I finished signing in")[0]?.disabled).toBe(true);
+ expect(usable(row("antigravity"))).not.toContain("Cancel");
+ expect(usable(row("antigravity"))).not.toContain("I finished signing in");
await act(async () => { send(); await fixture.completeGate; });
});