From 7e7cbebd576599f3f9dbba936789bb316eb6d013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Sat, 21 Nov 2026 14:29:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E5=B0=8B=E8=A8=AD=E5=AE=9A=EF=BC=88?= =?UTF-8?q?=E8=A8=88=E7=95=AB=20C3=20=E7=AC=AC=E4=B8=80=E6=AD=A5=EF=BC=89?= =?UTF-8?q?=EF=BC=9A=E8=A8=AD=E5=AE=9A=E8=A6=96=E7=AA=97=E5=B7=A6=E6=AC=84?= =?UTF-8?q?=E6=9C=80=E4=B8=8A=E9=9D=A2=E3=80=8C=E6=90=9C=E5=B0=8B=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E2=80=A6=E3=80=8D=E3=80=82=E6=89=93=E5=AD=97=E6=99=82?= =?UTF-8?q?=E9=A0=81=E9=9D=A2=E6=B8=85=E5=96=AE=E6=8F=9B=E6=88=90=E7=AC=A6?= =?UTF-8?q?=E5=90=88=E7=9A=84=E8=A8=AD=E5=AE=9A=EF=BC=8C=E6=9C=80=E5=A4=9A?= =?UTF-8?q?=2012=20=E5=80=8B=EF=BC=9A=E6=A8=99=E9=A1=8C=E9=96=8B=E9=A0=AD?= =?UTF-8?q?=E7=9B=B8=E7=AC=A6=E7=9A=84=E5=9C=A8=E5=89=8D=EF=BC=8C=E5=86=8D?= =?UTF-8?q?=E4=BE=86=E6=A8=99=E9=A1=8C=E5=8C=85=E5=90=AB=E7=9A=84=EF=BC=8C?= =?UTF-8?q?=E5=86=8D=E4=BE=86=E6=89=80=E5=9C=A8=E5=8D=80=E5=A1=8A=E6=88=96?= =?UTF-8?q?=E5=88=A5=E7=9A=84=E8=AA=AA=E6=B3=95=E2=80=94=E2=80=94=E6=AF=8F?= =?UTF-8?q?=E5=80=8B=E8=A8=AD=E5=AE=9A=E7=99=BB=E8=A8=98=E4=BA=86=E4=BA=BA?= =?UTF-8?q?=E6=9C=83=E6=89=93=E7=9A=84=E5=AD=97=EF=BC=88=E3=80=8C=E6=B7=B1?= =?UTF-8?q?=E8=89=B2=E3=80=8D=E2=86=92=20=E4=B8=BB=E9=A1=8C=E3=80=81?= =?UTF-8?q?=E3=80=8Cbilling=E3=80=8D=E3=80=8C=E8=8A=B1=E8=B2=BB=E3=80=8D?= =?UTF-8?q?=E2=86=92=20=E7=94=A8=E9=87=8F=E3=80=81=E3=80=8CWi-Fi=E3=80=8D?= =?UTF-8?q?=E3=80=8CTailscale=E3=80=8D=E2=86=92=20=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E5=80=8B=E7=B6=B2=E8=B7=AF=E7=9B=B4=E6=8E=A5=E9=80=A3=EF=BC=89?= =?UTF-8?q?=EF=BC=8C=E6=A8=A1=E5=9E=8B=E4=BE=9B=E6=87=89=E5=95=86=E7=94=A8?= =?UTF-8?q?=E5=90=8D=E5=AD=97=E6=89=BE=EF=BC=9B=E6=AF=8F=E5=80=8B=E4=B8=8B?= =?UTF-8?q?=E9=9D=A2=E5=AF=AB=E5=9C=A8=E5=93=AA=EF=BC=88=E3=80=8C=E4=B8=80?= =?UTF-8?q?=E8=88=AC=20=E2=80=BA=20Bot=E3=80=8D=EF=BC=89=E3=80=82=E9=BB=9E?= =?UTF-8?q?=E4=B8=80=E5=80=8B=E6=88=96=E6=8C=89=20Enter=20=E6=8B=BF?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E5=80=8B=EF=BC=9A=E6=8F=9B=E5=88=B0=E9=82=A3?= =?UTF-8?q?=E4=B8=80=E9=A0=81=EF=BC=8C=E6=95=B4=E5=90=88=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E5=88=86=E9=A0=81=E5=92=8C=E5=B8=82=E9=9B=86=E3=80=81=E6=94=B6?= =?UTF-8?q?=E8=B5=B7=E4=BE=86=E7=9A=84=E3=80=8C=E6=9B=B4=E5=A4=9A=E5=A4=96?= =?UTF-8?q?=E8=A7=80=E8=A8=AD=E5=AE=9A=E3=80=8D=E8=B7=9F=E8=91=97=E6=89=93?= =?UTF-8?q?=E9=96=8B=EF=BC=8C=E6=8D=B2=E5=88=B0=E9=82=A3=E4=B8=80=E5=88=97?= =?UTF-8?q?=EF=BC=8C=E5=A4=96=E6=A1=86=E7=94=A8=E5=BC=B7=E8=AA=BF=E8=89=B2?= =?UTF-8?q?=E4=BA=AE=E4=B8=80=E4=B8=8B=E3=80=81=E7=B4=84=202=20=E7=A7=92?= =?UTF-8?q?=E6=B7=A1=E6=8E=89=EF=BC=88kit=20=E7=9A=84=20section=E3=80=81se?= =?UTF-8?q?tting=5Ftitle=E3=80=81card=5Frow=20=E7=95=AB=E7=9A=84=E6=99=82?= =?UTF-8?q?=E5=80=99=E5=B0=8D=E4=B8=80=E4=B8=8B=EF=BC=89=EF=BC=9BEsc=20?= =?UTF-8?q?=E5=8F=AA=E6=B8=85=E7=A9=BA=E3=80=81=E4=B8=8D=E9=97=9C=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 登記表在 src/app/settings_find.rs;新測試擋兩件事:設定頁畫的每個區塊和列都要在表裡(漏登記的新設定會失敗——刪掉「磁碟」試過,會報出來),表裡的也都還在頁面上。layout_audit 多一景「設定 › 搜尋」。 已驗證: cargo test 836 過(含 app::settings_find:: 兩個新測試、featuremap::、layout_audit::);clippy 維持 12;scratch 桌面截圖(示範資料):打「自動」左欄是 自動更新/電腦 › Bot 的電腦、自動審核/權限、自動更新/更新;打「時區」按 Enter,換到一般、捲到 Bot 下的時區,那列強調色外框;從更新頁打「對比」按 Enter,換到一般、更多外觀設定變「收起」、對比有外框;打「連接器市」按 Enter,到 整合 › 連接器 的市集頁、標題有外框。 未驗證: 英文介面下的搜尋(登記的字是中文,英文標題靠 t() 翻過的也比對,沒實際截圖);條件才出現的列(例如沒有 Docker 時的「Docker 主機」、Mac 才有的「螢幕錄製」)在這台不出現時只換頁不亮框;左欄分組、每列至少 64 px、危險區、確認框預設停在取消還沒做。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm --- FEATURES.md | 6 + docs/feature-map/settings.md | 4 +- docs/plan-2026-11-openbot.md | 2 +- src/app.rs | 44 ++++ src/app/kit.rs | 7 +- src/app/layout_audit.rs | 7 + src/app/settings_find.rs | 377 +++++++++++++++++++++++++++++++++++ 7 files changed, 443 insertions(+), 4 deletions(-) create mode 100644 src/app/settings_find.rs diff --git a/FEATURES.md b/FEATURES.md index a5d08f3..9f1dcc3 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1588,6 +1588,12 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - 檔案不在原處(刪掉或搬走):灰字、紅字「不見了」,點不開。其他點一下用 AnyBot 的檢視器打開(Markdown、表格、圖片、PDF、影音、程式碼;用其他 App 打開、下載)。 - 螢幕電腦看的是從大腦抓過來的副本。手機還沒有(只有每個對話的「資料庫」)。功能地圖新的一區 library.md。 +### 搜尋設定(設定視窗左欄) + +- 左欄最上面「搜尋設定…」。打字時頁面清單換成符合的設定,最多 12 個:標題開頭相符的在前,再來標題包含的,再來所在區塊或別的說法(每個設定登記了人會打的字:「深色」→ 主題、「billing」「花費」→ 用量、「Wi-Fi」「Tailscale」→ 同一個網路直接連;模型供應商用名字找)。每個下面一行寫在哪(「一般 › Bot」「整合 › 連接器」)。 +- 點一個或按 Enter 拿第一個:換到那一頁,整合的小分頁和市集、收起來的「更多外觀設定」會跟著打開,捲到那一列,外框用強調色亮一下、約 2 秒淡掉。Esc 清空,不會關掉設定。 +- 登記表在 `src/app/settings_find.rs`;測試會擋:設定頁畫的每個區塊和列(`section`、`setting_title`、`card_row`…)都要在表裡,表裡的也都還在頁面上。 + ### Bot 在哪一台(左下角) - 左下角你的名字下面多一行:Bot 在哪一台——「這台電腦」,或「大腦「雲端大腦」」(綠點連得到、灰點連不到)。不用打開設定就看得出現在看的是哪一台的 Bot。 diff --git a/docs/feature-map/settings.md b/docs/feature-map/settings.md index 9e9e697..eb3a5f9 100644 --- a/docs/feature-map/settings.md +++ b/docs/feature-map/settings.md @@ -12,6 +12,7 @@ - 帳戶:「登入」或「管理帳戶」打開「手機與帳號」頁;資料放在哪。 - `settings-whose` 左下角(你的名字):名字下面一行寫 Bot 在哪一台——「這台電腦」,或「大腦「名字」」(綠點連得到、灰點連不到)。點一下開「Bot 在哪一台」選單:「這台電腦(這台的名字)」、帳號裡每台可以當大腦的電腦(現在用的打勾,離線的灰、不能點),點一下就換——跟「手機與帳號」頁大腦那一欄的「改用它當大腦」「改回用這台自己的 Bot」一樣([account](account.md));沒登入帳號多一行「登入帳號,才能換到別台大腦…」;分隔線下「所有檔案…」([library](library.md))、「個人資料與用量…」、「設定…」(⌘, 也可以)。 - `settings-me` 「個人資料」:名字、過去一年有幾個活躍日;五張卡——Token(過去一年,不算快取命中)、最活躍的一天、訊息、目前連續天數(今天還沒用不算斷)、最長連續天數;「活動」一年的熱度格子(一週一欄、越忙顏色越深,滑過看日期、token、訊息數);「用量」選 7 天/30 天/90 天/一年:token(新讀、寫、快取讀到)、呼叫次數、花費(模型服務回報的,沒回報寫「未定價」,不是 0 元)、每天一條、依模型、依 Bot。左下角選單也有「個人資料與用量…」。螢幕電腦上算的是大腦的(向大腦要);手機和螢幕的路是 `api/stats`、`api/sync/stats`(擁有者才有)。 +- `settings-search` 「搜尋設定…」(左欄最上面):打字時頁面清單換成符合的設定(最多 12 個),標題開頭相符的在前,再來標題包含的,再來所在區塊或別的說法(「深色」找到「主題」、「billing」找到「用量」;模型供應商用名字找);每個下面寫在哪(「一般 › Bot」)。點一個或按 Enter 拿第一個:換到那一頁(整合的小分頁、市集、收起來的「更多外觀設定」會跟著打開)、捲到那一列,外框用強調色亮一下(約 2 秒淡掉);Esc 清空。 - `settings-account` 「手機與帳號」頁(從 一般 › 帳戶 進去,[account](account.md)):「AnyBot 帳號」(登入、備份、還原)、大腦和「加一台電腦」([computers](computers.md))、「同一個網路直接連」、「手機可以做什麼」、「直接連線的裝置」、「分享給團隊」([team](team.md))、「帳號裡的電腦」。 - `settings-models` 「模型」:每家 AI 供應商的 API 金鑰、服務網址、新 Bot 預設模型、「測試連線並取得模型清單」([models](models.md));本機或區網的供應商多「看不到圖時,請雲端模型看截圖和附件」(預設關,[chat](chat.md))。「ChatGPT 方案」沒有金鑰和網址欄,改成「ChatGPT 帳號」:登入狀態、「使用 ChatGPT 繼續」「登出」「換帳號」「打開登入頁」「管理用量」;連到別台大腦時多一格貼回登入網址和「完成登入」。 - `settings-integrations` 「整合」,三個小分頁: @@ -48,11 +49,12 @@ - **左下角:Bot 在哪一台**(covers `settings-whose`):前提:要開視窗。指令:`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot whose ANYBOT_SHOT_VIEW=whose ANYBOT_SHOT_SIZE=1000x620 'ANYBOT_SHOT_CLICK=90,595@6' ANYBOT_SHOT_FRAMES=60`(示範資料:已登入、是「雲端大腦」的螢幕、jenny-Host 離線),再不帶 `ANYBOT_SHOT_VIEW` 跑一次(沒登入)。看到:左下角「daniel/● 大腦「雲端大腦」」;選單「Bot 在哪一台」下「這台電腦(…)」「✓ 雲端大腦」「jenny-Host(離線)」(灰),分隔線下「所有檔案…」「個人資料與用量…」「設定…」;沒登入時是「✓ 這台電腦(…)」「登入帳號,才能換到別台大腦…」,分隔線下同樣三項。真的切換要帳號裡有另一台大腦:走不到,和「手機與帳號」頁的按鈕是同一段(`mir.want`、`mir.leave`)。 - **個人資料與用量**(covers `settings-me`):指令:`$CTL api GET /api/stats --jq '{tokens_year, messages_year, streak_now, active_days, d: (.days|length), p: (.periods|keys)}'`;桌面要開視窗:`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot me ANYBOT_SHOT_TAB=me ANYBOT_SHOT_SIZE=1000x900`。看到:API 有 371 天的 days、periods 7/30/90/365;畫面上五張卡、熱度格子、「用量」和那四個期間、依模型、依 Bot。scratch 的假模型不回報用量,token 是 0、花費「未定價」(真的數字靠 `cargo test stats::`)。 +- **搜尋設定**(covers `settings-search`):前提:要開視窗。指令:`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot set-search ANYBOT_SHOT_TAB=general ANYBOT_SHOT_SIZE=1100x760 ANYBOT_SHOT_FRAMES=60 'ANYBOT_SHOT_CLICK=245,159@20' 'ANYBOT_SHOT_TYPE=自動@30'`;再跑兩次,加 `'ANYBOT_SHOT_KEYS=Enter@40'`、`ANYBOT_SHOT_FRAMES=66`:打 `時區@30`,和從更新頁(`ANYBOT_SHOT_TAB=updates`)打 `對比@30`。看到:「自動更新/電腦 › Bot 的電腦」「自動審核/權限」「自動更新/更新」;時區那次換到一般、捲到「Bot」下的「時區」,那列有強調色外框;對比那次「更多外觀設定」變「收起」、「對比」有外框。 - **Bot 改三樣**(covers `settings-by-bot`、`settings-general`):請 Bot 換深色、只用黑色、時區紐約,再傳一句。指令:`$CTL phone send '改 [[call update_settings {"theme":"dark","accent":"black","timezone":"America/New_York"}]]' && $CTL phone wait-text '時區 → America/New_York' --in '#msgs' && $CTL phone send 幾點 && $CTL phone wait-text 'FAKE-MODEL 回答:幾點' --in '#msgs' && $CTL model 'select(.kind == "turn") | .user' && TZ=America/New_York date +%H:%M`。看到:不用卡片,「已更新:主題 → dark、聊天的顏色 → black、時區 → America/New_York」;Bot 收到的〔送出時間〕是紐約時間。 - **錯的時區**(covers `settings-by-bot`):指令:`$CTL phone send '錯 [[call update_settings {"timezone":"Mars/Base"}]]' && $CTL phone wait-text '不是有效的時區名稱' --in '#msgs' && $CTL state .timezone`。看到:「「Mars/Base」不是有效的時區名稱(例如 Asia/Taipei)」;還是 America/New_York。 - **手機的設定**(covers `settings-general`、`settings-account`、`settings-models`、`settings-integrations`、`settings-computers`、`settings-perms`、`settings-vault`、`settings-updates`):重新整理,帳戶選單 › 設定 › 一般。指令:`$CTL phone open --listed && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 設定 && $CTL phone wait '[data-go="updates"]' && $CTL phone shot settings-tabs && $CTL phone click '[data-go="general"]' && $CTL phone wait-text America/New_York --in '#list' && $CTL phone wait-text 只用黑色 --in '#list' && $CTL phone shot settings-general`。看到:八列(沒有語音);一般裡主題「深色」、聊天的顏色「只用黑色」、時區、通知、這支手機的外觀。 - **桌面每個分頁、Bot 設定**(covers `settings-voice`、`settings-bot`、`settings-account`、`settings-computers`):每個分頁和 Bot 設定。指令:要開視窗——`$CTL stop && (for t in general remote providers channels computers review vault voice updates; do ABV_ALLOW_WINDOW=1 $CTL desktop-shot settings-$t ANYBOT_SHOT_TAB=$t || exit 1; done) && ABV_ALLOW_WINDOW=1 $CTL desktop-shot settings-bot ANYBOT_SHOT_VIEW=editor`。看到:各分頁的區塊照上面順序;Bot 設定最下面「儲存」。問候照時區(紐約晚上「晚上好」)也只在桌面。 -- 自動測試:`cargo test stats::`、`cargo test featuremap::`(每個分頁和區塊標題、Bot 能改的設定都要在這份)、`cargo test appctl::`、`cargo test policy::`、`cargo test the_greeting_follows_the_timezone_setting`、`cargo test layout_audit::`(每個分頁、Bot 設定、例行任務、右側面板,用三種字型、最窄和一般的視窗、示範和很長的資料畫:字被切、疊在一起,或對話框被撐得比標題列寬就失敗)。 +- 自動測試:`cargo test app::settings_find::`(設定頁畫的每個區塊和列都要在搜尋的清單裡)、`cargo test stats::`、`cargo test featuremap::`(每個分頁和區塊標題、Bot 能改的設定都要在這份)、`cargo test appctl::`、`cargo test policy::`、`cargo test the_greeting_follows_the_timezone_setting`、`cargo test layout_audit::`(每個分頁、Bot 設定、例行任務、右側面板,用三種字型、最窄和一般的視窗、示範和很長的資料畫:字被切、疊在一起,或對話框被撐得比標題列寬就失敗)。 ## 陷阱 diff --git a/docs/plan-2026-11-openbot.md b/docs/plan-2026-11-openbot.md index f300e09..c0b3008 100644 --- a/docs/plan-2026-11-openbot.md +++ b/docs/plan-2026-11-openbot.md @@ -127,7 +127,7 @@ 你不在時回完了 → 閒著;暫停的是睡著、連線中另一個表情。做事時依步驟種類換臉(搜尋、看網頁、讀檔、跑指令、改檔、交給別的 Bot), 一張臉至少停 1.4 秒;忙的時候輕微呼吸(2.6 秒、縮放 ±3%);「減少動態」開關,CPU 繪圖時預設關。 -**C3. 設定的樣子**:左欄分組(見 B2)+最上面「搜尋設定…」:每一列設定都登記(標題、說明、在哪一頁), +**C3. 設定的樣子**(11/21 做了搜尋:左欄「搜尋設定…」、登記表+測試擋漏登記、跳過去捲到那一列並亮框;左欄分組、每列 64 px、危險區、確認框停在取消還沒做):左欄分組(見 B2)+最上面「搜尋設定…」:每一列設定都登記(標題、說明、在哪一頁), (現況:沒有設定搜尋;「手機與帳號」藏在 一般 › 帳戶 裡;螢幕電腦上哪些是這台的設定是程式裡寫死的一張表 `LOCAL_KEYS`(`src/app/mirror_ui.rs:20`),畫面上只有零星的「在大腦上」小字。) 搜尋標題開頭 > 標題包含 > 說明包含,最多 12 筆,選了就跳過去、標亮、游標放進那個欄位; 每列固定樣式:左邊標題+說明、右邊動作,至少 64 px 高;警告用整條橫幅+右邊按鈕;刪除類集中在最下面「危險區」,確認框預設停在「取消」。 diff --git a/src/app.rs b/src/app.rs index d5156d8..97d7390 100644 --- a/src/app.rs +++ b/src/app.rs @@ -45,6 +45,7 @@ mod tasks_ui; mod me_ui; mod activity_ui; mod library_ui; +mod settings_find; mod memory_ui; mod goal_ui; mod context_ui; @@ -246,6 +247,8 @@ pub struct App { page_toc_open: bool, /// 設定 › 一般 › 外觀: the less used dials (底色、對比、密度、慶祝動畫、重設) unfolded. appearance_more: bool, + /// 搜尋設定: what is typed in the settings window's search (settings_find.rs). + settings_q: String, /// A heading the 目錄 asked to jump to (consumed by the frame that draws it). page_goto: Option, /// Heading rects the Markdown renderer measured for the page it last drew (article mode), @@ -555,6 +558,7 @@ impl App { page_find: String::new(), page_toc_open: false, appearance_more: false, + settings_q: String::new(), page_goto: None, md_head_rects: Vec::new(), popup_hidden: Default::default(), @@ -5843,6 +5847,45 @@ impl App { ui.set_min_height(page_h - 24.0); ui.vertical(|ui| { ui.spacing_mut().item_spacing.y = 2.0; + // 搜尋設定 (settings_find.rs): while something is typed, the settings that match + // stand where the pages were; Enter takes the first, Esc empties the box. + let search = Frame::new() + .fill(p.elevated) + .stroke(Stroke::new(1.0, p.border)) + .corner_radius(R_M) + .inner_margin(Margin::symmetric(8, 5)) + .show(ui, |ui| ui.add(egui::TextEdit::singleline(&mut self.settings_q).hint_text(t("搜尋設定…")).frame(Frame::NONE).desired_width(f32::INFINITY))) + .inner; + ui.add_space(6.0); + if !self.settings_q.trim().is_empty() { + if ui.input(|i| i.key_pressed(Key::Escape)) { + ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, Key::Escape)); + self.settings_q.clear(); + } + let hits = settings_find::find(&self.settings_q); + let mut go = (search.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter))).then(|| hits.first().map(|h| h.target.clone())).flatten(); + if hits.is_empty() { + ui.label(RichText::new(t("沒有符合的設定")).size(FONT_SM).color(p.text3)); + } + let w = ui.available_width(); + for (i, h) in hits.iter().enumerate() { + let (rect, r) = ui.allocate_exact_size(vec2(w, 44.0), egui::Sense::click()); + if r.hovered() || (i == 0 && search.has_focus()) { + ui.painter().rect_filled(rect, R_M, p.hover); + } + let title = sidebar_ui::shorten_width(ui, &h.title, w - 20.0, FONT_SM); + let path = sidebar_ui::shorten_width(ui, &h.path, w - 20.0, FONT_XS); + ui.painter().text(rect.left_top() + vec2(10.0, 6.0), egui::Align2::LEFT_TOP, title, egui::FontId::proportional(FONT_SM), p.text); + ui.painter().text(rect.left_top() + vec2(10.0, 25.0), egui::Align2::LEFT_TOP, path, egui::FontId::proportional(FONT_XS), p.text3); + if r.on_hover_text(format!("{} · {}", h.title, h.path)).on_hover_cursor(egui::CursorIcon::PointingHand).clicked() { + go = Some(h.target.clone()); + } + } + if let Some(target) = go { + self.settings_go(ctx, &target); + self.settings_q.clear(); + } + } else { use crate::icons::Icon; for (tab, name, icon) in [(SettingsTab::General, "一般", Icon::Gear), (SettingsTab::Me, "個人資料", Icon::Person), (SettingsTab::Providers, "模型", Icon::Sparkle), (SettingsTab::Channels, "整合", Icon::Chat), (SettingsTab::Computers, "電腦", Icon::Monitor), (SettingsTab::Review, "權限", Icon::Shield), (SettingsTab::Vault, "保險庫", Icon::Vault), (SettingsTab::Voice, "語音", Icon::Mic), (SettingsTab::Updates, "更新", Icon::CloudDownload)] { let (rect, r) = ui.allocate_exact_size(vec2(ui.available_width(), 38.0), egui::Sense::click()); @@ -5862,6 +5905,7 @@ impl App { self.settings_tab = tab; } } + } }); }); let r = ui.min_rect(); diff --git a/src/app/kit.rs b/src/app/kit.rs index 01ec876..c1f9ee1 100644 --- a/src/app/kit.rs +++ b/src/app/kit.rs @@ -30,7 +30,7 @@ pub(super) fn section(ui: &mut egui::Ui, title: &str, p: Palette) { /// A section heading with something at its right end (a name, a button). pub(super) fn section_with(ui: &mut egui::Ui, title: &str, p: Palette, accessory: impl FnOnce(&mut egui::Ui)) { ui.add_space(sp::S5); - ui.horizontal(|ui| { + let r = ui.horizontal(|ui| { ui.add_space(sp::S1); ui.label(RichText::new(t(title)).size(FONT_SM).family(crate::bold()).color(p.text2)); ui.with_layout(Layout::right_to_left(Align::Center), |ui| { @@ -38,6 +38,7 @@ pub(super) fn section_with(ui: &mut egui::Ui, title: &str, p: Palette, accessory accessory(ui); }); }); + super::settings_find::jump_mark(ui, title, r.response.rect, p); ui.add_space(sp::S2); } @@ -107,6 +108,7 @@ pub(super) fn card_row(ui: &mut egui::Ui, p: Palette, label: &str, sub: &str, he } let h = if sub.is_empty() { 52.0 } else { 62.0 }; let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), h), egui::Sense::hover()); + super::settings_find::jump_mark(ui, label, rect, p); let row_hovered = ui.rect_contains_pointer(rect); // The control first, from the right edge; the words get the room that is left. let mut right = ui.new_child(egui::UiBuilder::new().max_rect(rect).layout(Layout::right_to_left(Align::Center))); @@ -153,11 +155,12 @@ pub(super) fn segmented(ui: &mut egui::Ui, p: Palette, cur: } pub(super) fn setting_title(ui: &mut egui::Ui, title: &str, desc: &str, p: Palette) { - ui.horizontal(|ui| { + let r = ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 4.0; ui.label(RichText::new(t(title)).strong().family(crate::bold()).size(FONT_BASE)); help_mark(ui, desc, p); }); + super::settings_find::jump_mark(ui, title, r.response.rect, p); ui.add_space(4.0); } diff --git a/src/app/layout_audit.rs b/src/app/layout_audit.rs index 766eefd..2758714 100644 --- a/src/app/layout_audit.rs +++ b/src/app/layout_audit.rs @@ -154,6 +154,13 @@ fn scenes() -> Vec<(&'static str, Open)> { ), ("設定 › 模型", tab(SettingsTab::Providers)), ("設定 › 個人資料", tab(SettingsTab::Me)), + ( + "設定 › 搜尋", + Box::new(|a: &mut App| { + a.show_settings = true; + a.settings_q = "自動".into(); + }), + ), ( "所有檔案", Box::new(|a: &mut App| { diff --git a/src/app/settings_find.rs b/src/app/settings_find.rs new file mode 100644 index 0000000..cee3958 --- /dev/null +++ b/src/app/settings_find.rs @@ -0,0 +1,377 @@ +// 搜尋設定 (plan C3): every setting a person might look for — which page it is on, under which +// heading, and the other words they might type for it. The settings window's left column searches +// it (title starts with what was typed, then title contains it, then the heading or the other +// words do; at most 12); picking one turns to its page (and the page inside it), scrolls the row +// into view and outlines it for a moment — `jump_mark`, which the kit's headings and rows call. +// A test keeps the list whole: every heading and row title the settings pages draw is in it (or +// said here why not). + +use super::channels_ui::Page; +use super::*; +use std::cell::RefCell; + +pub(super) struct Entry { + pub tab: SettingsTab, + /// The heading it is under, as the page shows it (「外觀」); for a whole page, the page. + pub place: &'static str, + /// The row or heading as drawn — what is outlined; empty: the page itself. + pub title: &'static str, + /// Other words for it: what it does, what people call it. + pub words: &'static str, + /// How to get there inside the page (a folded row, the 整合 page's own pages). + pub open: Option, +} + +const fn e(tab: SettingsTab, place: &'static str, title: &'static str, words: &'static str) -> Entry { + Entry { tab, place, title, words, open: None } +} + +const fn o(tab: SettingsTab, place: &'static str, title: &'static str, words: &'static str, open: fn(&mut App)) -> Entry { + Entry { tab, place, title, words, open: Some(open) } +} + +fn more_look(a: &mut App) { + a.appearance_more = true; +} +fn ch_channels(a: &mut App) { + a.ch.sub = 0; +} +fn ch_mcp(a: &mut App) { + a.ch.sub = 1; + a.ch.mcp_page = Page::List; +} +fn ch_mcp_market(a: &mut App) { + a.ch.sub = 1; + a.ch.mcp_page = Page::Market; +} +fn ch_mcp_add(a: &mut App) { + a.ch.sub = 1; + a.ch.mcp_page = Page::Add; +} +fn ch_skills(a: &mut App) { + a.ch.sub = 2; + a.ch.skill_page = Page::List; +} +fn ch_skill_market(a: &mut App) { + a.ch.sub = 2; + a.ch.skill_page = Page::Market; +} + +use SettingsTab as S; + +pub(super) const INDEX: &[Entry] = &[ + // 一般 + e(S::General, "一般", "", "設定 general"), + e(S::General, "外觀", "外觀", "樣子 顏色 appearance"), + e(S::General, "外觀", "主題", "淺色 深色 跟著系統 深色模式 夜間 dark mode light theme"), + e(S::General, "外觀", "強調色", "選中項 連結 新訊息點 圖表 accent color"), + e(S::General, "外觀", "聊天的顏色", "泡泡 訊息顏色 跟著 Bot 只用黑色 安靜"), + e(S::General, "外觀", "語言", "中文 英文 English 選單 回答的語言 language"), + e(S::General, "外觀", "更多外觀設定", "展開"), + o(S::General, "外觀", "底色", "色溫 藍灰 米白 背景", more_look), + o(S::General, "外觀", "對比", "分層 細線 文字階級 contrast", more_look), + o(S::General, "外觀", "密度", "緊湊 行距 按鈕大小 density", more_look), + o(S::General, "外觀", "慶祝動畫", "彩帶 動畫 完成", more_look), + o(S::General, "外觀", "外殼顏色重設", "預設 紙 還原 reset", more_look), + e(S::General, "記憶與文件", "記憶與文件", ""), + e(S::General, "記憶與文件", "用意思找記憶", "語意搜尋 向量 embedding 本機模型 Ollama 關閉"), + e(S::General, "記憶與文件", "Bot 可以翻的資料夾", "文件 資料夾 搜尋 md txt csv 程式碼 知識庫"), + e(S::General, "通知", "通知", "notification"), + e(S::General, "通知", "Bot 做完或等你時通知", "推播 提醒 手機通知"), + e(S::General, "通知", "需要你時響一聲", "聲音 音效 鈴聲 sound"), + e(S::General, "Bot", "Bot", ""), + e(S::General, "Bot", "時區", "Asia/Taipei 例行任務 提醒 時間 timezone"), + e(S::General, "帳戶", "帳戶", "登入 帳號 管理帳戶 account"), + e(S::General, "帳戶", "資料放在哪", "資料夾 Finder 聊天記錄 金鑰 data"), + // 一般 › 手機與帳號 + e(S::Remote, "手機與帳號", "手機與帳號", "手機 iPhone Android phone"), + e(S::Remote, "手機與帳號", "AnyBot 帳號", "登入 登出 帳號伺服器 換網址 註冊 邀請碼 驗證碼 密碼"), + e(S::Remote, "手機與帳號", "同一個網路直接連", "Wi-Fi 區網 Tailscale 手機密碼 直接連線"), + e(S::Remote, "手機與帳號", "手機可以做什麼", "手機權限"), + e(S::Remote, "手機與帳號", "直接連線的裝置", "登出 裝置 瀏覽器"), + e(S::Remote, "手機與帳號", "分享給團隊", "團隊 同事 成員 team"), + e(S::Remote, "手機與帳號", "帳號裡的電腦", "大腦 手腳 螢幕 其他電腦 裝置"), + // 個人資料 + e(S::Me, "個人資料", "", "名字 活躍日 Token 連續天數 最活躍 訊息數 profile"), + e(S::Me, "個人資料", "活動", "熱度 一年 格子 activity"), + e(S::Me, "個人資料", "用量", "花費 費用 token 呼叫次數 帳單 用了多少 billing usage cost"), + // 模型 (each provider is added by `find`) + e(S::Providers, "模型", "", "供應商 API 金鑰 key provider model"), + // 整合 + e(S::Channels, "整合", "", "integrations"), + o(S::Channels, "訊息管道", "", "Slack Discord Telegram Teams iMessage 郵件 email 簡訊 SMS X 管道 channel", ch_channels), + o(S::Channels, "連接器", "連接器(MCP)", "MCP 伺服器 工具 GitHub Notion connector", ch_mcp), + o(S::Channels, "連接器", "連接器市集", "市集 MCP Registry 公用市集 加入", ch_mcp_market), + o(S::Channels, "連接器", "新增連接器", "自訂 指令 網址 環境變數 標頭", ch_mcp_add), + o(S::Channels, "技能", "技能", "SKILL.md 技能庫 作業流程 skill", ch_skills), + o(S::Channels, "技能", "內建技能包", "技能市集", ch_skill_market), + o(S::Channels, "技能", "Anthropic 開源技能", "技能市集", ch_skill_market), + o(S::Channels, "技能", "從 GitHub、網址或資料夾安裝", "安裝技能", ch_skill_market), + // 電腦 + e(S::Computers, "電腦", "", "computer"), + e(S::Computers, "你的電腦", "你的電腦", "重新命名 這台電腦 名字"), + e(S::Computers, "你的電腦", "在這台電腦上執行", "一律允許 每次詢問 永不允許 本機 本地"), + e(S::Computers, "你的電腦", "經這台電腦轉送流量", "代理 proxy 出口 IP"), + e(S::Computers, "你的電腦", "其他電腦", ""), + e(S::Computers, "你的電腦", "讓帳號裡的其他電腦使用這台", "裝置連結 遠端 操作這台"), + e(S::Computers, "訊息", "訊息", "Messages"), + e(S::Computers, "訊息", "傳送訊息", "iMessage 簡訊 Messages"), + e(S::Computers, "訊息", "無需詢問直接傳送", "不用核准"), + e(S::Computers, "Bot 的電腦", "Bot 的電腦", "Docker Linux 容器 box 沙盒"), + e(S::Computers, "Bot 的電腦", "在大腦上", ""), + e(S::Computers, "Bot 的電腦", "更新 Bot 的電腦", ""), + e(S::Computers, "Bot 的電腦", "自動更新", "Bot 的電腦自動更新"), + e(S::Computers, "Bot 的電腦", "重設 Bot 的電腦", "重設 清空 reset"), + e(S::Computers, "Bot 的電腦", "磁碟", "空間 清理 容量 disk"), + e(S::Computers, "終端機與環境密鑰", "終端機與環境密鑰", "環境變數 secret 金鑰 env"), + e(S::Computers, "在哪裡執行", "在哪裡執行", ""), + e(S::Computers, "在哪裡執行", "Docker 主機", "DOCKER_HOST 遠端 Docker"), + e(S::Computers, "在哪裡執行", "容器隔離", "gVisor runsc 安全"), + e(S::Computers, "瀏覽器", "AnyBot 瀏覽器設定檔", "Chrome 瀏覽器 登入 設定檔 profile"), + e(S::Computers, "瀏覽器", "做完就關掉瀏覽器", "關閉瀏覽器"), + e(S::Computers, "瀏覽器", "發布前檢查", "簡體字 AI 腔 送出前檢查 留言 貼文"), + e(S::Computers, "AnyBot Computer Use", "AnyBot Computer Use", "操作畫面 computer use"), + e(S::Computers, "AnyBot Computer Use", "看畫面和操作", ""), + e(S::Computers, "AnyBot Computer Use", "螢幕錄製", "權限 macOS 看螢幕"), + e(S::Computers, "AnyBot Computer Use", "輔助使用", "Accessibility 權限 點擊 打字"), + e(S::Computers, "AnyBot Computer Use", "授予權限", "系統設定 隱私權"), + e(S::Computers, "AnyBot Computer Use", "一律允許的應用程式", "App 應用程式 允許"), + e(S::Computers, "示範教學", "示範教學", "教 錄製 示範"), + // 權限 + e(S::Review, "權限", "", "安全 核准 允許 permission"), + e(S::Review, "權限", "直接操作", "不用問"), + e(S::Review, "權限", "智慧模式", ""), + e(S::Review, "權限", "一律放行", "全部允許"), + e(S::Review, "權限", "自動審核", "審核員 review"), + // 保險庫、語音 + e(S::Vault, "保險庫", "", "密碼 帳密 登入資訊 鑰匙圈 vault password"), + e(S::Voice, "語音", "語音服務", "voice"), + e(S::Voice, "語音", "聽(語音轉文字)", "語音輸入 聽寫 Whisper STT 轉文字 會議錄音"), + e(S::Voice, "語音", "說(朗讀)", "朗讀 TTS 唸出來 聲音"), + // 更新 + e(S::Updates, "更新", "AnyBot 更新", "新版本 升級 update"), + e(S::Updates, "更新", "版本", "version 哪一版"), + e(S::Updates, "更新", "自動更新", "離開時更新"), + e(S::Updates, "更新", "園丁報告", "例行任務 失敗 走冤枉路"), + e(S::Updates, "更新", "待改進", "改進 回報 回饋"), + e(S::Updates, "疑難排解", "疑難排解", ""), + e(S::Updates, "疑難排解", "重新啟動", "重開 restart 卡住 不對勁"), +]; + +/// Titles the settings pages draw that aren't searched for, and why. +#[cfg(test)] +const NOT_SEARCHED: &[&str] = &[ + // The connector list's own headings and one connector's page: names, not settings. + "已加入", + "設定", +]; + +/// Where a hit leads. +#[derive(Clone)] +pub(super) enum Target { + Entry(usize), + Provider(crate::providers::ProviderKind), +} + +pub(super) struct Hit { + pub title: String, + pub path: String, + pub target: Target, +} + +/// A page's name in the list (and in a hit's path). +pub(super) fn tab_name(tab: SettingsTab) -> &'static str { + match tab { + S::General => "一般", + S::Remote => "一般 › 手機與帳號", + S::Me => "個人資料", + S::Providers => "模型", + S::Channels => "整合", + S::Computers => "電腦", + S::Review => "權限", + S::Vault => "保險庫", + S::Voice => "語音", + S::Updates => "更新", + } +} + +const MAX_HITS: usize = 12; + +/// What matches: titles that start with it, then titles that contain it, then the heading or the +/// other words. +pub(super) fn find(q: &str) -> Vec { + let q = q.trim().to_lowercase(); + if q.is_empty() { + return vec![]; + } + let mut hits: Vec<(u8, usize, Hit)> = vec![]; + for (i, x) in INDEX.iter().enumerate() { + let title = if x.title.is_empty() { x.place } else { x.title }; + let tl = t(title).to_lowercase(); + let rank = if tl.starts_with(&q) || title.to_lowercase().starts_with(&q) { + 0 + } else if tl.contains(&q) || title.to_lowercase().contains(&q) { + 1 + } else if x.place.to_lowercase().contains(&q) || x.words.to_lowercase().contains(&q) { + 2 + } else { + continue; + }; + let (page, place) = (t(tab_name(x.tab)), t(x.place)); + let path = if x.title.is_empty() && x.place == tab_name(x.tab) { + t("設定頁") + } else if x.title.is_empty() || page.ends_with(&place) { + page + } else { + format!("{page} › {place}") + }; + hits.push((rank, i, Hit { title: t(title), path, target: Target::Entry(i) })); + } + for (j, k) in crate::providers::ALL_PROVIDERS.into_iter().enumerate() { + let name = k.label().to_lowercase(); + let rank = if name.starts_with(&q) { + 0 + } else if name.contains(&q) { + 1 + } else { + continue; + }; + hits.push((rank, INDEX.len() + j, Hit { title: k.label().to_string(), path: t("模型"), target: Target::Provider(k) })); + } + hits.sort_by_key(|(rank, i, _)| (*rank, *i)); + hits.into_iter().take(MAX_HITS).map(|(_, _, h)| h).collect() +} + +impl App { + /// Go to what was picked: its page, the page inside it, then outline its row. + pub(super) fn settings_go(&mut self, ctx: &egui::Context, target: &Target) { + match target { + Target::Entry(i) => { + let x = &INDEX[*i]; + self.settings_tab = x.tab; + if let Some(open) = x.open { + open(self); + } + if !x.title.is_empty() { + jump_to(ctx, x.title); + } + } + Target::Provider(k) => { + self.settings_tab = SettingsTab::Providers; + self.settings_provider = *k; + } + } + } +} + +// ── The outline ── + +struct Jump { + title: String, + /// When it was asked for, then when its row was first drawn. + at: f64, + drawn: bool, +} + +thread_local! { + static JUMP: RefCell> = const { RefCell::new(None) }; +} + +/// How long the outline stays; a row never drawn (on another page, folded away) is given up after +/// as long. +const LIT_SECS: f64 = 1.8; + +pub(super) fn jump_to(ctx: &egui::Context, title: &str) { + let now = ctx.input(|i| i.time); + JUMP.with(|j| *j.borrow_mut() = Some(Jump { title: title.to_string(), at: now, drawn: false })); + ctx.request_repaint(); +} + +/// Called with each heading and row as it is drawn: the one searched for is scrolled into view +/// (once) and outlined, fading. +pub(super) fn jump_mark(ui: &egui::Ui, title: &str, rect: egui::Rect, p: Palette) { + JUMP.with(|j| { + let mut j = j.borrow_mut(); + let Some(x) = j.as_mut() else { return }; + let now = ui.input(|i| i.time); + if now - x.at > LIT_SECS { + *j = None; + return; + } + if x.title != title { + return; + } + if !x.drawn { + ui.scroll_to_rect(rect, Some(Align::Center)); + x.drawn = true; + x.at = now; + } + let fade = (1.0 - (now - x.at) / LIT_SECS).clamp(0.0, 1.0) as f32; + ui.painter().rect_stroke(rect.expand(3.0), R_M, Stroke::new(2.0, p.accent.gamma_multiply(fade)), egui::StrokeKind::Outside); + ui.ctx().request_repaint_after(anim_after(40)); + }); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn what_is_typed_finds_titles_first_then_other_words() { + let titles = |q: &str| find(q).into_iter().map(|h| h.title).collect::>(); + // A title that starts with it comes before one that only contains it. + let mut v = titles("自動"); + v.truncate(3); + v.sort(); + assert_eq!(v, ["自動審核", "自動更新", "自動更新"]); + let v = titles("更新"); + assert!(v.iter().position(|x| x == "更新 Bot 的電腦") < v.iter().position(|x| x == "AnyBot 更新"), "{v:?}"); + // Other words find the row: 深色 is the 主題 row; billing is 用量. + assert_eq!(titles("深色")[0], "主題"); + assert_eq!(titles("billing")[0], "用量"); + // A provider by its name, on 模型. + let h = find("ollama"); + assert!(h.iter().any(|h| matches!(h.target, Target::Provider(crate::providers::ProviderKind::Ollama)) && h.path == "模型"), "{:?}", h.iter().map(|h| &h.title).collect::>()); + // The path names the page and the heading. + let h = find("時區"); + assert_eq!((h[0].title.as_str(), h[0].path.as_str()), ("時區", "一般 › Bot")); + assert!(find(" ").is_empty() && find("沒有這種設定xyz").is_empty()); + assert!(find("的").len() <= MAX_HITS); + } + + /// Every heading and row title the settings pages draw can be searched for — a new setting + /// that isn't added to INDEX fails here — and nothing in INDEX is gone from the pages. + #[test] + fn every_setting_on_the_pages_is_in_the_search() { + let sources: Vec<(&str, &str)> = vec![ + ("app.rs", include_str!("../app.rs")), + ("remote_ui.rs", include_str!("remote_ui.rs")), + ("vault_ui.rs", include_str!("vault_ui.rs")), + ("voice_ui.rs", include_str!("voice_ui.rs")), + ("channels_ui.rs", include_str!("channels_ui.rs")), + ("computers_ui.rs", include_str!("computers_ui.rs")), + ("me_ui.rs", include_str!("me_ui.rs")), + ]; + let heads = ["section(ui, \"", "section_with(ui, \"", "setting_title(ui, \"", "card_row(ui, p, \"", "sec_title(ui, \"", "sec_row(ui, p, \"", "sec_row_s(ui, p, \""]; + let mut drawn: Vec = vec![]; + for (file, src) in &sources { + // The Bot editor (in app.rs) isn't a settings page. + let src = if *file == "app.rs" { src.split("fn bot_editor(").next().unwrap_or("").to_string() + src.split("fn bot_editor(").nth(1).and_then(|r| r.split_once("\n fn ").map(|(_, rest)| rest)).unwrap_or("") } else { src.to_string() }; + for h in heads { + for part in src.split(h).skip(1) { + if let Some(name) = part.split('"').next().filter(|n| !n.is_empty()) { + drawn.push(name.to_string()); + } + } + } + } + drawn.sort(); + drawn.dedup(); + assert!(drawn.len() > 60, "the scan found too little: {drawn:?}"); + let listed: Vec<&str> = INDEX.iter().map(|x| x.title).filter(|x| !x.is_empty()).collect(); + let missing: Vec<&String> = drawn.iter().filter(|d| !listed.contains(&d.as_str()) && !NOT_SEARCHED.contains(&d.as_str())).collect(); + assert!(missing.is_empty(), "settings_find.rs INDEX doesn't have these settings (add them, with the words people would type): {missing:?}"); + let gone: Vec<&&str> = listed.iter().filter(|l| !drawn.iter().any(|d| d == *l)).collect(); + assert!(gone.is_empty(), "INDEX lists titles no settings page draws any more: {gone:?}"); + } +}