From 45c529d7f483dfca698b7f4082872f8772c932fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Sun, 22 Nov 2026 09:38:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=89=8B=E6=A9=9F=E6=8E=A5=E7=AE=A1?= =?UTF-8?q?=E9=9B=BB=E8=85=A6=E5=BE=8C=E5=9B=9E=E4=B8=8D=E5=8E=BB=EF=BC=9B?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E3=80=8C=E9=A2=A8=E6=A0=BC=E3=80=8D=EF=BC=88?= =?UTF-8?q?8=20=E5=A5=97=EF=BC=9A=E7=B4=99=E3=80=81=E5=A4=9C=E3=80=81?= =?UTF-8?q?=E5=A2=A8=E3=80=81=E8=8B=94=E3=80=81=E6=B5=B7=E3=80=81=E7=B3=96?= =?UTF-8?q?=E3=80=81=E5=A4=95=E9=99=BD=E3=80=81=E7=B5=82=E7=AB=AF=E6=A9=9F?= =?UTF-8?q?=EF=BC=8C=E4=B8=80=E5=A5=97=E9=A1=8F=E8=89=B2=E5=8A=A0=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E8=83=8C=E6=99=AF=E8=8A=B1=E7=B4=8B=EF=BC=8C=E9=9B=BB?= =?UTF-8?q?=E8=85=A6=E5=92=8C=E6=89=8B=E6=A9=9F=E4=B8=80=E8=B5=B7=E6=8F=9B?= =?UTF-8?q?=EF=BC=8C=E4=B9=9F=E8=83=BD=E8=AB=8B=20Bot=20=E6=8F=9B=EF=BC=89?= =?UTF-8?q?=EF=BC=9B=E8=A8=AD=E5=AE=9A=E6=AF=8F=E4=B8=80=E5=88=97=E9=83=BD?= =?UTF-8?q?=E6=9C=89=E5=9C=96=E7=A4=BA=EF=BC=88=E9=9B=BB=E8=85=A6=E5=92=8C?= =?UTF-8?q?=E6=89=8B=E6=A9=9F=EF=BC=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 接管回不去(mobile/index.html newBoxFrame):以前每次打開/關掉都改同一個 iframe 的網址,iframe 換頁會加進上一頁紀錄;第二次之後按 ✕ 或返回,退的是框裡那一頁,接管畫面卡著。現在每次換一個新的框,關掉就拿掉。舊版重現:第 2、3 次關不掉;新版連續 3 次都回到首頁。 - 風格(src/theme.rs TEMPLATES、palette_for、backdrop):每套有淺色和深色的墨、紙、強調色(同一個產生器長出整個殼),加聊天背景 dots/grid/waves。State 新欄位 shell_template(空=自訂)。電腦:設定 › 一般 › 外觀最上面一排小圖(kit::style_gallery,每張是那個風格的縮小畫面),聊天區後面畫花紋(chat_backdrop);點強調色、動底色或重設回到自訂。手機:palettes 帶 backdrop,聊天背景用 CSS 畫;設定 › 一般最上面同一排小圖(api/settings 的 styles、style)。Bot:update_settings 多 `style`(appctl;不在 tools::specs 的鎖檔裡,鎖檔沒變)。截圖:ANYBOT_SHOT_STYLE=ocean。 - 設定圖示:icons::setting_icon 照名字的字配圖示(主題月亮、風格和顏色調色盤、通知鈴鐺、時區地球、權限盾牌、電腦螢幕…,沒對到是滑桿),card_row 和 setting_title 都畫;新 Lucide 圖示 palette、moon、globe、sliders-horizontal、volume-2、hard-drive。手機設定頁、Bot 設定、電腦頁的列用 sitem(同一套規則,SET_ICON)。 - 測試:theme::template_tests::every_template_reads_in_light_and_dark(每套淺深色都讀得清楚、紙就是原本的預設);appctl 的 update_settings 測試加 style。 - 功能地圖 appearance.md 加 appearance-style 和一步驗證、settings.md(Bot 能改四樣)、box.md 陷阱;FEATURES.md。 已驗證: cargo test 881 個全過;clippy 沒有新警告;scratch 手機:接管開關 3 次都回首頁(舊版第 2 次就卡住);設定 › 一般點「海」→ state shell_template=ocean、聊天背景波浪;聊天請 Bot `update_settings {"style":"terminal"}` → 手機強調色 #2d8a3e、格線;Bot 設定 36 列都有圖示。桌面截圖:外觀的 8 張小圖、海、終端機(深色)、糖的聊天,電腦設定一般/電腦頁每列有圖示。 未驗證: 在真的 iPhone 上滑返回手勢(接管開著時本來就停用,靠 ✕);花紋在很大的螢幕上的耗電(電腦版每幀畫點點/線,沒量)。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm --- FEATURES.md | 2 + docs/feature-map/appearance.md | 4 +- docs/feature-map/box.md | 1 + docs/feature-map/settings.md | 4 +- icons/lucide/globe.svg | 17 ++++ icons/lucide/hard-drive.svg | 18 ++++ icons/lucide/moon.svg | 15 ++++ icons/lucide/palette.svg | 19 +++++ icons/lucide/sliders-horizontal.svg | 23 ++++++ icons/lucide/volume-2.svg | 17 ++++ mobile/index.html | 124 +++++++++++++++++++--------- src/app.rs | 76 ++++++++++++++++- src/app/kit.rs | 64 +++++++++++++- src/app/remote_ui.rs | 13 ++- src/appctl.rs | 24 +++++- src/icons.rs | 59 +++++++++++++ src/model.rs | 4 + src/theme.rs | 69 ++++++++++++++++ 18 files changed, 500 insertions(+), 53 deletions(-) create mode 100644 icons/lucide/globe.svg create mode 100644 icons/lucide/hard-drive.svg create mode 100644 icons/lucide/moon.svg create mode 100644 icons/lucide/palette.svg create mode 100644 icons/lucide/sliders-horizontal.svg create mode 100644 icons/lucide/volume-2.svg diff --git a/FEATURES.md b/FEATURES.md index a250786..7702bf3 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -2169,6 +2169,8 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - 字級 7 階:說明 12(時間、標記、圖表軸)、小字 13(說明、次要)、介面 14(按鈕、清單、輸入框、設定列)、閱讀 16(回答、頁面內文、輸入框裡你打的字)、小標 18、中標 22、大標 28。 - 行高:閱讀字 1.7 倍(16 px 字 27 px 行),介面字 20,小字 18,標題 26/30/36。 - 間距:4、8、12、16、24、32。 +- **風格**(設定 › 一般 › 外觀最上面一排小圖;手機 設定 › 一般 最上面同一排;Bot 用 `update_settings` 的 `style`):一次換整套樣子——淺色和深色各一組墨、紙、強調色(`theme::TEMPLATES`,從同一個產生器長出整個殼),加上聊天背景的花紋:紙(預設)、夜、墨、苔(點點)、海(波浪)、糖(點點)、夕陽(波浪)、終端機(黑底綠字、格線)。每張小圖是那個風格的縮小畫面(側邊欄、字、你的泡泡、強調色、花紋),現在用的有一圈強調色。電腦和手機一起換;點強調色、動「底色」或「外殼顏色重設」回到自訂。 +- **設定每一列都有圖示**:照名字裡的字配(`icons::setting_icon`/手機的 `setIcon`:主題月亮、風格和顏色調色盤、通知鈴鐺、時區地球、權限盾牌、電腦螢幕…),沒對到的是滑桿;電腦和手機同一套。 - 圓角三種:6(標籤、色塊、小控制項)、10(輸入框、程式碼、提示框)、14(卡片、對話框、面板);按鈕、分段選擇是膠囊(跟手機、macOS 26 一樣:形狀本身就說「可以按」,不用框)。 - 浮在上面的東西(聊天的輸入框、工作流畫布上的工具列和面板、選單)用一層柔和陰影浮起來(調色盤的 `shade`,手機的 `--shade`),不靠粗框線;平放的卡片用細框和底色分組。 - 中文和英文用 Apple 的一對字(SF Pro+蘋方),基準線和大小對得齊;沒有蘋方時用思源黑體,缺的字用系統字型補。程式碼用 **SF Mono**,沒有就用 Menlo。 diff --git a/docs/feature-map/appearance.md b/docs/feature-map/appearance.md index 72c4024..f36d490 100644 --- a/docs/feature-map/appearance.md +++ b/docs/feature-map/appearance.md @@ -4,6 +4,7 @@ AnyBot 長什麼樣子、用什麼語言,和怎麼聽、怎麼說:設定 › ## 子功能 +- `appearance-style` 風格(外觀最上面一排小圖,每張就是那個風格的樣子):紙(預設)、夜、墨、苔(點點)、海(波浪)、糖(點點)、夕陽(波浪)、終端機(格線)——一套淺色和深色的顏色,加上聊天背景的花紋;電腦和手機一起換(手機 設定 › 一般 最上面同一排)。點下面的強調色或動「底色」回到自訂(小圖下寫「現在是自訂的顏色」)。 - `appearance-theme` 主題:淺色/深色/跟隨系統;手機的外觀預設跟著電腦([phone](phone.md))。 - `appearance-colors` 強調色(八個點:黏土、靛藍、苔綠、藍綠、玫紅、琥珀、石板、墨黑)、聊天的顏色(你的訊息泡泡:安靜=淡灰,預設;跟著 Bot;只用黑色——手機同一個設定;只有點,選中的有外圈)。 - `appearance-language` 語言:選單和 Bot 回答用的語言。 @@ -20,7 +21,7 @@ AnyBot 長什麼樣子、用什麼語言,和怎麼聽、怎麼說:設定 › ## 怎麼操作(verify-anybot) -- Bot:`update_settings` 改得到 `theme`(light/dark/system)和 `accent`(quiet/bot_color/black,聊天的顏色),其他外觀和語音設定告訴使用者在哪裡([settings](settings.md))。 +- Bot:`update_settings` 改得到 `theme`(light/dark/system)、`style`(風格)和 `accent`(quiet/bot_color/black,聊天的顏色),其他外觀和語音設定告訴使用者在哪裡([settings](settings.md))。 前提: @@ -28,6 +29,7 @@ AnyBot 長什麼樣子、用什麼語言,和怎麼聽、怎麼說:設定 › - **Bot 換深色**(covers `appearance-theme`、`appearance-language`):請 Bot 換深色。指令:`$CTL phone send '換深色 [[call update_settings {"theme":"dark"}]]' && $CTL phone wait-text '主題 → dark' --in '#msgs' && $CTL phone wait 'html[data-theme="dark"]' && $CTL phone shot appearance-dark && $CTL state .theme && $CTL model 'select(.kind == "call") | .user'`。看到:手機不用重新整理就變深色;大腦存成 Dark;Bot 收到的訊息後面帶著語言的提示〔用繁體中文和台灣用語回答…〕。 - **手機上改主題、聊天的顏色**(covers `appearance-theme`、`appearance-colors`):重新整理,帳戶選單 › 設定 › 一般,主題選「淺色」,聊天的顏色選「跟著 Bot」。指令:`$CTL phone open --listed && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 設定 && $CTL phone click '[data-go="general"]' && $CTL phone click '[data-s="theme"]' && $CTL phone click '#sheet-in .opt' --text 淺色 && $CTL phone wait 'html[data-theme="light"]' && $CTL phone click '[data-s="accent"]' && $CTL phone click '#sheet-in .opt' --text 跟著 && $CTL phone wait-text '跟著 Bot' --in '#list' && $CTL api GET /api/settings --jq '{theme, accent}'`。看到:選了馬上變淺色;聊天的顏色寫「跟著 Bot」;大腦那邊 light、bot_color。 +- **換風格**(covers `appearance-style`):手機 設定 › 一般 點「海」,再請 Bot 換成終端機。指令:`$CTL phone click '[data-go="general"]' && $CTL phone click '[data-style="ocean"]' && $CTL phone wait-text 換好了 --in '#toast' && $CTL state '.shell_template' && $CTL phone js 'document.documentElement.dataset.backdrop' && $CTL phone send '換終端機 [[call update_settings {"style":"terminal"}]]' && $CTL wait-api /api/settings '.style == "terminal"'`。看到:ocean、waves(聊天背景變波浪);Bot 換完 style 是 terminal;桌面 `ANYBOT_SHOT_STYLE=terminal` 的截圖是黑底綠字加格線。 - **重開還在**(covers `appearance-theme`、`appearance-colors`):指令:`$CTL restart && $CTL api GET /api/settings --jq '{theme, accent}' && $CTL phone open --listed && $CTL phone wait 'html[data-theme="light"]'`。看到:重開後還是 light、bot_color。 - **語音還沒設定**(covers `appearance-voice`):打開聊天,看輸入框,請大腦唸一句。指令:`$CTL phone click '.row[data-bot="1"]' && $CTL phone wait '#input' && $CTL phone wait-gone '#b-mic' && $CTL api GET '/api/state?since=0' --jq '.voice' && $CTL api --expect 409 POST /api/voice/speech '{"text":"你好"}'`。看到:沒有「開始語音輸入」;聽、說都是 false;唸一句回「還沒設定語音:請到「設定 → 語音」選一個服務。」 - **桌面的外觀、語音**(covers `appearance-colors`、`appearance-more`、`appearance-fonts`、`appearance-language`、`appearance-voice`、`appearance-voices`):指令:要開視窗——`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot appearance ANYBOT_SHOT_VIEW=general && ABV_ALLOW_WINDOW=1 $CTL desktop-shot voice ANYBOT_SHOT_VIEW=voiceoff`(示範資料)。看到:外觀的八個點、聊天的顏色三個點、語言、「更多外觀設定」;「語音服務」的聽、說兩列和各自的服務選單。拉滑桿當下就換、設好的樣子靠自動測試。 diff --git a/docs/feature-map/box.md b/docs/feature-map/box.md index 01398df..e657456 100644 --- a/docs/feature-map/box.md +++ b/docs/feature-map/box.md @@ -38,5 +38,6 @@ - 桌面是第 12 版起換的(照 LazyBoy2 的 box:XFCE 工作列、深色主題、繁中、台北時間;字型第 14 版起是思源黑體,和 AnyBot 視窗同一套,以前是粉圓);第 11 版以前是 fluxbox,只有右鍵選單和一條細工作列,設定 › 電腦「更新 Bot 的電腦」換新版。桌面設定每次開機照映像檔重放,在桌面上改的外觀、工作列不會留下;留下的是檔案和瀏覽器的登入。工作列鎖住(xfconf 的鎖要寫使用者名稱 bot,寫「*」不算數);它的「面板 › 登出 › 結束」只關掉工作列,一秒後自己回來。網頁上傳檔案的視窗開機時設好大小和位置(GTK 沒記著位置就照字型算大小,比螢幕大)。時區是 /etc/localtime(台北),沒有 TZ 變數,Bot 改了就生效。 - 檔案視窗的「取消」「開啟」在最上面(第 11 版以前在最下面、被螢幕切掉,網頁上傳圖片選得到檔案卻送不出去——換新版)。看畫面時可以跟自己的電腦互相複製貼上;在畫面裡打的字進到正在看的那個螢幕(Bot 自己的螢幕也一樣,不會打到共用的)。那個 Bot 的螢幕沒開時,看到的是共用桌面,點擊和打字也算在共用桌面(共用桌面上的 Bot 會停手);畫面中途關掉,之後打的字不會另外開一個看不到的螢幕。 - 實機要確認的:選單是中文、只有一層;工作列按右鍵沒有「移除」;網頁上傳檔案的視窗整個在螢幕裡(看得到「開啟」);請 Bot 打開終端機要開出跟工作列「終端機」同一種視窗,打開檔案總管要開出檔案管理員、在 bot 家目錄;開著畫面關掉 Wi-Fi 一分鐘再打開要自己接回;把畫面連結複製到另一個瀏覽器(原本的開著)要連不上。 +- 手機的畫面(接管)每次打開都是一個新的框,關掉就拿掉:以前同一個框換網址,iframe 換頁會留在上一頁紀錄裡,第二次之後按 ✕ 或返回退的是框裡的那一頁,畫面卡著回不去。 - 從帳號看畫面:之前靜止一分鐘、或看超過十分鐘會被帳號伺服器切掉,要更新帳號伺服器(make update-server)。 - 從帳號看畫面的票會出現在網址裡,所以網頁一打開就換掉連結裡那張(舊的當場作廢),每次斷線重連再換一張;票只在發出後十分鐘內能開新連線,已連上的畫面在要票的手機還登入時一直開著。斷線超過十分鐘:手機網頁用自己的登入重新要票;電腦開的網頁顯示「這個畫面連結已過期」並停止重試,回 AnyBot 再開一次。 diff --git a/docs/feature-map/settings.md b/docs/feature-map/settings.md index 605d650..b0ee879 100644 --- a/docs/feature-map/settings.md +++ b/docs/feature-map/settings.md @@ -31,7 +31,7 @@ - `settings-voice` 「語音」:「語音服務」清單,「聽(語音轉文字)」和「說(朗讀)」各選一個服務([appearance](appearance.md))。 - `settings-updates` 「更新」:「版本」、「自動更新」(你離開時換新版)、「園丁報告」、「待改進」清單([garden](garden.md))、「重新啟動」。 - `settings-bot` Bot 設定(每個 Bot 一個視窗,[profile](profile.md)):「Bot 資料」(名稱、描述;個人檔案、能力、「技能」,群組沒有這三張)、「頭像」(形狀和顏色,可自訂顏色)、「AI 供應商與模型」(供應商、模型、執行步驟用的模型、思考模式,[models](models.md))、「電腦操作」(查看、修改檔案和執行指令;做事的電腦、起始資料夾、模型可讀長度;「一律允許」清單,[safety](safety.md))、「指示」「群組成員」(只有群組,[team](team.md))、「記憶」(記得幾件事、「打開記憶」);最下面釘選到側邊欄、團隊成員可以使用,按「儲存」。 -- `settings-by-bot` Bot 能改的只有三樣:`theme`(light/dark/system)、`accent`(quiet/bot_color/black)、`timezone`(像 Asia/Taipei,不是有效的時區名稱就不改)。 +- `settings-by-bot` Bot 能改的只有四樣:`theme`(light/dark/system)、`style`(風格:paper、night、ink、moss、ocean、candy、sunset、terminal,custom 回到自訂)、`accent`(quiet/bot_color/black)、`timezone`(像 Asia/Taipei,不是有效的時區名稱就不改)。 ## 使用者怎麼到 @@ -41,7 +41,7 @@ ## 怎麼操作(verify-anybot) -- Bot:大部分設定改不了。`update_settings` 只改三樣(`theme`、`accent`、`timezone`);「在這台電腦上執行」只有使用者能打開。改自己的個人檔案、能力、技能、電腦、模型、頭像:先 `my_profile` 看,再 `update_my_profile` 改(使用者看到確認卡片、按允許才生效)。其他設定告訴使用者在哪個分頁、哪一塊。 +- Bot:大部分設定改不了。`update_settings` 只改四樣(`theme`、`style`、`accent`、`timezone`);「在這台電腦上執行」只有使用者能打開。改自己的個人檔案、能力、技能、電腦、模型、頭像:先 `my_profile` 看,再 `update_my_profile` 改(使用者看到確認卡片、按允許才生效)。其他設定告訴使用者在哪個分頁、哪一塊。 前提: diff --git a/icons/lucide/globe.svg b/icons/lucide/globe.svg new file mode 100644 index 0000000..6c8dff2 --- /dev/null +++ b/icons/lucide/globe.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/icons/lucide/hard-drive.svg b/icons/lucide/hard-drive.svg new file mode 100644 index 0000000..bba81d6 --- /dev/null +++ b/icons/lucide/hard-drive.svg @@ -0,0 +1,18 @@ + + + + + + + diff --git a/icons/lucide/moon.svg b/icons/lucide/moon.svg new file mode 100644 index 0000000..174f00d --- /dev/null +++ b/icons/lucide/moon.svg @@ -0,0 +1,15 @@ + + + + diff --git a/icons/lucide/palette.svg b/icons/lucide/palette.svg new file mode 100644 index 0000000..a423e4f --- /dev/null +++ b/icons/lucide/palette.svg @@ -0,0 +1,19 @@ + + + + + + + + diff --git a/icons/lucide/sliders-horizontal.svg b/icons/lucide/sliders-horizontal.svg new file mode 100644 index 0000000..e54f9f4 --- /dev/null +++ b/icons/lucide/sliders-horizontal.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + diff --git a/icons/lucide/volume-2.svg b/icons/lucide/volume-2.svg new file mode 100644 index 0000000..ba0e148 --- /dev/null +++ b/icons/lucide/volume-2.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/mobile/index.html b/mobile/index.html index 47e34eb..1e4a913 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -620,6 +620,22 @@ textarea.field{min-height:96px;line-height:1.5} .pill.go{background:color-mix(in srgb,var(--accent) 16%,transparent);color:var(--accent-ink)} .pill.wait{background:var(--attention-bg);color:var(--warn)} .pill.bad{background:color-mix(in srgb,var(--danger) 14%,transparent);color:var(--danger)} +/* 風格 gallery: four little pictures a row, the one worn ringed in the accent. */ +.tpl-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin:0 var(--sp-4) var(--sp-2)} +.tpl{display:flex;flex-direction:column;align-items:center;gap:5px;padding:0;min-width:0} +.tpl .pic{position:relative;width:100%;aspect-ratio:1.25;border-radius:var(--r-m);border:1px solid;overflow:hidden;display:block} +.tpl.on .pic{box-shadow:0 0 0 2px var(--pane),0 0 0 4px var(--accent)} +.tpl .pic i{position:absolute;display:block;border-radius:999px} +.tpl .pic .sd{left:0;top:0;bottom:0;width:26%;border-radius:0;display:flex;flex-direction:column;gap:4px;padding:6px 4px} +.tpl .pic .sd b{display:block;height:3px;border-radius:999px} +.tpl .pic .ln{left:34%;top:14%;width:50%;height:3px}.tpl .pic .ln.s{top:24%;width:36%} +.tpl .pic .bb{right:8%;top:42%;width:38%;height:9px} +.tpl .pic .dt{right:8%;bottom:10%;width:8px;height:8px} +.tpl .nm{font-size:var(--fs-caption);color:var(--text2)}.tpl.on .nm{color:var(--text);font-weight:600} +/* 風格's chat backdrop: dots, a grid or waves in the page's faintest line colour, behind the chat. */ +html[data-backdrop="dots"] #scroller{background-image:radial-gradient(var(--grid) 1.3px,transparent 1.5px);background-size:22px 22px} +html[data-backdrop="grid"] #scroller{background-image:linear-gradient(var(--grid) 1px,transparent 1px),linear-gradient(90deg,var(--grid) 1px,transparent 1px);background-size:24px 24px} +html[data-backdrop="waves"] #scroller{background-image:radial-gradient(circle at 50% 100%,transparent 13.5px,var(--grid) 14px,var(--grid) 14.6px,transparent 15.2px);background-size:32px 16px} /* 個人資料與用量: one strip of big numbers, the year's dots, a big number and bars. */ .me-figs{display:grid;grid-template-columns:repeat(4,1fr);gap:4px;margin:var(--sp-3) var(--sp-4) 0;padding:var(--sp-3) var(--sp-2);background:var(--elev);border-radius:var(--r-l)} .me-figs div{display:flex;flex-direction:column;align-items:center;gap:2px;min-width:0} @@ -896,6 +912,7 @@ const LUCIDE = { "paperclip": '', "log-out": '', "bell": '', + "palette": '', "moon": '', "shield": '', "plug": '', @@ -989,6 +1006,9 @@ function applyPalette(p) { const css = paletteCss(p); let el = document.getElementById("desk-palette"); if (!el) { el = document.createElement("style"); el.id = "desk-palette"; document.head.appendChild(el); } + // The 風格's chat backdrop (dots, a grid, waves), drawn in the page's own faint line colour. + const bd = p && ["dots", "grid", "waves"].includes(p.backdrop) ? p.backdrop : ""; + if (bd) document.documentElement.dataset.backdrop = bd; else delete document.documentElement.dataset.backdrop; if (el.textContent === css) return; el.textContent = css; try { if (css) localStorage.setItem("anybot.palette", JSON.stringify(p)); else localStorage.removeItem("anybot.palette"); } catch (_) {} @@ -2879,6 +2899,11 @@ async function freshDetail(id) { } const item = (o) => `<${o.tap ? "button" : "div"} class="item ${o.danger ? "danger" : ""}" ${o.data || ""}>${o.icon ? ic(o.icon, 19) : ""}
${esc(o.k)}
${o.v ? `
${esc(o.v)}
` : ""}
${o.r != null ? `
${esc(o.r)}
` : ""}${o.sw != null ? `` : ""}${o.tap && o.chev !== false ? `${ic("chevron-right", 16)}` : ""}`; const group = (title, inner, extra = "") => `${title ? `
${esc(title)}${extra}
` : ""}
${inner}
`; +// 設定 rows all have a picture (as on the computer, src/icons.rs setting_icon): by the words in +// the name, first match wins; a name that matches none gets the sliders. +const SET_ICON = [[["上網"], "globe"], [["頁面"], "file-text"], [["合作", "同事"], "users"], [["電話", "簡訊"], "message"], [["Mac App"], "laptop"], [["管理 App"], "settings"], [["主題"], "moon"], [["風格", "強調色", "顏色", "外觀"], "palette"], [["頭像", "形狀"], "smile-plus"], [["語言", "時區"], "globe"], [["通知", "響一聲"], "bell"], [["記憶"], "brain"], [["資料夾", "文件", "檔案", "資料庫"], "folder"], [["金鑰", "Token", "密碼", "保險庫", "兩步"], "lock"], [["瀏覽器", "網址"], "globe"], [["更新", "版本", "重新啟動"], "refresh"], [["備份", "還原", "快照"], "history"], [["磁碟", "用量"], "hard-drive"], [["團隊", "成員", "分享"], "users"], [["帳號", "登入", "登出", "角色", "名稱"], "info"], [["手機", "裝置"], "smartphone"], [["語音", "聲音"], "audio-lines"], [["規則", "權限", "直接操作", "一律", "允許", "詢問", "審核", "隔離"], "shield"], [["連接器", "整合"], "plug"], [["管道"], "message"], [["技能"], "sparkles"], [["模型", "思考", "步驟"], "sparkles"], [["電腦", "螢幕", "Docker", "主機", "終端機"], "monitor"], [["例行"], "alarm-clock"], [["指示", "描述", "擅長", "不找"], "pen"], [["釘選"], "pin"], [["分區"], "folder"], [["主要"], "star"]]; +const setIcon = (k) => (SET_ICON.find(([ws]) => ws.some((w) => String(k || "").includes(w))) || [0, "settings"])[1]; +const sitem = (o) => item(o.icon || o.noIcon ? o : {...o, icon: setIcon(o.k)}); async function loadAudit(id) { try { S.audit[id] = await api(base() + `api/bots/${id}/audit`); } catch (e) { S.audit[id] = {turns: []}; } if (cur().v === "details" && S.tab === "audit") renderDetails(id, "audit", true); @@ -3224,10 +3249,10 @@ async function renderBotset(id) { // Shown from a copy kept from before: read anew first, then it can be changed. const held = !isNew(id); let h = `
${face(b, "lg")}
${esc(b.name)}
${held ? `
顯示的是上次的設定,讀到最新的才能改
` : ""}
`; - h += group("基本", item({k: "名稱", r: b.name, tap: 1, data: 'data-e="name"'}) + item({k: "描述", v: d.description || "還沒有寫", tap: 1, data: 'data-e="desc"'}) + item({k: "指示", v: d.instructions ? d.instructions.slice(0, 160) + (d.instructions.length > 160 ? "…" : "") : "還沒有寫", tap: 1, data: 'data-e="instr"'})); + h += group("基本", sitem({k: "名稱", r: b.name, tap: 1, data: 'data-e="name"'}) + sitem({k: "描述", v: d.description || "還沒有寫", tap: 1, data: 'data-e="desc"'}) + sitem({k: "指示", v: d.instructions ? d.instructions.slice(0, 160) + (d.instructions.length > 160 ? "…" : "") : "還沒有寫", tap: 1, data: 'data-e="instr"'})); if (isOwner()) { - h += group("個人檔案", item({k: "擅長", v: d.strengths || "還沒有寫(同事會看到,知道什麼事找它)", tap: 1, data: 'data-e="strengths"'}) + item({k: "不找它做的事", v: d.not_for || "還沒有寫", tap: 1, data: 'data-e="not_for"'})); - const ticks = (title, key, list, note) => (list || []).length ? group(title, list.map((x) => item({k: x.name, v: x.note || "", sw: !!x.on, swdata: `data-tick="${key}" data-key="${esc(x.key)}"`, disabled: !!x.fixed})).join("") + (note ? `
${note}
` : "")) : ""; + h += group("個人檔案", sitem({k: "擅長", v: d.strengths || "還沒有寫(同事會看到,知道什麼事找它)", tap: 1, data: 'data-e="strengths"'}) + sitem({k: "不找它做的事", v: d.not_for || "還沒有寫", tap: 1, data: 'data-e="not_for"'})); + const ticks = (title, key, list, note) => (list || []).length ? group(title, list.map((x) => sitem({k: x.name, v: x.note || "", sw: !!x.on, swdata: `data-tick="${key}" data-key="${esc(x.key)}"`, disabled: !!x.fixed})).join("") + (note ? `
${note}
` : "")) : ""; h += ticks("能力", "abilities", d.abilities, "沒勾的工具不會給它,也不佔它每一輪的字數。"); h += ticks("會的技能", "skills", d.skills, "") .replace(/^(
會的技能)/, `$1`); h += ticks("可以用的電腦", "may_use", (d.may_use || []).length > 1 ? d.may_use : [], "它自己的電腦一定可以用。"); @@ -3236,12 +3261,12 @@ async function renderBotset(id) { // (As on the computer's Bot 設定: who carries out the planned steps, and how long it thinks.) const EFFORTS = [["", "自動(模型自己決定)"], ["low", "快速(想得少,回得快)"], ["medium", "平衡"], ["high", "深入(想得久,較慢)"]]; const stepShown = !d.step_model ? "自動" : d.step_model === "off" ? "不分開" : d.step_model; - const extra = isOwner() ? item({icon: "zap", k: "執行步驟用的模型", v: "想計畫和確認用上面的模型;照計畫做的步驟交給這個比較快的", r: stepShown, tap: 1, data: 'data-e="step"'}) + item({icon: "lightbulb", k: "思考模式", r: (EFFORTS.find((e) => e[0] === (d.thinking || "")) || EFFORTS[0])[1].replace(/(.*)/, ""), tap: 1, data: 'data-e="think"'}) : ""; - h += group("AI 與電腦", item({icon: "sparkles", k: "模型", v: b.via || b.model, r: b.runs || "", tap: 1, data: 'data-e="model"'}) + extra + item({icon: "monitor", k: "做事的電腦", r: b.computer || "", tap: 1, data: 'data-e="comp"'}) + item({icon: "terminal", k: "電腦操作", v: S.settings && S.settings.direct_mode ? "直接操作開著:照樣可以用電腦(關掉直接操作才照這裡)" : "關掉時,用電腦前會先問你", sw: d.tools_enabled !== false, swdata: 'data-sw="tools"', disabled: !isOwner()}) + item({icon: "brain", k: "模型可讀長度", r: (CTX.find((c) => c[0] === d.context_tokens) || [0, Math.round((d.context_tokens || 0) / 1000) + "K"])[1], tap: 1, data: 'data-e="ctx"'})); + const extra = isOwner() ? sitem({icon: "zap", k: "執行步驟用的模型", v: "想計畫和確認用上面的模型;照計畫做的步驟交給這個比較快的", r: stepShown, tap: 1, data: 'data-e="step"'}) + sitem({icon: "lightbulb", k: "思考模式", r: (EFFORTS.find((e) => e[0] === (d.thinking || "")) || EFFORTS[0])[1].replace(/(.*)/, ""), tap: 1, data: 'data-e="think"'}) : ""; + h += group("AI 與電腦", sitem({icon: "sparkles", k: "模型", v: b.via || b.model, r: b.runs || "", tap: 1, data: 'data-e="model"'}) + extra + sitem({icon: "monitor", k: "做事的電腦", r: b.computer || "", tap: 1, data: 'data-e="comp"'}) + sitem({icon: "terminal", k: "電腦操作", v: S.settings && S.settings.direct_mode ? "直接操作開著:照樣可以用電腦(關掉直接操作才照這裡)" : "關掉時,用電腦前會先問你", sw: d.tools_enabled !== false, swdata: 'data-sw="tools"', disabled: !isOwner()}) + sitem({icon: "brain", k: "模型可讀長度", r: (CTX.find((c) => c[0] === d.context_tokens) || [0, Math.round((d.context_tokens || 0) / 1000) + "K"])[1], tap: 1, data: 'data-e="ctx"'})); if (isOwner()) h += group("已設定「一律允許」", (d.allow_rules || []).map((r) => `
${ic("shield", 17)}
${esc(r)}
`).join("") || `
還沒有。在核准時選「一律允許」就會記在這裡。
`); - h += group("整理", item({icon: "pin", k: "釘選", sw: !!d.pinned, swdata: 'data-sw="pinned"'}) + item({icon: "star", k: "主要 Bot", v: d.primary ? "這是主要 Bot" : "", sw: !!d.primary, swdata: 'data-sw="primary"', disabled: !!d.primary}) + item({icon: "folder", k: "分區", r: d.folder || "未分區", tap: 1, data: 'data-e="folder"'})); - if ((d.demos || []).length) h += group("示範教學", d.demos.map((x) => item({icon: "eye", k: x.name, v: `${x.steps} 個步驟 · ${x.created}`})).join("") + `
示範要在那台電腦上錄;Bot 在對話裡會照著做。
`); - h += group("", item({icon: "refresh", k: "重新啟動這個 Bot", v: "卡住時用:停止它正在做的事和背景指令", tap: 1, data: 'data-e="restart"', chev: false}) + item({icon: "trash", k: "清除聊天記錄", tap: 1, data: 'data-e="clear"', danger: true, chev: false}) + (isOwner() ? item({icon: "trash", k: "刪除 Bot", tap: 1, data: 'data-e="delete"', danger: true, chev: false}) : "")); + h += group("整理", sitem({icon: "pin", k: "釘選", sw: !!d.pinned, swdata: 'data-sw="pinned"'}) + sitem({icon: "star", k: "主要 Bot", v: d.primary ? "這是主要 Bot" : "", sw: !!d.primary, swdata: 'data-sw="primary"', disabled: !!d.primary}) + sitem({icon: "folder", k: "分區", r: d.folder || "未分區", tap: 1, data: 'data-e="folder"'})); + if ((d.demos || []).length) h += group("示範教學", d.demos.map((x) => sitem({icon: "eye", k: x.name, v: `${x.steps} 個步驟 · ${x.created}`})).join("") + `
示範要在那台電腦上錄;Bot 在對話裡會照著做。
`); + h += group("", sitem({icon: "refresh", k: "重新啟動這個 Bot", v: "卡住時用:停止它正在做的事和背景指令", tap: 1, data: 'data-e="restart"', chev: false}) + sitem({icon: "trash", k: "清除聊天記錄", tap: 1, data: 'data-e="clear"', danger: true, chev: false}) + (isOwner() ? sitem({icon: "trash", k: "刪除 Bot", tap: 1, data: 'data-e="delete"', danger: true, chev: false}) : "")); $("botset").innerHTML = h + `
`; const el = $("botset"); el.classList.toggle("held", held); @@ -3656,59 +3681,68 @@ function drawSettings(kind, quiet) { ["general", "settings", "一般", "外觀、時區、通知總開關"], ...(isOwner() ? [["me", "activity", "個人資料與用量", ""]] : []), ["models", "sparkles", "模型", "可以用的 AI 服務"], ["perms", "shield", "權限", st.direct_mode ? "直接操作:開" : "Bot 做事前的規則"], ["integrations", "plug", "整合", "訊息管道、連接器、技能"], ["computers", "monitor", "電腦", "Bot 的電腦和你帳號裡的電腦"], ["vault", "lock", "保險庫", "密碼和卡號"], ["account", "smartphone", "手機與帳號", "登入的手機、這支手機的通知"], ["updates", "download", "更新", st.version || ""], - ].map(([k, i, n, v]) => item({icon: i, k: n, r: k === "updates" ? v : "", tap: 1, data: `data-go="${k}"`})).join("")); + ].map(([k, i, n, v]) => sitem({icon: i, k: n, r: k === "updates" ? v : "", tap: 1, data: `data-go="${k}"`})).join("")); } if (kind === "general") { st.accent = ({Quiet: "quiet", BotColor: "bot_color", Black: "black"})[st.accent] || st.accent; // The computer's 主題 and 聊天的顏色 (the phone follows them unless its own 外觀 says otherwise). const ACC = {quiet: "安靜(淡灰泡泡)", bot_color: "跟著 Bot", black: "只用黑色"}; - if (isOwner()) h += group("電腦的外觀", item({icon: "moon", k: "主題", r: ({system: "跟隨系統", light: "淺色", dark: "深色"})[st.theme] || "跟隨系統", tap: 1, data: 'data-s="theme"'}) + item({icon: "message", k: "聊天的顏色", r: ACC[st.accent || "quiet"] || "", tap: 1, data: 'data-s="accent"'})); - h += group("", item({icon: "globe", k: "時區", r: st.timezone || "", tap: 1, data: 'data-s="tz"'}) + item({icon: "bell", k: "通知總開關", v: "Bot 做完或等你時通知,電腦和手機都算;關掉就都不通知", sw: !!st.notify, swdata: 'data-sset="notify"', disabled: !isOwner()})); - h += group("這支手機", item({icon: "smartphone", k: "外觀", r: (THEMES.find((t) => t[0] === phoneTheme()) || THEMES[0])[1], tap: 1, data: 'data-s="phonetheme"'})); + // 風格: a little picture of each (the sidebar, words, your bubble, the accent, its backdrop). + if (isOwner() && (st.styles || []).length) { + const dk = isDark(); + h += `
風格
${st.styles.map((t) => { + const c = dk ? t.dark : t.light, on = st.style === t.id; + const bd = t.backdrop === "dots" ? `background-image:radial-gradient(${c.grid} 1px,transparent 1.2px);background-size:9px 9px;` : t.backdrop === "grid" ? `background-image:linear-gradient(${c.grid} 1px,transparent 1px),linear-gradient(90deg,${c.grid} 1px,transparent 1px);background-size:10px 10px;` : t.backdrop === "waves" ? `background-image:radial-gradient(circle at 50% 100%,transparent 6px,${c.grid} 6.5px,${c.grid} 7.5px,transparent 8px);background-size:14px 7px;` : ""; + return ``; + }).join("")}
${st.style ? "" : `
現在是自訂的顏色(電腦上的強調色);點一個風格整套換,電腦和手機一起。
`}`; + } + if (isOwner()) h += group("電腦的外觀", sitem({icon: "moon", k: "主題", r: ({system: "跟隨系統", light: "淺色", dark: "深色"})[st.theme] || "跟隨系統", tap: 1, data: 'data-s="theme"'}) + sitem({icon: "message", k: "聊天的顏色", r: ACC[st.accent || "quiet"] || "", tap: 1, data: 'data-s="accent"'})); + h += group("", sitem({icon: "globe", k: "時區", r: st.timezone || "", tap: 1, data: 'data-s="tz"'}) + sitem({icon: "bell", k: "通知總開關", v: "Bot 做完或等你時通知,電腦和手機都算;關掉就都不通知", sw: !!st.notify, swdata: 'data-sset="notify"', disabled: !isOwner()})); + h += group("這支手機", sitem({icon: "smartphone", k: "外觀", r: (THEMES.find((t) => t[0] === phoneTheme()) || THEMES[0])[1], tap: 1, data: 'data-s="phonetheme"'})); } if (kind === "models") { - h += group("AI 服務", (st.providers || []).map((p, i) => item({k: p.label, v: [p.runs, p.ready && p.default_model ? p.default_model : ""].filter(Boolean).join(" · "), r: p.ready ? "可以用" : "未設定", tap: isOwner() ? 1 : 0, data: `data-prov="${i}"`})).join("")); + h += group("AI 服務", (st.providers || []).map((p, i) => sitem({icon: "sparkles", k: p.label, v: [p.runs, p.ready && p.default_model ? p.default_model : ""].filter(Boolean).join(" · "), r: p.ready ? "可以用" : "未設定", tap: isOwner() ? 1 : 0, data: `data-prov="${i}"`})).join("")); h += `
金鑰只存在這台 AnyBot,手機寫得進去、看不到。
`; } if (kind === "perms") { - h += group("", item({icon: "zap", k: "直接操作", v: st.direct_locked ? "已由管理員關閉" : "Bot 直接做事,只有危險操作和「一律詢問」規則會先問你", sw: !!st.direct_mode, swdata: 'data-sset="direct_mode"', disabled: !isOwner() || st.direct_locked}) + item({icon: "shield", k: "自動審核", v: "照下面的規則自動允許或先問你", sw: !!st.auto_review, swdata: 'data-sset="auto_review"', disabled: !isOwner()})); + h += group("", sitem({icon: "zap", k: "直接操作", v: st.direct_locked ? "已由管理員關閉" : "Bot 直接做事,只有危險操作和「一律詢問」規則會先問你", sw: !!st.direct_mode, swdata: 'data-sset="direct_mode"', disabled: !isOwner() || st.direct_locked}) + sitem({icon: "shield", k: "自動審核", v: "照下面的規則自動允許或先問你", sw: !!st.auto_review, swdata: 'data-sset="auto_review"', disabled: !isOwner()})); h += rulesGroup("一律詢問(優先)", st.ask_rules, "ask") + rulesGroup("無需詢問直接允許", st.allow_rules, "allow"); // 直接操作 always asks about these three too (not written into the rules: turning it off leaves nothing behind). - if (st.direct_mode) h += group("直接操作開著時也一定先問", ["刪除檔案或資料夾", "付款、購買或轉帳", "用我的帳號發文、留言,或傳訊息給別人"].map((r) => item({icon: "hand", k: r})).join("")); + if (st.direct_mode) h += group("直接操作開著時也一定先問", ["刪除檔案或資料夾", "付款、購買或轉帳", "用我的帳號發文、留言,或傳訊息給別人"].map((r) => sitem({icon: "hand", k: r})).join("")); h += `
用一般的話寫,例如「付款前先問我」。兩邊都符合時先問。${st.direct_mode ? "直接操作開著:「一律詢問」照樣檢查,「直接允許」用不到。" : st.auto_review === false ? "自動審核關著時不會用這些規則。" : ""}
`; } if (kind === "integrations") { const dot = (ok, on) => ``; h += group("訊息管道", (st.channels || []).map((c) => `
${dot(c.ok, c.enabled)}
${esc(c.kind)} · ${esc(c.name)}
由「${esc(c.bot)}」回覆${c.note ? " · " + esc(c.note) : ""}
${isOwner() ? `` : ""}
`).join("") || `
還沒有。Telegram、Slack、Discord… 要在電腦上的 AnyBot 新增(需要輸入 Token)。
`); - h += group("連接器(MCP)", ((st.mcp || []).map((m) => `
${dot(m.tools != null, m.enabled)}
${esc(m.name)}
${!m.enabled ? "已關閉" : m.tools != null ? `已連上,${m.tools} 個工具` : m.error ? esc(m.error) : "連線中…"}
${isOwner() ? `${m.enabled ? `` : ""}` : ""}
`).join("") || `
還沒有連接器
`) + (isOwner() ? item({icon: "plus", k: "從公用市集加入", v: "搜尋官方 MCP Registry 裡用網址連的連接器", tap: 1, data: 'data-mcpmarket="1"'}) : "")); + h += group("連接器(MCP)", ((st.mcp || []).map((m) => `
${dot(m.tools != null, m.enabled)}
${esc(m.name)}
${!m.enabled ? "已關閉" : m.tools != null ? `已連上,${m.tools} 個工具` : m.error ? esc(m.error) : "連線中…"}
${isOwner() ? `${m.enabled ? `` : ""}` : ""}
`).join("") || `
還沒有連接器
`) + (isOwner() ? sitem({icon: "plus", k: "從公用市集加入", v: "搜尋官方 MCP Registry 裡用網址連的連接器", tap: 1, data: 'data-mcpmarket="1"'}) : "")); const skRows = (st.skills || []).map((k, i) => { const tags = [...(k.resources && k.resources.length ? [`${k.resources.length} 檔`] : []), ...(k.steps ? [`可重播 ${k.steps} 步`] : [])].join(" · "); return `
${esc(k.name)}${tags ? ` ${esc(tags)}` : ""}
${esc(k.description)}
${isOwner() ? `` : ""}
`; }).join(""); const skActions = isOwner() - ? item({icon: "sparkles", k: "從技能市集加入", v: "內建繁中核心技能包與 Anthropic 官方開源技能", tap: 1, data: 'data-skillmarket="1"'}) + - item({icon: "plus", k: "從 GitHub 或網址安裝技能", v: "支援 anthropics/skills 網址、owner/repo/path 或 SKILL.md 連結", tap: 1, data: 'data-skilladd="1"', chev: false}) + ? sitem({icon: "sparkles", k: "從技能市集加入", v: "內建繁中核心技能包與 Anthropic 官方開源技能", tap: 1, data: 'data-skillmarket="1"'}) + + sitem({icon: "plus", k: "從 GitHub 或網址安裝技能", v: "支援 anthropics/skills 網址、owner/repo/path 或 SKILL.md 連結", tap: 1, data: 'data-skilladd="1"', chev: false}) : ""; h += group("技能", (skRows || `
還沒有技能。可從下方「技能市集」一鍵加入,或在聊天裡請 Bot 幫你建立。
`) + skActions); } if (kind === "computers") h += computersHtml(st); if (kind === "vault") h += `
${ic("lock", 28)}

