From ad0234d0ceebddd1adf278371fcfbba3f48953a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Thu, 5 Nov 2026 19:07:43 +0800 Subject: [PATCH] =?UTF-8?q?Phone:=20the=20computer=20list=20waits=20for=20?= =?UTF-8?q?a=20brain=20that=20is=20restarting=20and=20goes=20in=20by=20its?= =?UTF-8?q?elf=20(it=20sat=20on=20=E9=9B=A2=E7=B7=9A=20until=20tapped)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- mobile/index.html | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mobile/index.html b/mobile/index.html index 5bcf3fa..8d70bde 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -379,8 +379,13 @@ function signOut(expired) { } $("b-out1").onclick = () => signOut(); +// The list waits for a brain that is restarting (or a computer that woke up): it looks again +// every few seconds and goes in by itself; it used to sit on 「離線」 until tapped. +let hostRetry = null; async function pickHost() { - const me = await api("relay/me"); + clearTimeout(hostRetry); + let me; + try { me = await api("relay/me"); } catch (e) { toast(e.message); if (S.token) hostRetry = setTimeout(pickHost, 3000); return; } const all = me.hosts || []; // A computer that shows another one's bots (大腦) leads to that brain. const byId = Object.fromEntries(all.map((h) => [h.id, h])); @@ -399,10 +404,14 @@ async function pickHost() { } if (live.length === 1) { S.host = live[0].id; localStorage.setItem("anybot.host", S.host); return start(); } const note = (h) => { const n = sharers(h.id); return n.length ? " · " + esc(n.join("、")) + " 也用這個大腦" : ""; }; - $("hosts").innerHTML = hosts.length ? hosts.map((h) => `
${esc((h.name || "?")[0])}
${esc(h.name)}
${h.online ? "在線上" : "離線(" + esc(h.last_seen_text || "很久沒連線") + ")"}${note(h)}
`).join("") - : `
這個帳號還沒有連上任何 AnyBot。
在電腦上打開 AnyBot › 設定 › 手機與帳號,登入同一個帳號。
`; - document.querySelectorAll("#hosts .row").forEach((r) => r.onclick = () => { S.host = r.dataset.h; localStorage.setItem("anybot.host", S.host); start(); }); + const wanted = (S.host && byId[target(S.host)]) || (all.find((h) => sharers(h.id).length)) || hosts[0]; + const waiting = hosts.length && !live.length && wanted + ? `
「${esc(wanted.name)}」暫時沒有連線(可能正在重新啟動,或那台電腦睡著了)。
連上後會自動進入,不用重新整理。
` : ""; + $("hosts").innerHTML = waiting + (hosts.length ? hosts.map((h) => `
${esc((h.name || "?")[0])}
${esc(h.name)}
${h.online ? "在線上" : "離線(" + esc(h.last_seen_text || "很久沒連線") + ")"}${note(h)}
`).join("") + : `
這個帳號還沒有連上任何 AnyBot。
在電腦上打開 AnyBot › 設定 › 手機與帳號,登入同一個帳號。
`); + document.querySelectorAll("#hosts .row").forEach((r) => r.onclick = () => { clearTimeout(hostRetry); S.host = r.dataset.h; localStorage.setItem("anybot.host", S.host); start(); }); show("hosts"); + if (S.token && !live.length) hostRetry = setTimeout(pickHost, 3000); } // ---------- live state ----------