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 ----------