保險庫裡的密碼、卡號和聯絡資訊,只在電腦上的 AnyBot 管理。
Bot 用到時由 AnyBot 直接填進網頁,不會交給模型,也不會經過手機。
`; if (kind === "account") { - h += group("這台 AnyBot", item({icon: "monitor", k: "名稱", r: st.host || S.hostName}) + item({icon: "info", k: "你的角色", r: isOwner() ? "擁有者" : "管理員"})); - if (st.devices) h += group("直接連線的手機", st.devices.map((d, i) => item({icon: "smartphone", k: d.name, v: d.last_seen ? "上次使用 " + ago(d.last_seen * 1000) : "登入於 " + ago(d.created * 1000), tap: 1, data: `data-dev="${i}"`})).join("") || `
沒有
`); + h += group("這台 AnyBot", sitem({icon: "monitor", k: "名稱", r: st.host || S.hostName}) + sitem({icon: "info", k: "你的角色", r: isOwner() ? "擁有者" : "管理員"})); + if (st.devices) h += group("直接連線的手機", st.devices.map((d, i) => sitem({icon: "smartphone", k: d.name, v: d.last_seen ? "上次使用 " + ago(d.last_seen * 1000) : "登入於 " + ago(d.created * 1000), tap: 1, data: `data-dev="${i}"`})).join("") || `
沒有
`); const acts = []; - if (S.relay) acts.push(item({icon: "bell", k: "通知", v: "Bot 需要你允許、或做完事時,手機跳通知", tap: 1, data: 'data-s="push"'})); - if (S.relay) acts.push(item({icon: "shield", k: "兩步驗證", v: "登入要密碼+驗證器 App 的六位碼", tap: 1, data: 'data-s="2fa"'})); - if (S.relay) acts.push(item({icon: "smartphone", k: "登入的裝置", v: "看看有哪些裝置登著,可逐台踢掉", tap: 1, data: 'data-s="devices"'})); - if (S.relay && owner()) acts.push(item({icon: "plus", k: "加一台電腦", v: "Linux、伺服器當 Bot 的手腳", tap: 1, data: 'data-s="pair"'})); - if (S.relay) acts.push(item({icon: "refresh", k: "切換到別台 AnyBot", tap: 1, data: 'data-s="host"'})); - acts.push(item({icon: "log-out", k: "登出這支手機", tap: 1, data: 'data-s="out"', danger: true, chev: false})); + if (S.relay) acts.push(sitem({icon: "bell", k: "通知", v: "Bot 需要你允許、或做完事時,手機跳通知", tap: 1, data: 'data-s="push"'})); + if (S.relay) acts.push(sitem({icon: "shield", k: "兩步驗證", v: "登入要密碼+驗證器 App 的六位碼", tap: 1, data: 'data-s="2fa"'})); + if (S.relay) acts.push(sitem({icon: "smartphone", k: "登入的裝置", v: "看看有哪些裝置登著,可逐台踢掉", tap: 1, data: 'data-s="devices"'})); + if (S.relay && owner()) acts.push(sitem({icon: "plus", k: "加一台電腦", v: "Linux、伺服器當 Bot 的手腳", tap: 1, data: 'data-s="pair"'})); + if (S.relay) acts.push(sitem({icon: "refresh", k: "切換到別台 AnyBot", tap: 1, data: 'data-s="host"'})); + acts.push(sitem({icon: "log-out", k: "登出這支手機", tap: 1, data: 'data-s="out"', danger: true, chev: false})); h += group("這支手機", acts.join("")); } if (kind === "updates") { - h += group("", item({icon: "info", k: "版本", v: st.built ? `${stamp(st.built)} 建置` : "", r: st.version || ""}) + (st.newer ? item({icon: "download", k: "有新版", v: "電腦上的 AnyBot 已經下載新版,重新啟動就會換上"}) : item({icon: "circle-check", k: "已是最新版"}))); + h += group("", sitem({icon: "info", k: "版本", v: st.built ? `${stamp(st.built)} 建置` : "", r: st.version || ""}) + (st.newer ? sitem({icon: "download", k: "有新版", v: "電腦上的 AnyBot 已經下載新版,重新啟動就會換上"}) : sitem({icon: "circle-check", k: "已是最新版"}))); h += `
Bot 的電腦的更新在「電腦」裡。
`; - h += group("這支手機", item({icon: "smartphone", k: "畫面", v: fitWords(), tap: 1, data: 'data-ruler="1"'})); + h += group("這支手機", sitem({icon: "smartphone", k: "畫面", v: fitWords(), tap: 1, data: 'data-ruler="1"'})); h += `
畫面看起來被切到、上面糊糊的、下面空一塊時,按「畫面」打開量尺截圖給我們。
`; } el.innerHTML = h + `
`; @@ -3733,17 +3767,17 @@ function computersHtml(st) { const steps = f.steps && f.steps.n ? `平均每步 ${Math.round(f.steps.total_ms / f.steps.n)} ms(${f.steps.n} 步)` : ""; // (Not looked at yet: undefined. Nothing to look at — no Docker, no box yet: null.) const upd = f.update === undefined ? "檢查中…" : f.update === null ? (box.available ? `還沒建立(建立時是 v${box.version})` : "沒有 Docker,現在沒有這台電腦") : f.update ? `有新版(v${box.version})。檔案和登入都會留著` : `已是 v${box.version}`; - h += group("", item({icon: "download", k: "更新 Bot 的電腦", v: upd, tap: isOwner() && f.update ? 1 : 0, data: 'data-bx="update"'}) + - item({icon: "alarm-clock", k: "自動更新", r: box.auto_update || "關", tap: isOwner() ? 1 : 0, data: 'data-bx="auto"'}) + - item({icon: "shield", k: "容器隔離", v: running_rt && running_rt !== rt.slice(0, 2) ? `目前是${running_rt};按更新後改成${rt}` : (f.gvisor === false && box.runtime !== "runsc" ? "這台 Docker 主機沒有 gVisor" : ""), r: rt, tap: isOwner() && (f.gvisor || box.runtime === "runsc") ? 1 : 0, data: 'data-bx="runtime"'}) + - item({icon: "hard-drive", k: "上次快照", r: box.snapshot || "還沒有"}) + - (steps ? item({icon: "activity", k: "速度", r: steps}) : "") + - (st.docker_host ? item({icon: "server", k: "Docker 主機", v: st.docker_host}) : "")); - h += group("", item({icon: "sparkles", k: "請 Bot 提出清理方案", v: "先列出用量最大的地方,不會直接刪除", tap: 1, data: 'data-bx="clean"'}) + - (isOwner() ? item({icon: "refresh", k: box.snapshot ? "從快照復原" : "重設電腦", v: box.snapshot ? `回到 ${box.snapshot} 的快照(目前的內容會先存起來)` : "換一台全新的電腦(檔案和登入會清除)", tap: 1, data: 'data-bx="reset"', danger: true, chev: false}) : "")); + h += group("", sitem({icon: "download", k: "更新 Bot 的電腦", v: upd, tap: isOwner() && f.update ? 1 : 0, data: 'data-bx="update"'}) + + sitem({icon: "alarm-clock", k: "自動更新", r: box.auto_update || "關", tap: isOwner() ? 1 : 0, data: 'data-bx="auto"'}) + + sitem({icon: "shield", k: "容器隔離", v: running_rt && running_rt !== rt.slice(0, 2) ? `目前是${running_rt};按更新後改成${rt}` : (f.gvisor === false && box.runtime !== "runsc" ? "這台 Docker 主機沒有 gVisor" : ""), r: rt, tap: isOwner() && (f.gvisor || box.runtime === "runsc") ? 1 : 0, data: 'data-bx="runtime"'}) + + sitem({icon: "hard-drive", k: "上次快照", r: box.snapshot || "還沒有"}) + + (steps ? sitem({icon: "activity", k: "速度", r: steps}) : "") + + (st.docker_host ? sitem({icon: "server", k: "Docker 主機", v: st.docker_host}) : "")); + h += group("", sitem({icon: "sparkles", k: "請 Bot 提出清理方案", v: "先列出用量最大的地方,不會直接刪除", tap: 1, data: 'data-bx="clean"'}) + + (isOwner() ? sitem({icon: "refresh", k: box.snapshot ? "從快照復原" : "重設電腦", v: box.snapshot ? `回到 ${box.snapshot} 的快照(目前的內容會先存起來)` : "換一台全新的電腦(檔案和登入會清除)", tap: 1, data: 'data-bx="reset"', danger: true, chev: false}) : "")); if ((box.log || []).length) h += `
紀錄
${esc(box.log.slice(-25).join("\n"))}
`; const others = comps.filter((c) => c.kind !== "own"); - if (others.length) h += group("帳號裡的電腦", others.map((c) => item({icon: {this: "monitor", device: "laptop", ssh: "server"}[c.kind] || "monitor", k: c.name, v: (c.online ? "在線上" : "離線") + (c.person ? " · 你正在用的" : ""), tap: c.kind === "this" && S.mac ? 1 : 0, data: c.kind === "this" && S.mac ? 'data-bx="mac"' : ""})).join("")); + if (others.length) h += group("帳號裡的電腦", others.map((c) => sitem({icon: {this: "monitor", device: "laptop", ssh: "server"}[c.kind] || "monitor", k: c.name, v: (c.online ? "在線上" : "離線") + (c.person ? " · 你正在用的" : ""), tap: c.kind === "this" && S.mac ? 1 : 0, data: c.kind === "this" && S.mac ? 'data-bx="mac"' : ""})).join("")); return h; } async function devicesSheet() { @@ -3898,7 +3932,8 @@ function wireSettings(kind, st) { }); on("[data-s]", "onclick", async (x) => { const k = x.dataset.s; - if (k === "theme") sheet("主題", [["system", "跟隨系統"], ["light", "淺色"], ["dark", "深色"]].map(([v, n]) => ({label: n, check: st.theme === v, on: async () => { if (await app("update_settings", {theme: v})) again(); }}))); + if (k === "style") { if (await app("update_settings", {style: x.dataset.style}, 0, false)) { toast("換好了"); again(); } } + else if (k === "theme") sheet("主題", [["system", "跟隨系統"], ["light", "淺色"], ["dark", "深色"]].map(([v, n]) => ({label: n, check: st.theme === v, on: async () => { if (await app("update_settings", {theme: v})) again(); }}))); else if (k === "accent") sheet("聊天的顏色", [["quiet", "安靜(淡灰泡泡)"], ["bot_color", "跟著 Bot"], ["black", "只用黑色"]].map(([v, n]) => ({label: n, check: (st.accent || "quiet") === v, on: async () => { if (await app("update_settings", {accent: v})) again(); }}))); else if (k === "tz") { const zones = [...new Set([TZ, "Asia/Taipei", "Asia/Tokyo", "Asia/Shanghai", "Asia/Hong_Kong", "Asia/Singapore", "Europe/London", "America/New_York", "America/Los_Angeles", "UTC"].filter(Boolean))]; @@ -4468,13 +4503,22 @@ function openBox(control) { const at = S.relay ? "host=" + encodeURIComponent(S.host) : "lan=1"; boxOpen = true; history.pushState({box: 1}, ""); - $("boxframe").src = "screen#" + at + "&name=" + encodeURIComponent(own ? own.name : "Bot 的電腦") + (b.id ? "&bot=" + b.id : "") + (control ? "&control=1" : "") + "&embed=1"; + newBoxFrame("screen#" + at + "&name=" + encodeURIComponent(own ? own.name : "Bot 的電腦") + (b.id ? "&bot=" + b.id : "") + (control ? "&control=1" : "") + "&embed=1"); $("boxwrap").style.display = "block"; } function closeBox() { boxOpen = false; $("boxwrap").style.display = "none"; - $("boxframe").src = "about:blank"; + newBoxFrame(""); +} +// A fresh frame each time, never a new address in the same one: an iframe that navigates adds +// to the page's back history, and after the first open and close 返回 (and the screen's ✕) went +// back inside the frame instead of closing it — the takeover screen stayed and could not be left. +function newBoxFrame(url) { + const old = $("boxframe"), f = old.cloneNode(false); + f.removeAttribute("src"); + if (url) f.src = url; + old.replaceWith(f); } window.addEventListener("message", (e) => { if (e.origin !== location.origin || !e.data) return; diff --git a/src/app.rs b/src/app.rs index bc76ff7..7ac8445 100644 --- a/src/app.rs +++ b/src/app.rs @@ -761,6 +761,10 @@ impl App { if std::env::var("ANYBOT_SHOT_THEME").as_deref() == Ok("dark") { app.state.theme = Theme::Dark; } + // 風格 for pictures: ANYBOT_SHOT_STYLE=ocean (theme::TEMPLATES). + if let Ok(v) = std::env::var("ANYBOT_SHOT_STYLE") { + app.state.shell_template = v; + } // Shell dials for concept pictures: ANYBOT_SHOT_SHELL=tone,accent,contrast. if let Ok(v) = std::env::var("ANYBOT_SHOT_SHELL") { let mut it = v.split(','); @@ -1536,7 +1540,7 @@ impl App { /// What the shell is built from, to notice a change (f32s by their bits: equal means unchanged). fn shell_key(&self) -> ShellKey { - (self.state.theme, self.state.shell_tone.to_bits(), self.state.shell_accent.clone(), self.state.shell_contrast.to_bits(), self.state.dense) + (self.state.theme, self.state.shell_tone.to_bits(), format!("{}/{}", self.state.shell_accent, self.state.shell_template), self.state.shell_contrast.to_bits(), self.state.dense) } fn apply_theme(&mut self, ctx: &egui::Context) { @@ -1547,7 +1551,7 @@ impl App { Theme::System => ctx.input(|i| i.raw.system_theme) == Some(egui::Theme::Dark), }; // The shell from the person's three dials (設定 › 一般); defaults reproduce 「紙」. - self.pal = crate::theme::shell(self.state.shell_tone, &self.state.shell_accent, self.state.shell_contrast, dark); + self.pal = crate::theme::palette_for(&self.state.shell_template, self.state.shell_tone, &self.state.shell_accent, self.state.shell_contrast, dark); // Screenshot concept themes for picking a colour direction (see theme.rs `shot_palette`). if let Ok(t) = std::env::var("ANYBOT_SHOT_PAL") { if let Some(p) = crate::theme::shot_palette(&t, dark) { @@ -4304,6 +4308,8 @@ impl App { }; self.header(ui, &bot); self.mirror_banner(ui); + // 風格's backdrop behind the conversation (dots, a grid, waves; the faintest line colour). + chat_backdrop(ui.painter(), ui.available_rect_before_wrap(), crate::theme::backdrop(&self.state.shell_template), p); // The composer grows with a long draft: keep room for last frame's height — but never all // of it: the conversation keeps a strip, and the input stops growing (it scrolls) where // the column ends, even in a short window or the narrow chat beside a workflow. @@ -6356,6 +6362,12 @@ impl App { SettingsTab::General => { // One thing a row, in plain words; what needs explaining is behind the ?. section(ui, "外觀", p); + // 風格: a whole look in one press — a little picture of each. + if let Some(id) = self.style_gallery(ui) { + self.state.shell_template = id.to_string(); + self.dirty = true; + } + ui.add_space(crate::theme::sp::S2); rows_card(ui, p, |ui| { card_row(ui, p, "主題", "", "", |ui| { if let Some(th) = segmented(ui, p, self.state.theme, &[(Theme::Light, "淺色"), (Theme::Dark, "深色"), (Theme::System, "跟著系統")]) { @@ -6369,11 +6381,13 @@ impl App { let (rect, r) = ui.allocate_exact_size(vec2(26.0, 26.0), egui::Sense::click()); let c = rect.center(); ui.painter().circle_filled(c, 10.0, if darkish { darkv } else { light }); - if self.state.shell_accent == name { + if self.state.shell_accent == name && self.state.shell_template.is_empty() { ui.painter().circle_stroke(c, 13.0, Stroke::new(2.0, p.text)); } - if r.on_hover_text(t(label)).on_hover_cursor(egui::CursorIcon::PointingHand).clicked() && self.state.shell_accent != name { + if r.on_hover_text(t(label)).on_hover_cursor(egui::CursorIcon::PointingHand).clicked() && (self.state.shell_accent != name || !self.state.shell_template.is_empty()) { + // (A colour of one's own: the 風格 goes back to 自訂.) self.state.shell_accent = name.to_string(); + self.state.shell_template.clear(); self.dirty = true; } } @@ -6443,6 +6457,7 @@ impl App { let before = self.state.shell_tone; ui.add(egui::Slider::new(&mut self.state.shell_tone, 0.0..=1.0).show_value(false).text(" ")); if self.state.shell_tone != before { + self.state.shell_template.clear(); self.dirty = true; } }); @@ -6478,6 +6493,7 @@ impl App { self.state.shell_tone = 1.0; self.state.shell_accent = "clay".into(); self.state.shell_contrast = 1.0; + self.state.shell_template.clear(); self.dirty = true; } }); @@ -8433,6 +8449,58 @@ fn ask_dock_height(reason: &str, width: f32, cap: f32) -> f32 { (wrapped_lines(detail, (width - 92.0).max(120.0), cw) * 17.0 + 168.0).min(cap) } +/// The chat's backdrop of a 風格: dots, a grid or waves in the grid colour; "" draws nothing. +fn chat_backdrop(painter: &egui::Painter, rect: egui::Rect, kind: &str, p: Palette) { + let painter = painter.with_clip_rect(rect); + match kind { + "dots" => { + let step = 22.0; + let mut y = rect.top() + step / 2.0; + while y < rect.bottom() { + let mut x = rect.left() + step / 2.0; + while x < rect.right() { + painter.circle_filled(egui::pos2(x, y), 1.3, p.grid); + x += step; + } + y += step; + } + } + "grid" => { + let step = 24.0; + let line = Stroke::new(1.0, p.grid); + let mut x = rect.left(); + while x < rect.right() { + painter.vline(x, rect.y_range(), line); + x += step; + } + let mut y = rect.top(); + while y < rect.bottom() { + painter.hline(rect.x_range(), y, line); + y += step; + } + } + "waves" => { + // Rows of shallow arcs (scallops), like the phone's. + let (w, h) = (32.0, 16.0); + let line = Stroke::new(1.0, p.grid); + let mut y = rect.top() + h; + while y < rect.bottom() + h { + let mut x = rect.left(); + while x < rect.right() + w { + let pts: Vec = (0..=8).map(|i| { + let a = std::f32::consts::PI * (i as f32 / 8.0); + egui::pos2(x + w / 2.0 - a.cos() * (w / 2.0 - 2.0), y - a.sin() * (h - 2.0)) + }).collect(); + painter.add(egui::Shape::line(pts, line)); + x += w; + } + y += h; + } + } + _ => {} + } +} + /// What the card's 「之後都直接操作」 line adds past `ask_dock_height`'s guess (measured: the /// guess already leaves a little room under the last line). const ASK_DIRECT_ROW: f32 = 14.0; diff --git a/src/app/kit.rs b/src/app/kit.rs index 81ee34f..b2e2759 100644 --- a/src/app/kit.rs +++ b/src/app/kit.rs @@ -114,7 +114,9 @@ pub(super) fn card_row(ui: &mut egui::Ui, p: Palette, label: &str, sub: &str, he let mut right = ui.new_child(egui::UiBuilder::new().max_rect(rect).layout(Layout::right_to_left(Align::Center))); right.spacing_mut().item_spacing.x = 8.0; control(&mut right); - let words = egui::Rect::from_min_max(rect.min, egui::pos2((right.min_rect().left() - 12.0).max(rect.left() + 80.0), rect.bottom())); + // Every setting has its picture before its name (crate::icons::setting_icon). + crate::icons::paint(ui.painter(), egui::Rect::from_center_size(egui::pos2(rect.left() + 9.0, rect.center().y), vec2(17.0, 17.0)), crate::icons::setting_icon(label), p.text2); + let words = egui::Rect::from_min_max(egui::pos2(rect.left() + 28.0, rect.top()), egui::pos2((right.min_rect().left() - 12.0).max(rect.left() + 108.0), rect.bottom())); if sub.is_empty() { let mut left = ui.new_child(egui::UiBuilder::new().max_rect(words).layout(Layout::left_to_right(Align::Center))); left.spacing_mut().item_spacing.x = 4.0; @@ -157,6 +159,9 @@ 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) { let r = ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 4.0; + // (Its picture, as every setting row has one.) + let (pic, _) = ui.allocate_exact_size(vec2(22.0, 18.0), egui::Sense::hover()); + crate::icons::paint(ui.painter(), egui::Rect::from_center_size(pic.left_center() + vec2(8.0, 0.0), vec2(16.0, 16.0)), crate::icons::setting_icon(title), p.text2); ui.label(RichText::new(t(title)).strong().family(crate::bold()).size(FONT_BASE)); help_mark(ui, desc, p); }); @@ -406,3 +411,60 @@ pub(super) fn dialog_footer(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mu ui.horizontal(|ui| body(ui)); }); } + +impl App { + /// 設定 › 一般 › 外觀 › 風格: each template as a little picture of the app in its colours + /// (the sidebar, a line of words, your bubble, the accent, its backdrop) with its name; the + /// one worn has a ring. Returns the one pressed. The last card is 自訂 (the dials below). + pub(super) fn style_gallery(&mut self, ui: &mut egui::Ui) -> Option<&'static str> { + let p = self.pal; + let dark = is_dark(p); + let mut picked = None; + let width = ui.available_width(); + let gap = 10.0; + let cols = if width >= 560.0 { 4 } else { 3 }; + let w = ((width - gap * (cols as f32 - 1.0)) / cols as f32).floor(); + let h = (w * 0.62).round(); + for row in crate::theme::TEMPLATES.chunks(cols) { + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = gap; + for t in row { + let tp = crate::theme::palette_for(t.id, 1.0, "clay", self.state.shell_contrast, dark); + let (rect, r) = ui.allocate_exact_size(vec2(w, h + 22.0), egui::Sense::click()); + let pic = egui::Rect::from_min_size(rect.min, vec2(w, h)); + let paint = ui.painter(); + paint.rect(pic, R_M, tp.pane, Stroke::new(1.0, tp.border), egui::StrokeKind::Inside); + // The backdrop, faintly. + super::chat_backdrop(paint, pic.shrink(2.0), t.backdrop, tp); + let side = egui::Rect::from_min_max(pic.min, egui::pos2(pic.left() + w * 0.26, pic.bottom())); + paint.rect_filled(side.shrink(1.0), CornerRadius { nw: R_M - 1, sw: R_M - 1, ..Default::default() }, tp.sidebar); + for i in 0..3 { + let y = side.top() + 10.0 + i as f32 * 9.0; + paint.rect_filled(egui::Rect::from_min_size(egui::pos2(side.left() + 7.0, y), vec2(side.width() - 14.0, 4.0)), R_FULL, if i == 0 { tp.active } else { tp.hover }); + } + let body = egui::Rect::from_min_max(egui::pos2(side.right() + 8.0, pic.top() + 10.0), pic.max - vec2(8.0, 8.0)); + paint.rect_filled(egui::Rect::from_min_size(body.min, vec2(body.width() * 0.8, 4.0)), R_FULL, tp.text3); + paint.rect_filled(egui::Rect::from_min_size(body.min + vec2(0.0, 9.0), vec2(body.width() * 0.6, 4.0)), R_FULL, tp.text3); + let bubble = egui::Rect::from_min_size(egui::pos2(body.right() - body.width() * 0.5, body.top() + 20.0), vec2(body.width() * 0.5, 11.0)); + paint.rect_filled(bubble, R_FULL, tp.bubble_user); + paint.circle_filled(egui::pos2(body.right() - 6.0, body.bottom() - 6.0), 5.0, tp.accent); + let on = self.state.shell_template == t.id; + if on { + paint.rect_stroke(pic.expand(2.0), R_M + 2, Stroke::new(2.0, p.accent), egui::StrokeKind::Outside); + } else if r.hovered() { + paint.rect_stroke(pic.expand(1.0), R_M + 1, Stroke::new(1.0, p.text3), egui::StrokeKind::Outside); + } + paint.text(egui::pos2(pic.center().x, pic.bottom() + 5.0), egui::Align2::CENTER_TOP, t.name, if on { egui::FontId::new(FONT_SM, crate::bold()) } else { egui::FontId::proportional(FONT_SM) }, if on { p.text } else { p.text2 }); + if r.on_hover_text(t.about).on_hover_cursor(egui::CursorIcon::PointingHand).clicked() && !on { + picked = Some(t.id); + } + } + }); + ui.add_space(gap); + } + if self.state.shell_template.is_empty() { + ui.label(RichText::new(t("現在是自訂的顏色(下面的強調色和更多外觀設定);點一個風格整套換。")).size(FONT_XS).color(p.text3)); + } + picked + } +} diff --git a/src/app/remote_ui.rs b/src/app/remote_ui.rs index 44ef337..3045892 100644 --- a/src/app/remote_ui.rs +++ b/src/app/remote_ui.rs @@ -97,8 +97,9 @@ const MAX_WAITING_FROM_MEMBERS: usize = 8; /// 設定 › 一般 › 外觀 as the phone's colours: the shell the desktop draws, light and dark. pub(super) fn phone_palettes(st: &crate::model::State) -> serde_json::Value { - let one = |dark| remote::palette_json(&crate::theme::shell(st.shell_tone, &st.shell_accent, st.shell_contrast, dark)); - json!({"light": one(false), "dark": one(true)}) + let one = |dark| remote::palette_json(&crate::theme::palette_for(&st.shell_template, st.shell_tone, &st.shell_accent, st.shell_contrast, dark)); + // (And the 風格's chat backdrop: dots, a grid, waves, or none.) + json!({"light": one(false), "dark": one(true), "backdrop": crate::theme::backdrop(&st.shell_template)}) } impl App { @@ -320,7 +321,7 @@ impl App { self.scr.cfg_hash.hash(&mut h); (&self.state.folders, self.state.loose_index, &self.state.pin_order, self.state.accent as u8, self.newer_build.is_some()).hash(&mut h); // 外觀: the phone wears the desktop's theme and colours. - (self.state.theme as u8, &self.state.shell_accent, self.state.shell_tone.to_bits(), self.state.shell_contrast.to_bits()).hash(&mut h); + (self.state.theme as u8, &self.state.shell_accent, &self.state.shell_template, self.state.shell_tone.to_bits(), self.state.shell_contrast.to_bits()).hash(&mut h); for b in &self.state.bots { (b.id, &b.name, &b.color, b.unread, b.messages.len(), &b.thinking, &b.step_model).hash(&mut h); // (What the phone's home, editor and reactions show.) @@ -2211,6 +2212,12 @@ impl App { crate::model::Accent::BotColor => "bot_color", }, "timezone": st.timezone, "notify": st.notify, "language": st.language, + // 風格: the one worn ("" = 自訂) and each one's colours for the phone's little pictures. + "style": st.shell_template, + "styles": crate::theme::TEMPLATES.iter().map(|t| { + let look = |dark| { let p = crate::theme::palette_for(t.id, 1.0, "clay", st.shell_contrast, dark); let pj = remote::palette_json(&p); json!({"pane": pj["pane"], "side": pj["side"], "text3": pj["text3"], "hover": pj["hover"], "active": pj["active"], "bubble": pj["bubble-user"], "accent": pj["accent"], "line": pj["line"], "grid": pj["grid"]}) }; + json!({"id": t.id, "name": t.name, "about": t.about, "backdrop": t.backdrop, "light": look(false), "dark": look(true)}) + }).collect::>(), "direct_mode": st.direct_mode, "direct_locked": !self.managed.direct.allows() || !self.managed.local.allows(), "smart_mode": st.smart_mode, "auto_review": st.auto_review, "allow_rules": st.review_allow_rules, "ask_rules": st.review_ask_rules, diff --git a/src/appctl.rs b/src/appctl.rs index e51474a..53c49db 100644 --- a/src/appctl.rs +++ b/src/appctl.rs @@ -174,9 +174,11 @@ pub fn specs() -> Vec { "step_model": {"type": "string", "description": "The quicker model for planned steps: \"\" automatic, \"off\" none."}, "color": {"type": "string", "description": "black, red, orange, yellow, green, cyan, blue, purple, magenta, brown, or #rrggbb."}, "shape": {"type": "string", "description": "squircle, blob, capsule, egg, hex, gem, cloud, arch, star, heart, shield, pebble."}}}}), - json!({"name": "update_settings", "description": "Change app settings: theme (light/dark/system), accent (bot_color/black), timezone (IANA). Running tasks on the person's own computer can only be turned on by the person.", + json!({"name": "update_settings", "description": "Change app settings: theme (light/dark/system), style (風格: a whole look), accent (bot_color/black), timezone (IANA). Running tasks on the person's own computer can only be turned on by the person.", "parameters": {"type": "object", "properties": { - "theme": {"type": "string", "enum": ["light", "dark", "system"]}, "accent": {"type": "string", "enum": ["quiet", "bot_color", "black"], "description": "聊天的顏色: quiet = your messages in a light grey bubble (default), bot_color = in the bot's colour, black"}, "timezone": {"type": "string"}}}}), + "theme": {"type": "string", "enum": ["light", "dark", "system"]}, + "style": {"type": "string", "enum": ["paper", "night", "ink", "moss", "ocean", "candy", "sunset", "terminal", "custom"], "description": "風格 (colours and the chat's backdrop, desktop and phone): paper 紙 (default), night 夜, ink 墨, moss 苔 (dots), ocean 海 (waves), candy 糖 (dots), sunset 夕陽 (waves), terminal 終端機 (grid); custom = the person's own accent and dials"}, + "accent": {"type": "string", "enum": ["quiet", "bot_color", "black"], "description": "聊天的顏色: quiet = your messages in a light grey bubble (default), bot_color = in the bot's colour, black"}, "timezone": {"type": "string"}}}}), crate::mcp::manage_spec(), crate::hooks::manage_spec(), crate::chatgpt::spec(), @@ -1095,6 +1097,20 @@ pub fn apply(state: &mut State, bot_id: u64, name: &str, args: &str) -> Outcome out.text.push_str(&format!("主題「{t}」不存在(可用 dark、light、system)。\n")); } } + if let Some(st) = s("style") { + if st == "custom" { + state.shell_template.clear(); + out.theme_changed = true; + changed.push("風格 → 自訂".to_string()); + } else if let Some(t) = crate::theme::template(&st) { + state.shell_template = t.id.to_string(); + out.theme_changed = true; + changed.push(format!("風格 → {}({})", t.name, t.about)); + } else { + let ids: Vec<&str> = crate::theme::TEMPLATES.iter().map(|t| t.id).collect(); + out.text.push_str(&format!("風格「{st}」不存在(可用 {}、custom)。\n", ids.join("、"))); + } + } if let Some(a) = s("accent") { state.accent = match a.as_str() { "bot_color" => Accent::BotColor, @@ -1444,6 +1460,10 @@ mod tests { assert!(m.ok && m.wake[0].0 == 3, "{}", m.text); assert!(apply(&mut st, 1, "update_bot", r#"{"default_computer":"火星"}"#).text.contains("沒有")); assert!(apply(&mut st, 1, "update_settings", r#"{"theme":"dark","timezone":"Asia/Tokyo"}"#).theme_changed); + // 風格: a whole look by name; custom goes back to the person's own dials. + let styled = apply(&mut st, 1, "update_settings", r#"{"style":"ocean"}"#); + assert!(styled.theme_changed && st.shell_template == "ocean" && styled.text.contains("海"), "{}", styled.text); + assert!(apply(&mut st, 1, "update_settings", r#"{"style":"custom"}"#).theme_changed && st.shell_template.is_empty()); assert_eq!(st.timezone, "Asia/Tokyo"); } diff --git a/src/icons.rs b/src/icons.rs index 5f34250..944166f 100644 --- a/src/icons.rs +++ b/src/icons.rs @@ -97,6 +97,13 @@ pub enum Icon { Map, Scan, Send, + // 設定's rows (setting_icon). + Palette, + Moon, + Globe, + Sliders, + Volume, + Drive, } impl Icon { @@ -199,6 +206,12 @@ impl Icon { Icon::Map => include_str!("../icons/lucide/map.svg"), Icon::Scan => include_str!("../icons/lucide/scan.svg"), Icon::Send => include_str!("../icons/lucide/send.svg"), + Icon::Palette => include_str!("../icons/lucide/palette.svg"), + Icon::Moon => include_str!("../icons/lucide/moon.svg"), + Icon::Globe => include_str!("../icons/lucide/globe.svg"), + Icon::Sliders => include_str!("../icons/lucide/sliders-horizontal.svg"), + Icon::Volume => include_str!("../icons/lucide/volume-2.svg"), + Icon::Drive => include_str!("../icons/lucide/hard-drive.svg"), Icon::CircleCheck => include_str!("../icons/lucide/circle-check.svg"), Icon::CircleX => include_str!("../icons/lucide/circle-x.svg"), Icon::Minus => include_str!("../icons/lucide/minus.svg"), @@ -342,6 +355,52 @@ pub fn button(ui: &mut egui::Ui, icon: Icon, size: f32, col: Color32, hover_fill r.on_hover_cursor(egui::CursorIcon::PointingHand) } +/// The picture before a setting's name (設定: every row has one — the eye finds 通知 by its bell +/// before it reads the word). By the words in its name, first match wins; a name that matches +/// none gets the plain sliders. +pub fn setting_icon(label: &str) -> Icon { + const RULES: &[(&[&str], Icon)] = &[ + (&["上網"], Icon::Globe), + (&["頁面"], Icon::FileText), + (&["合作", "同事"], Icon::Users), + (&["電話", "簡訊"], Icon::Message), + (&["主題"], Icon::Moon), + (&["風格", "強調色", "顏色", "底色", "對比", "外觀", "外殼"], Icon::Palette), + (&["密度"], Icon::Apps), + (&["慶祝"], Icon::Star), + (&["頭像"], Icon::Smile), + (&["語言"], Icon::Globe), + (&["時區", "時間"], Icon::Clock), + (&["通知", "響一聲", "提醒"], Icon::Bell), + (&["記憶", "意思找"], Icon::Brain), + (&["資料夾", "文件", "檔案"], Icon::Folder), + (&["金鑰", "Token", "token", "密鑰"], Icon::Key), + (&["密碼", "保險庫", "兩步"], Icon::Lock), + (&["瀏覽器", "網址", "網頁"], Icon::Globe), + (&["發布前", "檢查"], Icon::CircleCheck), + (&["更新", "版本", "重新啟動"], Icon::Update), + (&["備份", "快照", "還原"], Icon::History), + (&["磁碟", "用量", "容量"], Icon::Drive), + (&["團隊", "成員", "分享"], Icon::Users), + (&["帳號", "帳戶", "登入", "登出", "個人"], Icon::Person), + (&["手機", "裝置"], Icon::Monitor), + (&["語音", "聽", "說", "朗讀", "聲音"], Icon::Volume), + (&["麥克風", "錄音"], Icon::Mic), + (&["審核", "規則", "權限", "直接操作", "一律", "允許", "詢問", "隔離", "智慧"], Icon::Shield), + (&["連接器", "MCP", "整合"], Icon::Apps), + (&["管道", "Telegram", "Slack", "Discord", "訊息"], Icon::Message), + (&["技能"], Icon::Sparkle), + (&["模型", "AI"], Icon::Sparkle), + (&["電腦", "螢幕", "SSH", "Docker", "主機", "容器", "終端機", "執行"], Icon::Monitor), + (&["例行", "排程", "日程"], Icon::Alarm), + (&["工作流"], Icon::Workflow), + (&["Bot"], Icon::Bot), + (&["園丁", "改進", "診斷"], Icon::Target), + (&["資料", "放在哪"], Icon::Drive), + ]; + RULES.iter().find(|(words, _)| words.iter().any(|w| label.contains(w))).map(|(_, i)| *i).unwrap_or(Icon::Sliders) +} + /// A model service's mark: a small rounded tile in the service's own colour with a simple shape /// drawn here (no one's artwork copied — just enough to tell them apart at a glance, the way an /// app icon is found before its name is read). The same tile in light and dark. diff --git a/src/model.rs b/src/model.rs index 3a072aa..46c8396 100644 --- a/src/model.rs +++ b/src/model.rs @@ -762,6 +762,9 @@ pub struct State { pub shell_accent: String, #[serde(default = "default_shell_contrast")] pub shell_contrast: f32, + /// 風格 (theme::TEMPLATES): one whole look; empty = 自訂 (the dials above). + #[serde(default, skip_serializing_if = "String::is_empty")] + pub shell_template: String, /// 緊湊間距(設定 › 一般);關=寬鬆。 #[serde(default)] pub dense: bool, @@ -1420,6 +1423,7 @@ impl State { shell_tone: 1.0, shell_accent: "clay".into(), shell_contrast: 1.0, + shell_template: String::new(), dense: false, celebrate: true, motion: String::new(), diff --git a/src/theme.rs b/src/theme.rs index da6074b..5b1510e 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -222,6 +222,52 @@ const fn rgb(r: u8, g: u8, b: u8) -> Color32 { Color32::from_rgb(r, g, b) } +/// 風格 (設定 › 一般 › 外觀): a whole look in one choice — its ink, paper and accent in light and +/// in dark — and the chat's backdrop (none, dots, grid, waves). Picking a 強調色 or moving the +/// 色調 dial after goes back to 自訂 (the dials). The desktop and the phone wear the same one. +pub struct Template { + pub id: &'static str, + pub name: &'static str, + pub about: &'static str, + /// (ink, paper, accent) in light, and in dark. + pub light: (Color32, Color32, Color32), + pub dark: (Color32, Color32, Color32), + /// The chat's backdrop: "" (plain), "dots", "grid" or "waves". + pub backdrop: &'static str, +} + +pub const TEMPLATES: [Template; 8] = [ + Template { id: "paper", name: "紙", about: "溫暖的紙和墨,黏土色點綴(預設)", light: (rgb(0x25, 0x22, 0x1f), rgb(0xfa, 0xf9, 0xf6), rgb(0xc0, 0x62, 0x44)), dark: (rgb(0xf2, 0xf0, 0xeb), rgb(0x1e, 0x1d, 0x1b), rgb(0xd8, 0x83, 0x66)), backdrop: "" }, + Template { id: "night", name: "夜", about: "冷靜的灰,一點靛藍", light: (rgb(0x20, 0x21, 0x24), rgb(0xf6, 0xf6, 0xf8), rgb(0x5e, 0x6a, 0xd2)), dark: (rgb(0xf0, 0xf0, 0xf2), rgb(0x10, 0x11, 0x12), rgb(0x7c, 0x87, 0xe0)), backdrop: "" }, + Template { id: "ink", name: "墨", about: "只有黑和白,最安靜", light: (rgb(0x0d, 0x0d, 0x0d), rgb(0xf9, 0xf9, 0xf9), rgb(0x0d, 0x0d, 0x0d)), dark: (rgb(0xf7, 0xf7, 0xf7), rgb(0x0a, 0x0a, 0x0a), rgb(0xf7, 0xf7, 0xf7)), backdrop: "" }, + Template { id: "moss", name: "苔", about: "綠色的紙,背景有點點", light: (rgb(0x1f, 0x24, 0x20), rgb(0xf4, 0xf6, 0xf2), rgb(0x4a, 0x7c, 0x59)), dark: (rgb(0xec, 0xf0, 0xea), rgb(0x15, 0x18, 0x15), rgb(0x7f, 0xaa, 0x8a)), backdrop: "dots" }, + Template { id: "ocean", name: "海", about: "藍色的海,背景有波浪", light: (rgb(0x13, 0x29, 0x3d), rgb(0xf2, 0xf7, 0xfb), rgb(0x1f, 0x7a, 0xb8)), dark: (rgb(0xe3, 0xee, 0xf7), rgb(0x0c, 0x18, 0x22), rgb(0x5f, 0xb0, 0xe6)), backdrop: "waves" }, + Template { id: "candy", name: "糖", about: "粉粉的糖果色,背景有點點", light: (rgb(0x3b, 0x23, 0x40), rgb(0xff, 0xf5, 0xfa), rgb(0xd6, 0x45, 0x7f)), dark: (rgb(0xf7, 0xe6, 0xf0), rgb(0x1f, 0x14, 0x20), rgb(0xf0, 0x7a, 0xab)), backdrop: "dots" }, + Template { id: "sunset", name: "夕陽", about: "橘紅的傍晚,暖暖的", light: (rgb(0x3a, 0x22, 0x14), rgb(0xff, 0xf6, 0xee), rgb(0xe0, 0x6a, 0x2c)), dark: (rgb(0xf6, 0xe9, 0xde), rgb(0x1d, 0x13, 0x0d), rgb(0xf2, 0x9a, 0x5c)), backdrop: "waves" }, + Template { id: "terminal", name: "終端機", about: "黑底綠字,背景有格線", light: (rgb(0x0e, 0x2a, 0x12), rgb(0xf1, 0xf7, 0xee), rgb(0x2d, 0x8a, 0x3e)), dark: (rgb(0xa8, 0xf0, 0xa0), rgb(0x07, 0x10, 0x0a), rgb(0x4f, 0xe3, 0x6a)), backdrop: "grid" }, +]; + +pub fn template(id: &str) -> Option<&'static Template> { + TEMPLATES.iter().find(|t| t.id == id) +} + +/// The shell to wear: the 風格 picked (`template`), else the three dials (`shell`). +pub fn palette_for(template_id: &str, tone: f32, accent: &str, contrast: f32, dark: bool) -> Palette { + match template(template_id) { + Some(t) => { + let (ink, paper, acc) = if dark { t.dark } else { t.light }; + let (danger, up) = if dark { (rgb(0xe2, 0x6e, 0x6e), rgb(0x6f, 0xb9, 0x7d)) } else { (rgb(0xb4, 0x2a, 0x2a), rgb(0x2e, 0x7d, 0x3f)) }; + build(ink, paper, acc, danger, up, contrast.clamp(0.6, 1.5), dark) + } + None => shell(tone, accent, contrast, dark), + } +} + +/// The chat's backdrop of a 風格 ("" for none, or 自訂). +pub fn backdrop(template_id: &str) -> &'static str { + template(template_id).map(|t| t.backdrop).unwrap_or("") +} + /// The accents the person can pick (設定 › 一般): name, 中文名, light, dark. pub const ACCENTS: [(&str, &str, Color32, Color32); 8] = [ ("clay", "黏土", rgb(0xc0, 0x62, 0x44), rgb(0xd8, 0x83, 0x66)), @@ -402,6 +448,29 @@ pub fn is_dark(p: Palette) -> bool { (0.2126 * p.pane.r() as f32 + 0.7152 * p.pane.g() as f32 + 0.0722 * p.pane.b() as f32) < 128.0 } +#[cfg(test)] +mod template_tests { + use super::*; + + /// Every 風格 reads: its text stands off its page in light and in dark, its sidebar steps + /// the right way, and 紙 is the shipped default exactly. + #[test] + fn every_template_reads_in_light_and_dark() { + let luma = |c: Color32| 0.2126 * c.r() as f32 + 0.7152 * c.g() as f32 + 0.0722 * c.b() as f32; + for t in &TEMPLATES { + let l = palette_for(t.id, 1.0, "clay", 1.0, false); + let d = palette_for(t.id, 1.0, "clay", 1.0, true); + assert!(luma(l.pane) - luma(l.text) > 150.0, "{} light", t.id); + assert!(luma(d.text) - luma(d.pane) > 150.0, "{} dark", t.id); + assert!(!is_dark(l) && is_dark(d), "{}", t.id); + assert!(["", "dots", "grid", "waves"].contains(&t.backdrop), "{}", t.id); + } + assert_eq!(palette_for("paper", 1.0, "clay", 1.0, false).pane, LIGHT.pane); + // No 風格 (自訂): the dials, as before. + assert_eq!(palette_for("", 0.0, "indigo", 1.0, false).accent, shell(0.0, "indigo", 1.0, false).accent); + } +} + #[cfg(test)] mod dark_tests { use super::*;