Phone: the computer list waits for a brain that is restarting and goes in by itself (it sat on 離線 until tapped)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
60f4fa7411
commit
ad0234d0ce
|
|
@ -379,8 +379,13 @@ function signOut(expired) {
|
||||||
}
|
}
|
||||||
$("b-out1").onclick = () => signOut();
|
$("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() {
|
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 || [];
|
const all = me.hosts || [];
|
||||||
// A computer that shows another one's bots (大腦) leads to that brain.
|
// A computer that shows another one's bots (大腦) leads to that brain.
|
||||||
const byId = Object.fromEntries(all.map((h) => [h.id, h]));
|
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(); }
|
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("、")) + " 也用這個大腦" : ""; };
|
const note = (h) => { const n = sharers(h.id); return n.length ? " · " + esc(n.join("、")) + " 也用這個大腦" : ""; };
|
||||||
$("hosts").innerHTML = hosts.length ? hosts.map((h) => `<div class="row" data-h="${esc(h.id)}"><div class="av" style="background:${h.online ? "var(--ok)" : "#888"}">${esc((h.name || "?")[0])}</div><div class="mid"><div class="name">${esc(h.name)}</div><div class="last">${h.online ? "在線上" : "離線(" + esc(h.last_seen_text || "很久沒連線") + ")"}${note(h)}</div></div></div>`).join("")
|
const wanted = (S.host && byId[target(S.host)]) || (all.find((h) => sharers(h.id).length)) || hosts[0];
|
||||||
: `<div class="empty">這個帳號還沒有連上任何 AnyBot。<br>在電腦上打開 AnyBot › 設定 › 手機與帳號,登入同一個帳號。</div>`;
|
const waiting = hosts.length && !live.length && wanted
|
||||||
document.querySelectorAll("#hosts .row").forEach((r) => r.onclick = () => { S.host = r.dataset.h; localStorage.setItem("anybot.host", S.host); start(); });
|
? `<div class="empty">「${esc(wanted.name)}」暫時沒有連線(可能正在重新啟動,或那台電腦睡著了)。<br>連上後會自動進入,不用重新整理。</div>` : "";
|
||||||
|
$("hosts").innerHTML = waiting + (hosts.length ? hosts.map((h) => `<div class="row" data-h="${esc(h.id)}"><div class="av" style="background:${h.online ? "var(--ok)" : "#888"}">${esc((h.name || "?")[0])}</div><div class="mid"><div class="name">${esc(h.name)}</div><div class="last">${h.online ? "在線上" : "離線(" + esc(h.last_seen_text || "很久沒連線") + ")"}${note(h)}</div></div></div>`).join("")
|
||||||
|
: `<div class="empty">這個帳號還沒有連上任何 AnyBot。<br>在電腦上打開 AnyBot › 設定 › 手機與帳號,登入同一個帳號。</div>`);
|
||||||
|
document.querySelectorAll("#hosts .row").forEach((r) => r.onclick = () => { clearTimeout(hostRetry); S.host = r.dataset.h; localStorage.setItem("anybot.host", S.host); start(); });
|
||||||
show("hosts");
|
show("hosts");
|
||||||
|
if (S.token && !live.length) hostRetry = setTimeout(pickHost, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- live state ----------
|
// ---------- live state ----------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue