Stop QR scanning after an attempt ends

The scan screen now keeps its workflow in a small model. When the user
cancels the host confirmation, closes the password prompt, or the attempt
fails, scanning stops until they tap Scan QR code again. Before, the code
still in front of the camera started a new attempt on the next frame.

A host confirmation answer is now tied to the request it answers, so a tap
on one sheet never answers a newer one. Relay hosts can no longer be added
through HostMutations without the confirmation, the add-host modal drops
the reset its per-open mount made redundant, and the fingerprint comment
says what the shortened form shows.
This commit is contained in:
Mohamed Boudra
2026-09-30 13:02:26 +02:00
parent 1f8ce0ee08
commit bddc9a5bd5
7 changed files with 322 additions and 84 deletions
+35 -7
View File
@@ -522,12 +522,19 @@ function answerHostConfirmations(
if (!pending) return;
requests.push(pending);
store.answerHostConfirmation(
pending.id,
typeof answer === "function" ? answer(pending, requests.length - 1) : answer,
);
});
return requests;
}
function requirePendingConfirmation(store: HostRuntimeStore): HostConfirmationRequest {
const pending = store.getPendingHostConfirmation();
if (!pending) throw new Error("Expected a pending host confirmation");
return pending;
}
function createPairingStore(
input: {
hostname?: string;
@@ -3696,12 +3703,14 @@ describe("HostRuntimeStore", () => {
expect(requests).toEqual([
...Array.from({ length: 3 }, () => ({
id: expect.any(Number),
serverId: "srv_offer",
keyFingerprint: "pkte stof fer",
relayEndpoint: "relay.paseo.sh:443",
kind: "newHost",
})),
{
id: expect.any(Number),
serverId: "srv_relay",
keyFingerprint: "AAAA",
relayEndpoint: "relay.example:443",
@@ -3832,13 +3841,36 @@ describe("HostRuntimeStore", () => {
expect(store.getPendingHostConfirmation()).toMatchObject({ serverId: "srv_second" }),
);
store.answerHostConfirmation(true);
store.answerHostConfirmation(requirePendingConfirmation(store).id, true);
await expect(second).resolves.toEqual({ status: "connected", serverId: "srv_second" });
expect(store.getPendingHostConfirmation()).toBeNull();
expect(store.getHosts().map((host) => host.serverId)).toEqual(["srv_second"]);
store.syncHosts([]);
});
it("ignores an answer for a host confirmation that a newer one replaced", async () => {
const store = createPairingStore();
const first = store.importConnectionLink(encodeOfferUrl(makeOffer()), "openProject");
await vi.waitFor(() =>
expect(store.getPendingHostConfirmation()).toMatchObject({ serverId: "srv_offer" }),
);
const firstRequest = requirePendingConfirmation(store);
const second = store.importConnectionLink(
encodeOfferUrl(makeOffer({ serverId: "srv_second" })),
"openProject",
);
await expect(first).resolves.toEqual({ status: "cancelled" });
// Connect tapped on the first sheet as the second link arrives.
store.answerHostConfirmation(firstRequest.id, true);
const secondRequest = requirePendingConfirmation(store);
expect(secondRequest.serverId).toBe("srv_second");
store.answerHostConfirmation(secondRequest.id, false);
await expect(second).resolves.toEqual({ status: "cancelled" });
expect(store.getHosts()).toEqual([]);
});
it("waits for saved hosts to load before deciding whether a pairing link asks", async () => {
const savedHost = makeHost({
serverId: "srv_offer",
@@ -3891,12 +3923,8 @@ describe("HostRuntimeStore", () => {
const store = createPairingStore({ hostname: "mbp" });
answerHostConfirmations(store, true);
await store.upsertRelayConnection({
serverId: "srv_offer",
relayEndpoint: "relay.paseo.sh:443",
daemonPublicKeyB64: "pk_test_offer",
label: "Custom name",
});
await store.beginLinkPairing().submit(encodeOfferUrl(makeOffer()));
await store.renameHost("srv_offer", "Custom name");
await store.beginLinkPairing().submit(encodeOfferUrl(makeOffer()));