修手機接管電腦後回不去;新增「風格」(8 套:紙、夜、墨、苔、海、糖、夕陽、終端機,一套顏色加聊天背景花紋,電腦和手機一起換,也能請 Bot 換);設定每一列都有圖示(電腦和手機)。
- 接管回不去(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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
This commit is contained in:
parent
806ac8a9f1
commit
45c529d7f4
|
|
@ -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。
|
||||
|
|
|
|||
|
|
@ -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`(示範資料)。看到:外觀的八個點、聊天的顏色三個點、語言、「更多外觀設定」;「語音服務」的聽、說兩列和各自的服務選單。拉滑桿當下就換、設好的樣子靠自動測試。
|
||||
|
|
|
|||
|
|
@ -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 再開一次。
|
||||
|
|
|
|||
|
|
@ -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` 改(使用者看到確認卡片、按允許才生效)。其他設定告訴使用者在哪個分頁、哪一塊。
|
||||
|
||||
前提:
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<!-- @license lucide-static v1.67.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-globe"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<circle cx="12" cy="12" r="10" />
|
||||
<path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20" />
|
||||
<path d="M2 12h20" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 407 B |
|
|
@ -0,0 +1,18 @@
|
|||
<!-- @license lucide-static v1.67.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-hard-drive"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<line x1="22" x2="2" y1="12" y2="12" />
|
||||
<path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z" />
|
||||
<line x1="6" x2="6.01" y1="16" y2="16" />
|
||||
<line x1="10" x2="10.01" y1="16" y2="16" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 543 B |
|
|
@ -0,0 +1,15 @@
|
|||
<!-- @license lucide-static v1.67.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-moon"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 409 B |
|
|
@ -0,0 +1,19 @@
|
|||
<!-- @license lucide-static v1.67.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-palette"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z" />
|
||||
<circle cx="13.5" cy="6.5" r=".5" fill="currentColor" />
|
||||
<circle cx="17.5" cy="10.5" r=".5" fill="currentColor" />
|
||||
<circle cx="6.5" cy="12.5" r=".5" fill="currentColor" />
|
||||
<circle cx="8.5" cy="7.5" r=".5" fill="currentColor" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 649 B |
|
|
@ -0,0 +1,23 @@
|
|||
<!-- @license lucide-static v1.67.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-sliders-horizontal"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<line x1="21" x2="14" y1="4" y2="4" />
|
||||
<line x1="10" x2="3" y1="4" y2="4" />
|
||||
<line x1="21" x2="12" y1="12" y2="12" />
|
||||
<line x1="8" x2="3" y1="12" y2="12" />
|
||||
<line x1="21" x2="16" y1="20" y2="20" />
|
||||
<line x1="12" x2="3" y1="20" y2="20" />
|
||||
<line x1="14" x2="14" y1="2" y2="6" />
|
||||
<line x1="8" x2="8" y1="10" y2="14" />
|
||||
<line x1="16" x2="16" y1="18" y2="22" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 672 B |
|
|
@ -0,0 +1,17 @@
|
|||
<!-- @license lucide-static v1.67.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-volume-2"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z" />
|
||||
<path d="M16 9a5 5 0 0 1 0 6" />
|
||||
<path d="M19.364 18.364a9 9 0 0 0 0-12.728" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 555 B |
|
|
@ -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": '<path d="m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551"/>',
|
||||
"log-out": '<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" x2="9" y1="12" y2="12"/>',
|
||||
"bell": '<path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/>',
|
||||
"palette": '<path d="M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z"/><circle cx="13.5" cy="6.5" r=".5" fill="currentColor"/><circle cx="17.5" cy="10.5" r=".5" fill="currentColor"/><circle cx="6.5" cy="12.5" r=".5" fill="currentColor"/><circle cx="8.5" cy="7.5" r=".5" fill="currentColor"/>',
|
||||
"moon": '<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>',
|
||||
"shield": '<path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/>',
|
||||
"plug": '<path d="M12 22v-5"/><path d="M9 8V2"/><path d="M15 8V2"/><path d="M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z"/>',
|
||||
|
|
@ -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) : ""}<div class="mid"><div class="k">${esc(o.k)}</div>${o.v ? `<div class="v">${esc(o.v)}</div>` : ""}</div>${o.r != null ? `<div class="r">${esc(o.r)}</div>` : ""}${o.sw != null ? `<label class="sw"><input type="checkbox" ${o.sw ? "checked" : ""} ${o.swdata || ""} ${o.disabled ? "disabled" : ""}><i></i></label>` : ""}${o.tap && o.chev !== false ? `<span class="chev">${ic("chevron-right", 16)}</span>` : ""}</${o.tap ? "button" : "div"}>`;
|
||||
const group = (title, inner, extra = "") => `${title ? `<div class="gt">${esc(title)}${extra}</div>` : ""}<div class="group">${inner}</div>`;
|
||||
// 設定 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 = `<div class="hero">${face(b, "lg")}<div class="n">${esc(b.name)}</div>${held ? `<div class="d">顯示的是上次的設定,讀到最新的才能改</div>` : ""}</div>`;
|
||||
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 ? `<div class="note" style="padding:8px 16px">${note}</div>` : "")) : "";
|
||||
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 ? `<div class="note" style="padding:8px 16px">${note}</div>` : "")) : "";
|
||||
h += ticks("能力", "abilities", d.abilities, "沒勾的工具不會給它,也不佔它每一輪的字數。");
|
||||
h += ticks("會的技能", "skills", d.skills, "") .replace(/^(<div class="gt">會的技能)/, `$1<button data-allsk="1" style="margin-left:auto">${(d.skills || []).every((x) => x.on) ? "全不選" : "全選"}</button>`);
|
||||
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) => `<div class="item">${ic("shield", 17)}<div class="mid"><div class="v" style="color:var(--text);font-size:var(--fs-ui)">${esc(r)}</div></div><button class="btn sm no" data-rule="${esc(r)}">移除</button></div>`).join("") || `<div class="note" style="padding:12px 16px">還沒有。在核准時選「一律允許」就會記在這裡。</div>`);
|
||||
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("") + `<div class="note" style="padding:8px 16px">示範要在那台電腦上錄;Bot 在對話裡會照著做。</div>`);
|
||||
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("") + `<div class="note" style="padding:8px 16px">示範要在那台電腦上錄;Bot 在對話裡會照著做。</div>`);
|
||||
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 + `<div style="height:calc(var(--safe-b) + 24px)"></div>`;
|
||||
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 += `<div class="gt">風格</div><div class="tpl-grid">${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 `<button class="tpl ${on ? "on" : ""}" data-s="style" data-style="${t.id}" title="${esc(t.about)}"><span class="pic" style="background-color:${c.pane};border-color:${c.line};${bd}"><i class="sd" style="background:${c.side}"><b style="background:${c.active}"></b><b style="background:${c.hover}"></b></i><i class="ln" style="background:${c.text3}"></i><i class="ln s" style="background:${c.text3}"></i><i class="bb" style="background:${c.bubble}"></i><i class="dt" style="background:${c.accent}"></i></span><span class="nm">${esc(t.name)}</span></button>`;
|
||||
}).join("")}</div>${st.style ? "" : `<div class="note" style="padding-top:4px">現在是自訂的顏色(電腦上的強調色);點一個風格整套換,電腦和手機一起。</div>`}`;
|
||||
}
|
||||
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 += `<div class="note">金鑰只存在這台 AnyBot,手機寫得進去、看不到。</div>`;
|
||||
}
|
||||
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 += `<div class="note">用一般的話寫,例如「付款前先問我」。兩邊都符合時先問。${st.direct_mode ? "直接操作開著:「一律詢問」照樣檢查,「直接允許」用不到。" : st.auto_review === false ? "自動審核關著時不會用這些規則。" : ""}</div>`;
|
||||
}
|
||||
if (kind === "integrations") {
|
||||
const dot = (ok, on) => `<span style="width:8px;height:8px;border-radius:50%;flex:none;background:${!on ? "var(--text4)" : ok ? "var(--ok)" : "var(--warn)"}"></span>`;
|
||||
h += group("訊息管道", (st.channels || []).map((c) => `<div class="item">${dot(c.ok, c.enabled)}<div class="mid"><div class="k">${esc(c.kind)} · ${esc(c.name)}</div><div class="v">由「${esc(c.bot)}」回覆${c.note ? " · " + esc(c.note) : ""}</div></div>${isOwner() ? `<label class="sw"><input type="checkbox" ${c.enabled ? "checked" : ""} data-ch="${c.id}"><i></i></label><button class="ib" data-chrm="${c.id}" title="移除">${ic("trash", 16)}</button>` : ""}</div>`).join("") || `<div class="note" style="padding:12px 16px">還沒有。Telegram、Slack、Discord… 要在電腦上的 AnyBot 新增(需要輸入 Token)。</div>`);
|
||||
h += group("連接器(MCP)", ((st.mcp || []).map((m) => `<div class="item">${dot(m.tools != null, m.enabled)}<div class="mid"><div class="k">${esc(m.name)}</div><div class="v">${!m.enabled ? "已關閉" : m.tools != null ? `已連上,${m.tools} 個工具` : m.error ? esc(m.error) : "連線中…"}</div></div>${isOwner() ? `${m.enabled ? `<button class="ib" data-mcpre="${esc(m.name)}" title="重新連線">${ic("refresh", 16)}</button>` : ""}<label class="sw"><input type="checkbox" ${m.enabled ? "checked" : ""} data-mcp="${esc(m.name)}"><i></i></label><button class="ib" data-mcprm="${esc(m.name)}" title="移除">${ic("trash", 16)}</button>` : ""}</div>`).join("") || `<div class="note" style="padding:12px 16px">還沒有連接器</div>`) + (isOwner() ? item({icon: "plus", k: "從公用市集加入", v: "搜尋官方 MCP Registry 裡用網址連的連接器", tap: 1, data: 'data-mcpmarket="1"'}) : ""));
|
||||
h += group("連接器(MCP)", ((st.mcp || []).map((m) => `<div class="item">${dot(m.tools != null, m.enabled)}<div class="mid"><div class="k">${esc(m.name)}</div><div class="v">${!m.enabled ? "已關閉" : m.tools != null ? `已連上,${m.tools} 個工具` : m.error ? esc(m.error) : "連線中…"}</div></div>${isOwner() ? `${m.enabled ? `<button class="ib" data-mcpre="${esc(m.name)}" title="重新連線">${ic("refresh", 16)}</button>` : ""}<label class="sw"><input type="checkbox" ${m.enabled ? "checked" : ""} data-mcp="${esc(m.name)}"><i></i></label><button class="ib" data-mcprm="${esc(m.name)}" title="移除">${ic("trash", 16)}</button>` : ""}</div>`).join("") || `<div class="note" style="padding:12px 16px">還沒有連接器</div>`) + (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 `<div class="item"><div class="mid" data-skill="${i}" style="cursor:pointer"><div class="k">${esc(k.name)}${tags ? ` <span class="pill" style="margin-left:4px">${esc(tags)}</span>` : ""}</div><div class="v">${esc(k.description)}</div></div>${isOwner() ? `<label class="sw"><input type="checkbox" ${k.enabled !== false ? "checked" : ""} data-sksw="${esc(k.name)}"><i></i></label>` : ""}</div>`;
|
||||
}).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 || `<div class="note" style="padding:12px 16px">還沒有技能。可從下方「技能市集」一鍵加入,或在聊天裡請 Bot 幫你建立。</div>`) + skActions);
|
||||
}
|
||||
if (kind === "computers") h += computersHtml(st);
|
||||
if (kind === "vault") h += `<div class="empty">${ic("lock", 28)}<br><br>保險庫裡的密碼、卡號和聯絡資訊,只在電腦上的 AnyBot 管理。<br>Bot 用到時由 AnyBot 直接填進網頁,不會交給模型,也不會經過手機。</div>`;
|
||||
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("") || `<div class="note" style="padding:12px 16px">沒有</div>`);
|
||||
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("") || `<div class="note" style="padding:12px 16px">沒有</div>`);
|
||||
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 += `<div class="note">Bot 的電腦的更新在「電腦」裡。</div>`;
|
||||
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 += `<div class="note">畫面看起來被切到、上面糊糊的、下面空一塊時,按「畫面」打開量尺截圖給我們。</div>`;
|
||||
}
|
||||
el.innerHTML = h + `<div style="height:calc(var(--safe-b) + 24px)"></div>`;
|
||||
|
|
@ -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 += `<div class="gt">紀錄</div><div class="group"><div class="log">${esc(box.log.slice(-25).join("\n"))}</div></div>`;
|
||||
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;
|
||||
|
|
|
|||
76
src/app.rs
76
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<egui::Pos2> = (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;
|
||||
|
|
|
|||
|
|
@ -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<T: PartialEq + Copy>(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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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::<Vec<_>>(),
|
||||
"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,
|
||||
|
|
|
|||
|
|
@ -174,9 +174,11 @@ pub fn specs() -> Vec<Value> {
|
|||
"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");
|
||||
}
|
||||
|
||||
|
|
|
|||
59
src/icons.rs
59
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.
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
69
src/theme.rs
69
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::*;
|
||||
|
|
|
|||
Loading…
Reference in New Issue