fix(mobile): pairing says what went wrong, and leaves the code alone

The code field offered word suggestions over the keyboard; it is a code.
A wrong, expired or unreachable code is explained with what to do next
rather than the gateway's lower-case reason.
This commit is contained in:
l0ng-ai
2026-10-03 20:27:44 +08:00
parent 89f3b477d9
commit 9220e8824a
+11 -1
View File
@@ -937,6 +937,9 @@ function pairScreen(linked?: string) {
spellcheck: false,
ariaLabel: "Pairing code",
});
// A code, not words: no suggestions over the keyboard, no "fixing" it.
code.setAttribute("autocorrect", "off");
code.setAttribute("autocomplete", "off");
const name = h("input", {
class: "field-input",
value: guessDeviceName(),
@@ -1002,7 +1005,14 @@ function pairScreen(linked?: string) {
const host = await api.pair(code.value.trim(), name.value.trim() || "phone");
hostScreen(host, "push");
} catch (e) {
error.textContent = errorText(e);
const text = errorText(e);
error.textContent = /not a tty7 pairing code/i.test(text)
? "That isn't a pairing code. On your computer, open Settings → Mobile and click Show code."
: /used up or expired/i.test(text)
? "That code has expired or was already used. Make a new one with New code on your computer."
: /^could not reach /i.test(text)
? `${why(text, text.replace(/^could not reach ([^:]+):.*$/i, "$1"))} Check that tty7 is running there with phone access on.`
: sentence(text);
submit.classList.remove("busy");
submit.textContent = "Pair";
submit.disabled = false;