From 35ac6834858a7d20a3f27ee27654919d54ade75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Thu, 19 Nov 2026 21:35:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=A3=E4=B8=8A=E5=89=8D=E5=81=9C?= =?UTF-8?q?=E5=9C=A8=E5=A4=96=E9=9D=A2=EF=BC=9B=E6=A1=8C=E9=9D=A2=E9=96=92?= =?UTF-8?q?=E7=BD=AE=E8=88=87=E7=AD=89=E5=BE=85=E6=99=82=E4=B8=8D=E6=BB=BF?= =?UTF-8?q?=E5=B9=80=E9=87=8D=E7=95=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 手機頁面 - 還沒連上、第一份狀態還沒到手之前,停在「正在連線…」,不先顯示登入表單或 Bot 清單 - 連上、狀態到手才進去,清單與要開的聊天已經填好 - 進去之後斷線仍留在裡面,照舊顯示「連線中斷」並重連 桌面(Intel 上發熱、耗電) - 工作中的臉、「正在…」閃光、串流文字的重畫最多每秒 20 次(以前每一個 token 都立刻重畫整個視窗) - 等你決定的卡:黃點和輕彈約每秒 5 次,卡片本身不再逼整頁滿幀重畫 - 沒在動就不為了動畫重畫 feature-map:phone.md 新增 phone-net 的「還沒連上就在外面」步驟;chat.md、FEATURES.md 補上重畫頻率。 已驗證: cargo test 728 通過(含 featuremap::,11 項);verify-anybot phone.md 全部步驟(新增「還沒連上就在外面」,login 步驟改成先等 v-login)+account.md 直接連線步驟,EXIT=0 未驗證: 真 Intel Mac 的發熱和耗電(要實機量 CPU 與風扇);帳號伺服器路徑的進場;實機 iPhone 的連線切換;Bot 的電腦閒置休眠的決定尚未做 Co-authored-by: Cursor --- FEATURES.md | 4 +- docs/feature-map/chat.md | 2 +- docs/feature-map/phone.md | 3 +- mobile/index.html | 82 +++++++++++++++++++++++++++++---------- src/agent.rs | 11 +++++- src/app/chat_ui.rs | 6 +-- src/app/mood_ui.rs | 7 ++++ src/app/sidebar_ui.rs | 6 ++- 8 files changed, 90 insertions(+), 31 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 310290a..03caff8 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1641,7 +1641,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - 搜尋、讀網頁:一支放大鏡在臉下半部左右掃,眼睛跟著它。 - 看螢幕、點擊:小游標移到一個地方按下去,按的地方冒出一圈漣漪。 - 寫回覆:低頭點頭,一枝筆在臉下畫出一行波浪墨水;字停下來時筆也停。 - - 等你決定/回答:看著你,黃點外面一圈光慢慢擴散,每隔幾秒輕輕彈一下。 + - 等你決定/回答:看著你,黃點外面一圈光慢慢擴散,每隔幾秒輕輕彈一下。這段等待不會把整頁畫到滿幀(大約每秒 5 次);工作中的臉和字也最多每秒 20 次。沒在動就不為了動畫重畫。 - 完成:笑臉、跳一下,五顆金色小星星輪流冒出來再消失(約 2 秒)。 - 失敗:眼睛變一字、搖一次頭,一滴汗滑下來後停住(之後不再動,不耗電)。 - 其他步驟(指令、檔案、記憶…)目前還是看著旁邊那句話;道具顏色太接近頁面(深色模式的黑臉、淺色模式的白臉)時會往文字顏色調亮或調暗。 @@ -2186,7 +2186,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - 畫面更新:手機問「有沒有新東西」會等最多 20 秒,有變化就立刻回來,所以不用一直刷新。 - **單趟同步**:開著對話時,狀態檢查順帶把那個對話的訊息帶回來(手機附上簽名,沒變不重傳):Bot 串流輸出時每趟少一個請求,訊息和側欄狀態永遠同一刻。 - **只傳有變的**:手機附上它手上那份狀態的指紋,大腦只回改了的部分(沒變的欄位不送、沒變的 Bot 只寫代號);對話也只送從不一樣的地方開始的訊息(最舊的滑出視窗、最後一則長大、多了新的,都不必整段重送)。大腦記得最近幾千份給過的指紋,慢的網路隔很多次更新再問也對得上;對不上就整份重送。舊版頁面不帶指紋,照舊拿整份。 -- **網路不穩**:每個請求有期限(等新東西 45 秒、其他 60 秒,上傳不限),連線無聲斷掉也會發現;連不上時頂端顯示「連線中斷,正在重新連線…」,重試間隔 1 秒起倍增到 15 秒,回到前景、網路恢復時立刻重連。傳出的訊息帶一個代號自動重送(約一分鐘內),大腦 10 分鐘內同一代號只收一次。打開頁面時連不上,照上次記得的登入方式(帳號或手機密碼)等它連上,不會誤顯示另一種登入。 +- **網路不穩**:每個請求有期限(等新東西 45 秒、其他 60 秒,上傳不限),連線無聲斷掉也會發現;連不上時頂端顯示「連線中斷,正在重新連線…」,重試間隔 1 秒起倍增到 15 秒,回到前景、網路恢復時立刻重連。傳出的訊息帶一個代號自動重送(約一分鐘內),大腦 10 分鐘內同一代號只收一次。還沒連上之前停在最外面的「正在連線…」,第一份狀態到手才進去(進去時清單已經在)。已經進去之後斷線留在裡面重連。 - **傳輸**:直接連線的連線留著給下一個請求(30 秒沒用才關,手機不用每次重做 TCP 和 TLS 握手)、文字回答用 gzip 壓縮、手機頁面帶版本標記(沒換版只回「沒有變」);帳號連線時,電腦回給手機的資料壓縮著上傳到帳號伺服器,在那裡打開、再由 Caddy 壓縮給手機。 ### 設定 › 手機與帳號 diff --git a/docs/feature-map/chat.md b/docs/feature-map/chat.md index 89ad963..4ab0443 100644 --- a/docs/feature-map/chat.md +++ b/docs/feature-map/chat.md @@ -11,7 +11,7 @@ - `chat-stop` 停止:工作中、輸入框空著時,送出鈕變成「停止」。 - `chat-actions` 回答旁的操作:滑過 Bot 的回答出現「新增表情回應」「回覆」(引用這則)「更多訊息操作」;⋯ 裡有「複製」「重新產生」(只有最後一則)「還原上一個答案」「顯示步驟(N)」,最下面寫是哪個模型寫的。出錯的回答下面直接有「重試」。 - `chat-select` 選取一段文字(手機頁面,和用電腦的瀏覽器打開的網頁版):按住一則訊息(或回答下的 ⋯)打開訊息選單,「複製」是整則;「選取文字」把這則放進下方的面板,在那裡按住一個字開始選、拖兩端調整、再按系統的「拷貝」(電腦上拖曳後按 ⌘C 或 Ctrl+C),「完成」關掉。用電腦的瀏覽器時也能直接在聊天裡拖曳選取:在選好的字上按右鍵是瀏覽器自己的選單(「複製」),在別的地方按右鍵才是訊息選單;按住選好的字也不開選單;連結上按右鍵(Android 是長按)是瀏覽器的連結選單。 -- `chat-steps` 步驟和思考:預設收起。「顯示步驟」一行一個工具(等你允許/執行中/完成/被拒絕或停止/失敗),滑過那一行看結果;「思考過程」也在這裡。工作中,輸入框上方的臉旁邊寫它正在做什麼。 +- `chat-steps` 步驟和思考:預設收起。「顯示步驟」一行一個工具(等你允許/執行中/完成/被拒絕或停止/失敗),滑過那一行看結果;「思考過程」也在這裡。工作中,輸入框上方的臉旁邊寫它正在做什麼。臉和「正在…」的閃光最多每秒畫 20 次;等你決定時黃點和輕彈還在,大約每秒 5 次。沒在動就不為了動畫重畫,視窗閒著不一直佔著 CPU。 - `chat-attach` 附件:「附加檔案」、拖進視窗、⌘V 貼圖。每個檔最多 50 MB,一個文字檔最多讀 20,000 字給模型。 - `chat-compact` 長對話:用到「模型可讀長度」的 7 成,先收起舊步驟的長結果,不夠才把舊對話寫成摘要,聊天裡出現「較早的對話已整理成摘要」(「展開摘要」)。 - `chat-stall` 卡住偵測:120 秒還沒開始回應,顯示「模型未能及時開始回應。請重試。」;開始後安靜 35 秒,顯示「回應中斷:模型超過 35 秒沒有送出任何內容。」。等你允許、工具在跑時不算。 diff --git a/docs/feature-map/phone.md b/docs/feature-map/phone.md index 880b1d5..e2eb9ba 100644 --- a/docs/feature-map/phone.md +++ b/docs/feature-map/phone.md @@ -9,7 +9,7 @@ - `phone-look` 長相(和電腦版同一份設計規格:字級、間距、圓角都是同一組數字):Bot 的回答不放在泡泡裡,像文件一樣直接排在畫面上,用宋體(思源宋體,沒有就用系統的宋體)、16px、行距寬;裡面的表格只有橫向細線、數字欄靠右,提示框([!NOTE] 等)同一種淡底、只有圖示依種類上色,程式碼是淡底圓角塊。你自己的訊息(泡泡)和所有按鈕、清單、設定用黑體。手機沒有字型選項。 - `phone-colors` 顏色跟電腦版一樣:電腦上 設定 › 一般 › 外觀 的主題(淺色/深色/跟隨系統)、底色、強調色、對比,手機照著穿;手機自己的「外觀」可以選「跟著電腦」(預設)、「跟著手機」、「淺色」、「深色」。狀態列的顏色跟著畫面。舊版的電腦沒送顏色時,手機用內建的「紙」。 - `phone-claude` 像 Claude 的手機 App:上面一條簡單的標題列(Bot 名稱,第二行是它在做什麼或用哪個模型),輸入框是底部一張圓角卡片,回答下面只有時間和複製/重新產生/⋯;按鈕和點的地方至少 44px;清單每列的說明只有一行(太長以 … 結尾);顏色少,強調色只用在連結、選取和新訊息的點。 -- `phone-net` 網路不穩也能用:連不上時上面出現「連線中斷,正在重新連線…」,自己重試(間隔越來越長,最長 15 秒),回到前景或網路恢復時立刻重連,不用重新整理;一個請求太久沒回音(連線斷了不會自己報錯)就放棄重來。傳出去的訊息沒送到會自己重送,同一則只會送到一次;Bot 工作中插的話重送時寫「網路不穩,重新傳送中…」,真的送不出去才標「沒送出,點一下拿回來重送」(Bot 沒在工作時,字放回輸入框)。只傳有變的部分:狀態只送改了的、打開的聊天只送從不一樣的地方開始的訊息;直接連線的連線留著給下一個請求用、文字壓縮,頁面沒換版就不重新下載。打開時連不上,照上次的方式(帳號或手機密碼)等它連上。 +- `phone-net` 網路不穩也能用:還沒連上之前停在最外面的「正在連線…」(登入表單和 Bot 清單都還沒出現),連上、第一份狀態到手才進去,進去時清單已經在,可以直接點。已經進去之後斷線才留在裡面:上面出現「連線中斷,正在重新連線…」,自己重試(間隔越來越長,最長 15 秒),回到前景或網路恢復時立刻重連,不用重新整理;一個請求太久沒回音(連線斷了不會自己報錯)就放棄重來。傳出去的訊息沒送到會自己重送,同一則只會送到一次;Bot 工作中插的話重送時寫「網路不穩,重新傳送中…」,真的送不出去才標「沒送出,點一下拿回來重送」(Bot 沒在工作時,字放回輸入框)。只傳有變的部分:狀態只送改了的、打開的聊天只送從不一樣的地方開始的訊息;直接連線的連線留著給下一個請求用、文字壓縮,頁面沒換版就不重新下載。 - `phone-app` 像 App 一樣:加入主畫面後全螢幕、沒有網址列(瀏海、動態島、底部手勢條、橫放都避開);首頁會提示「把 AnyBot 裝成 App」(Android 直接安裝,iPhone 教你加入主畫面,可以關掉);換畫面會左右滑動;iPhone 主畫面 App 從左邊緣往右滑回上一頁。 ## 使用者怎麼到 @@ -26,6 +26,7 @@ - 基本前提和「手機已登入」(README;走的是直接連線,帳號那條見 [account](account.md))。 +- **還沒連上就在外面**(covers `phone-net`):打開頁面,等它自己連上。指令:`$CTL phone open --listed && $CTL phone wait-gone '#v-gate.on' 20 && $CTL phone wait '#v-login.on'`。看到:連上之後停在登入,不是 Bot 清單;登入後才進得去。 - **清單和選單**(covers `phone-pages`、`phone-claude`):看首頁,打開 Bot 那列的「⋯」。指令:`$CTL phone wait '.row[data-bot="1"]' && $CTL phone click '[data-botmenu="1"]' && $CTL phone wait-text 對話詳細資訊 --in '#sheet-in' && $CTL phone shot phone-menu && $CTL phone click '#sheet-in .opt' --text 釘選 && $CTL wait-api '/api/state?since=0' '.bots[0].pinned == true'`。看到:一列一個 Bot(第二行一行說明);選單有「對話詳細資訊」「釘選」「移至分區」「更多…」;釘選後大腦那邊 pinned。 - **聊天**(covers `phone-pages`、`phone-look`、`phone-claude`):打開 Bot、傳一句。指令:`$CTL phone click '.row[data-bot="1"]' && $CTL phone send '你好,從手機傳的' && $CTL phone wait-text 'FAKE-MODEL 回答:你好,從手機傳的' --in '#msgs' && $CTL phone shot phone-chat`。看到:標題列是名稱和 fake-model;你的話是泡泡,回答直接排在畫面上(宋體)、下面只有時間和圖示;輸入框是底部圓角卡片。 - **全部允許,之後直接操作**(covers `phone-pages`、`phone-cards`):請 Bot 改名,在卡片上按「全部允許,之後直接操作」›「打開」,再按「允許」。指令:`$CTL phone send '請改名 [[call update_bot {"name":"手機改的名字"}]]' && $CTL phone click '#ask [data-direct]' && $CTL phone click '#sheet-in .opt' --text 打開 && $CTL phone wait-text '只能收緊、不能放寬' && $CTL phone wait '#ask .ask' && $CTL phone click '#ask button[data-a="once"]' && $CTL phone wait-text 手機改的名字 --in '#isl-name'`。看到:直接連線打不開直接操作([autonomy](autonomy.md)),卡片留著;按「允許」才改名。 diff --git a/mobile/index.html b/mobile/index.html index 0fd2afc..ed2cec7 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -577,6 +577,17 @@ button,.row,.ib,.island,.opt,.chip,.tab,label.sw,[role="button"]{-webkit-user-se
+ +
+
+ +
+
+
@@ -873,7 +884,7 @@ const S = { sending: [], voice: {}, relay: false, token: localStorage.getItem("anybot.token") || "", host: localStorage.getItem("anybot.host") || "", version: 0, bots: [], approvals: [], pages: [], models: [], hostName: "", mac: false, box: "", boxOn: false, role: "owner", prevShown: 0, prevFirst: "", answer: null, sc: "", - open: 0, msgs: [], pending: [], quote: null, unfold: {}, openSteps: {}, detail: {}, audit: {}, settings: null, polling: false, + open: 0, msgs: [], pending: [], quote: null, unfold: {}, openSteps: {}, detail: {}, audit: {}, settings: null, polling: false, entered: false, chatSig: "", file: null, search: "", size: [0, 0], right: false, }; @@ -1061,14 +1072,18 @@ const cur = () => NAV[NAV.length - 1] || {v: "home", arg: {}}; // ---------- sign in ---------- async function hello(tries = 0) { - // Opened on a bad network: the way in it had last time (the account's or the phone password's), - // not the phone password's because nothing answered. + // Still outside: the login and the bot list wait until this answers. A remembered way in + // (account or phone password) only labels the wait — it does not open the app on a dead line. + if (!S.entered) show("gate"); const known = localStorage.getItem("anybot.relay"); try { const v = await api("api/hello", {timeout: 12000}); S.relay = v.app === "anybot-relay"; localStorage.setItem("anybot.relay", S.relay ? "1" : "0"); netDown(false); } catch (e) { if (!e.transient) S.relay = false; - else if (known !== null) { S.relay = known === "1"; netDown(true); } - else { netDown(true); await rest(backoff(tries, 15000)); return hello(tries + 1); } + else { + if (known !== null) S.relay = known === "1"; + netDown(true); + if (!S.entered) { await rest(backoff(tries, 15000)); return hello(tries + 1); } + } } $("f-user").style.display = S.relay ? "" : "none"; $("b-mode").style.display = S.relay ? "" : "none"; @@ -1107,7 +1122,7 @@ $("b-login").onclick = async () => { $("f-pass").addEventListener("keydown", (e) => { if (e.key === "Enter") $("b-login").click(); }); function signOut(expired) { if (S.token && !expired) api(S.relay ? "relay/logout" : "api/logout", {json: {}}).catch(() => {}); - S.token = ""; localStorage.removeItem("anybot.token"); S.version = 0; NAV.length = 0; show("login"); + S.token = ""; localStorage.removeItem("anybot.token"); S.version = 0; S.entered = false; NAV.length = 0; show("login"); if (expired) $("login-err").textContent = "登入已失效,請重新登入"; } $("b-out1").innerHTML = ic("log-out", 20); @@ -1146,19 +1161,34 @@ async function pickHost() { const waiting = hosts.length && !live.length && wanted ? `
「${esc(wanted.name)}」暫時沒有連線(可能正在重新啟動,或那台電腦睡著了)。
連上後會自動進入,不用重新整理。
` : ""; $("hosts").innerHTML = waiting + (hosts.length ? hosts.map((h) => `
${ic(h.online ? "monitor" : "power", 18)}
${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(); }); + document.querySelectorAll("#hosts .row").forEach((r) => r.onclick = () => { clearTimeout(hostRetry); S.host = r.dataset.h; localStorage.setItem("anybot.host", S.host); if (!S.entered) show("gate"); start(); }); show("hosts"); if (S.token && !live.length) hostRetry = setTimeout(pickHost, 3000); } // ---------- live state ---------- const TZ = (() => { try { return Intl.DateTimeFormat().resolvedOptions().timeZone || ""; } catch (_) { return ""; } })(); +// The first state is in: now the list (or the chat a link asked for) is drawn, already filled. +function enter() { + if (S.entered) return; + S.entered = true; + netDown(false); + if (!NAV.length) { NAV.push({v: "home", arg: {}}); history.replaceState({n: 1}, ""); } + if (S.answer && S.token) { + const a = S.answer; S.answer = null; + api(base() + `api/bots/${a.bot}/answer`, {json: {answer: a.answer, call: a.call, from: "notice"}}).then(() => toast("已從通知回覆")).catch((e) => toast(e.message)); + } + if (S.sc && !S.open) { + const want = S.sc === "unread" ? S.bots.find((b) => b.unread) : (S.bots.find((b) => b.primary) || S.bots[0]); + S.sc = ""; + if (want) S.open = want.id; + } + if (S.open && cur().v !== "chat") go("chat", {bot: S.open}); + else { const t = cur(); draw(t.v, t.arg); } +} async function start() { - if (!NAV.length) { - NAV.push({v: "home", arg: {}}); history.replaceState({n: 1}, ""); - if (S.open) go("chat", {bot: S.open}); else draw("home", {}); - } else { const t = cur(); draw(t.v, t.arg); } if (S.polling) return; + if (!S.entered) show("gate"); S.polling = true; let fails = 0; while (S.token) { @@ -1168,7 +1198,7 @@ async function start() { // when their signature changed, and then only from where they differ (api/state?bot=… // &chat_sig=…&chat_delta=1). The rest of the state likewise: only what changed since the // state this page holds (ssig). - const open = S.view === "chat" && S.open ? "&bot=" + S.open + "&chat_sig=" + encodeURIComponent(S.chatSig) + "&chat_delta=1" : ""; + const open = S.open && (S.view === "chat" || !S.entered) ? "&bot=" + S.open + "&chat_sig=" + encodeURIComponent(S.chatSig) + "&chat_delta=1" : ""; const held = S.version && S.ssig ? "&ssig=" + encodeURIComponent(S.ssig) : ""; let v = await api(base() + "api/state?since=" + S.version + "&tz=" + encodeURIComponent(TZ) + held + open, {timeout: POLL_MS, signal: pollCtl.signal}); fails = 0; netDown(false); @@ -1179,7 +1209,8 @@ async function start() { v = whole; } S.st = v; S.ssig = v.ssig || ""; - if (v.version !== S.version) { S.version = v.version; apply(v); } + if (v.version !== S.version || !S.entered) { S.version = v.version; apply(v); } + if (!S.entered) enter(); } catch (e) { if (!S.token) break; // Cut short by kick(): ask again at once. @@ -1217,6 +1248,18 @@ function mergeState(prev, v) { } function apply(v) { S.bots = v.bots || []; S.approvals = v.approvals || []; S.hostName = v.host || ""; S.mac = !!v.mac; + S.box = v.box || ""; S.boxOn = !!v.box_available; S.pages = v.pages || []; S.models = v.models || []; S.sections = v.sections || null; S.role = v.role || "owner"; + S.voice = v.voice || {}; micShown(); appBadge(); + // The computer's 外觀 (an older brain sends neither: the built-in look stays). + if (v.palettes) applyPalette(v.palettes); + if (typeof v.theme === "string" && v.theme !== DESK.theme) { DESK.theme = v.theme; try { localStorage.setItem("anybot.desk-theme", v.theme); } catch (_) {} applyTheme(); } + // Still on the gate: keep what arrived (so the list and an opened chat are full the moment + // we go in) but don't draw the inside yet. + if (!S.entered) { + const c = v.chat; + if (c && c.bot === S.open && c.messages && c.from === undefined) { S.msgs = c.messages; S.chatSig = c.sig || ""; } + return; + } // An approval answered from a notification banner, and a home-screen shortcut (主要 Bot, 未讀). if (S.answer && S.token) { const a = S.answer; S.answer = null; @@ -1228,11 +1271,6 @@ function apply(v) { S.sc = ""; if (want) { S.open = want.id; go("chat", {bot: want.id}); } } - S.box = v.box || ""; S.boxOn = !!v.box_available; S.pages = v.pages || []; S.models = v.models || []; S.sections = v.sections || null; S.role = v.role || "owner"; - S.voice = v.voice || {}; micShown(); appBadge(); - // The computer's 外觀 (an older brain sends neither: the built-in look stays). - if (v.palettes) applyPalette(v.palettes); - if (typeof v.theme === "string" && v.theme !== DESK.theme) { DESK.theme = v.theme; try { localStorage.setItem("anybot.desk-theme", v.theme); } catch (_) {} applyTheme(); } const t = cur(); if (t.v === "home") renderHome(); else if (t.v === "chat") { @@ -1388,7 +1426,7 @@ $("b-me").onclick = () => { if (!installed() && (S.installPrompt || navigator.standalone === false)) items.push({icon: "download", label: "安裝成 App", on: installApp}); if (S.mac) items.push({icon: "monitor", label: "看這台 Mac 的螢幕", on: () => go("screen")}); if (S.relay && owner()) items.push({icon: "plus", label: "加一台電腦(Linux、伺服器)", on: pair}); - if (S.relay) items.push({icon: "refresh", label: "切換到別台 AnyBot", on: () => { S.host = ""; localStorage.removeItem("anybot.host"); S.version = 0; NAV.length = 0; pickHost(); }}); + if (S.relay) items.push({icon: "refresh", label: "切換到別台 AnyBot", on: () => { S.host = ""; localStorage.removeItem("anybot.host"); S.version = 0; S.ssig = ""; S.entered = false; NAV.length = 0; show("gate"); kick(); pickHost(); }}); items.push({icon: "log-out", label: "登出這支手機", danger: true, on: async () => { if (await confirmSheet("要登出這支手機嗎?", "", "登出", true)) signOut(); }}); sheet(S.hostName || "AnyBot", items); }; @@ -1427,7 +1465,9 @@ function openChat(id) { chat.classList.toggle("quiet", bubble === "quiet"); if (bubble === "bot" && ob.color && ob.color_key !== "black") { chat.style.setProperty("--bot", ob.color); chat.style.setProperty("--bot-ink", "var(--on-color)"); } else { chat.style.removeProperty("--bot"); chat.style.removeProperty("--bot-ink"); } - chatHead(); renderChips(); renderQuote(); loadChat(true); renderDock(); + chatHead(); renderChips(); renderQuote(); + if (S.msgs.length) { renderMsgs(); $("scroller").scrollTop = $("scroller").scrollHeight; } + loadChat(true); renderDock(); api(base() + `api/bots/${id}/read`, {json: {}}).catch(() => {}); } let loading = false, again = false; @@ -2796,7 +2836,7 @@ function wireSettings(kind, st) { else if (k === "2fa") twoFaSheet(); else if (k === "devices") devicesSheet(); else if (k === "pair") pair(); - else if (k === "host") { S.host = ""; localStorage.removeItem("anybot.host"); S.version = 0; NAV.length = 0; pickHost(); } + else if (k === "host") { S.host = ""; localStorage.removeItem("anybot.host"); S.version = 0; S.ssig = ""; S.entered = false; NAV.length = 0; show("gate"); kick(); pickHost(); } else if (k === "out") { if (await confirmSheet("要登出這支手機嗎?", "", "登出")) signOut(); } }); on("[data-bx]", "onclick", async (x) => { diff --git a/src/agent.rs b/src/agent.rs index c01ef46..9df57ad 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -1944,9 +1944,18 @@ pub fn spawn(job: Job, bot_id: u64, tx: Sender<(u64, StreamEvent)>, cancel: Arc< let mut job = job; crate::providers::set_patient(job.unattended); TURN_BOT.with(|b| b.set(bot_id)); + // A token must not redraw the whole window on its own: they arrive faster than a + // slower machine can paint, and the fans stay on for the whole answer. + let last_paint = std::cell::Cell::new(Instant::now() - Duration::from_millis(50)); let send = |ev: StreamEvent| { let _ = tx.send((bot_id, ev)); - ctx.request_repaint(); + let now = Instant::now(); + if now.saturating_duration_since(last_paint.get()) >= Duration::from_millis(50) { + last_paint.set(now); + ctx.request_repaint(); + } else { + ctx.request_repaint_after(Duration::from_millis(50)); + } }; let mut history = job.req.history.clone(); let mut grants = job.grants.clone(); diff --git a/src/app/chat_ui.rs b/src/app/chat_ui.rs index c149549..09ae326 100644 --- a/src/app/chat_ui.rs +++ b/src/app/chat_ui.rs @@ -420,7 +420,7 @@ pub fn spinner(ui: &mut egui::Ui, size: f32, col: Color32) { c + vec2(a.cos(), a.sin()) * r }).collect(); ui.painter().add(egui::Shape::line(pts, Stroke::new(2.0, col))); - ui.ctx().request_repaint(); + ui.ctx().request_repaint_after(std::time::Duration::from_millis(50)); } /// Text with a light band sweeping across it (the original's sand-shimmer-text). @@ -436,7 +436,7 @@ pub fn shimmer(ui: &mut egui::Ui, text: &str, base: Color32, bright: Color32, si job.append(&ch.to_string(), 0.0, egui::TextFormat { font_id: egui::FontId::proportional(size), color: col, ..Default::default() }); } ui.label(job); - ui.ctx().request_repaint(); + ui.ctx().request_repaint_after(std::time::Duration::from_millis(50)); } impl App { @@ -962,7 +962,7 @@ impl App { let now = ui.input(|i| i.time); self.jump_bottom = jump_still_on(self.jump_bottom, from_bottom, now); if self.jump_bottom.is_some() { - ui.ctx().request_repaint(); + ui.ctx().request_repaint_after(std::time::Duration::from_millis(50)); } let id = egui::Id::unique("jump-bottom"); let k = ui.ctx().animate_bool_with_time(id, jump_shows(from_bottom, self.jump_bottom.is_some()), JUMP_BOTTOM_FADE); diff --git a/src/app/mood_ui.rs b/src/app/mood_ui.rs index 49733d7..8c6e7a7 100644 --- a/src/app/mood_ui.rs +++ b/src/app/mood_ui.rs @@ -259,10 +259,17 @@ impl App { Mood::Idle => false, // An error stays on screen: the shake and the drop play once, then it rests. Mood::Failed => age < 2.6, + // Needs the person for as long as they take: the ring and the hop still move, + // but the whole window is not redrawn every frame while the card sits there. + Mood::Waiting => false, + Mood::Done => age < CHEER_SECS, _ => true, }; // (Its own state, apart from the same bot's face in the sidebar, which looks elsewhere.) let mut pose = self.settle_face(&ctx, !bot.id, target, moving, false); + if mood == Mood::Waiting { + ctx.request_repaint_after(std::time::Duration::from_millis(200)); + } pose.eyes = match mood { Mood::Done => avatar::Eyes::Smile, Mood::Failed => avatar::Eyes::Flat, diff --git a/src/app/sidebar_ui.rs b/src/app/sidebar_ui.rs index b65fc58..e706d6f 100644 --- a/src/app/sidebar_ui.rs +++ b/src/app/sidebar_ui.rs @@ -161,7 +161,9 @@ impl App { } let moving = f.poke.is_some() || (f.gaze - target).length() > 0.002 || blink > 0.0 || working || f.spin != 0.0; if moving { - ctx.request_repaint(); + // One frame of the whole window, not as fast as the display can go: on a slower + // machine an uncapped face redrew the chat flat out and the fans never stopped. + ctx.request_repaint_after(std::time::Duration::from_millis(50)); } else { ctx.request_repaint_after(std::time::Duration::from_secs_f64((f.next_blink - now).max(0.05))); } @@ -1059,7 +1061,7 @@ impl App { ui.allocate_exact_size(screen.size(), egui::Sense::click()); }); } - ctx.request_repaint(); + ctx.request_repaint_after(std::time::Duration::from_millis(50)); true } }