From 5144259c8e6115c2a416f295a88f2d45dd431a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Mon, 16 Nov 2026 10:55:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Bot=20=E7=9A=84=E9=9B=BB=E8=85=A6?= =?UTF-8?q?=E6=8F=9B=E6=88=90=20LazyBoy2=20=E7=9A=84=20XFCE=20=E6=A1=8C?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=E5=8A=A0=E4=B8=8A=E6=AA=94=E6=A1=88=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=93=A1=E3=80=81=E6=96=87=E5=AD=97=E7=B7=A8=E8=BC=AF?= =?UTF-8?q?=E5=99=A8=E3=80=81=E5=BD=B1=E5=83=8F=E6=AA=A2=E8=A6=96=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bot 的電腦(第 12 版):原本的 fluxbox 只有右鍵選單和一條細工作列,不好用;現在照 LazyBoy2 的 box 換成精簡的 XFCE(xfwm4、xfdesktop、xfce4-panel,沒有工作階段管理員)。下方工作列有「應用 程式」、瀏覽器、檔案管理員、終端機、開著的視窗和時鐘;Arc-Dark 深色主題、Papirus 圖示、jf open 粉圓字型(建映像檔時下載並核對 sha256);選單、Chromium 和網頁語言是繁體中文(加了 chromium-l10n:LazyBoy2 的 Chromium 介面其實是英文),時區台北。開機就開好瀏覽器,第一次是 說明頁。每個 Bot 自己的螢幕也是同一套桌面。Bot 說「終端機」開的是工作列那個 xfce4-terminal, 說「檔案總管」「Files」開 Thunar、從家目錄開始,回覆用 Bot 說的名字。 LazyBoy2 沒有、這裡加的:檔案管理員 Thunar(有縮圖)、文字編輯器 Mousepad、影像檢視器 Ristretto,檔案按兩下用對的程式開,PDF 和網頁開瀏覽器;檔案管理員和網頁上傳檔案的視窗側邊欄 都有「下載」(Bot 下載的檔案);瀏覽器下載的「在資料夾中顯示」開檔案管理員。應用程式選單只剩 一層,拿掉 XFCE 的設定(每次開機照映像檔重放,而且大多要設定服務才生效)。 實際操作找到的問題:網頁上傳檔案的視窗 1342×1029、比螢幕大,「開啟」掉到螢幕外(GTK 要同時 記著位置才照記住的大小開,沒有就照字型算,粉圓 12 號算出來太大),現在開機時大小和位置一起設; 工作列的「面板 › 登出 › 結束」會把工作列關掉到下次開機,現在一秒後自己回來;工作列按右鍵能 移除、移動項目,現在鎖住(xfconf 的鎖要寫使用者名稱,寫「*」不算數);新視窗擠在左上角蓋住 瀏覽器分頁,現在開在中間。關機時先讓瀏覽器正常關掉,剛登入的 cookie 才會寫進磁碟。 box_update_keeps_files 改讀說明頁(fluxbox 的選單檔沒了);box_screen_is_exact 多測打開檔案 管理員。映像檔約 1.67 GB。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Uirha54sGCEGh2rRbTsSeh --- FEATURES.md | 3 +- bench/computer-use/run.py | 2 +- box/Dockerfile | 89 ++++++++++++++++++++++--- box/a11y | 5 +- box/browser | 4 +- box/fluxbox-init | 9 --- box/fonts.conf | 41 ++++++++++++ box/gtk3-settings.ini | 7 ++ box/licenses/huninn-OFL.txt | 101 ++++++++++++++++++++++++++++ box/menu | 7 -- box/overlay | 2 - box/screen | 18 +++-- box/start.sh | 85 ++++++++++++++++++----- box/terminal | 15 +++++ box/welcome.html | 17 +++++ box/xfce/browser.desktop | 12 ++++ box/xfce/helper-browser.desktop | 11 +++ box/xfce/helper-terminal.desktop | 11 +++ box/xfce/helpers.rc | 3 + box/xfce/menu.xml | 49 ++++++++++++++ box/xfce/mimeapps.list | 22 ++++++ box/xfce/terminal.desktop | 11 +++ box/xfce/wallpaper.svg | 32 +++++++++ box/xfce/xfce4-desktop.xml | 66 ++++++++++++++++++ box/xfce/xfce4-panel-lock.xml | 11 +++ box/xfce/xfce4-panel.xml | 71 ++++++++++++++++++++ box/xfce/xfwm4.xml | 24 +++++++ docs/feature-map/computers.md | 8 ++- src/cloudbox.rs | 111 ++++++++++++++++++++++--------- src/facts.rs | 2 +- 30 files changed, 757 insertions(+), 92 deletions(-) delete mode 100644 box/fluxbox-init create mode 100644 box/fonts.conf create mode 100644 box/gtk3-settings.ini create mode 100644 box/licenses/huninn-OFL.txt delete mode 100644 box/menu delete mode 100644 box/overlay create mode 100644 box/terminal create mode 100644 box/welcome.html create mode 100644 box/xfce/browser.desktop create mode 100644 box/xfce/helper-browser.desktop create mode 100644 box/xfce/helper-terminal.desktop create mode 100644 box/xfce/helpers.rc create mode 100644 box/xfce/menu.xml create mode 100644 box/xfce/mimeapps.list create mode 100644 box/xfce/terminal.desktop create mode 100644 box/xfce/wallpaper.svg create mode 100644 box/xfce/xfce4-desktop.xml create mode 100644 box/xfce/xfce4-panel-lock.xml create mode 100644 box/xfce/xfce4-panel.xml create mode 100644 box/xfce/xfwm4.xml diff --git a/FEATURES.md b/FEATURES.md index 3724ae6..365d2b6 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -852,6 +852,7 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。 - **健康檢查**:每 20 秒看一次,單次最多等 3 秒(原版 /health 的逾時)。 - **Bot 在上面的權限**:這是它自己的電腦,所以指令、改檔案、操作螢幕都不用問你;只有「一律不允許」的指令(例如格式化)還是會擋。可以 `sudo` 安裝套件。 - **開機時間**:最多等 60 秒(估計值)。 +- **桌面**(第 12 版起,照 LazyBoy2 的 box;以前是 fluxbox,只有右鍵選單和一條細工作列,不好用):XFCE(xfwm4 視窗、xfdesktop 桌布、xfce4-panel 工作列,沒有工作階段管理員)。下方工作列:「應用程式」選單、「瀏覽器」、「檔案管理員」、「終端機」、開著的視窗、時鐘;桌面按右鍵也有應用程式選單。應用程式選單只有一層:瀏覽器、檔案管理員、終端機、文字編輯器、影像檢視器(Bot 另外裝的程式出現在「其他」);沒有 XFCE 的設定選項(每次開機照映像檔重放,而且大多要 XFCE 的設定服務才會生效)。這三個是 AnyBot 加的(LazyBoy2 沒有):檔案管理員是 Thunar(有縮圖;在檔案上按兩下:文字檔開文字編輯器 Mousepad、圖片開影像檢視器 Ristretto、PDF 和網頁開瀏覽器;按右鍵「在此開啟終端機」開在那個資料夾),側邊欄和網頁上傳檔案的視窗都有「下載」(/home/bot/Downloads,Bot 下載的檔案在這裡);瀏覽器下載完按「在資料夾中顯示」會開檔案管理員。工作列鎖住:按右鍵沒有移除、移動、屬性(只剩「面板 › 登出/說明/關於」);「登出」只會關掉工作列,一秒後自己回來。新視窗開在螢幕中間。網頁上傳檔案的視窗每次開機設成螢幕的七成寬、四分之三高(GTK 要同時記著位置才會照記住的大小開;沒有時照字型算,粉圓 12 號算出 1342×1029,比螢幕大,「開啟」掉到螢幕外)。Arc-Dark 深色主題、Papirus 圖示、jf open 粉圓字型(OFL,建映像檔時下載並核對 sha256),選單、瀏覽器和網頁語言都是繁體中文(LANG=zh_TW.UTF-8,沒設 LC_ALL,單一指令還能用 LANG=C),時區台北(/etc/localtime,沒有 TZ 變數)。選單裡瀏覽器和終端機各只有一個:瀏覽器一律是 `anybot-browser`,終端機是 `anybot-terminal`(xfce4-terminal,一個視窗一個程式,用桌面的 D-Bus)。開機就在共用螢幕開好瀏覽器,設定檔第一次用時開說明頁「這是 Bot 的電腦」。桌面設定每次開機都照映像檔重放。每個 Bot 自己的螢幕也是同一套桌面(各自的 D-Bus 和 xfconfd,讀同一份設定)。工作列和桌布不在 Bot 截圖的編號裡(看得到,但清單只列在用的視窗)。`docker stop` 時先讓瀏覽器正常關掉(最多 5 秒),剛登入的 cookie 才會寫進磁碟。 ### 快照與三種更新(原版的規則) @@ -1261,7 +1262,7 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。 computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)、drag、scroll、typing、press_key、check_permissions。另外兩個: - **(已併入截圖)「讀 App 畫面」**:按鈕清單現在就在每張截圖裡,不再是另一個工具。很長的內容(終端機的整段捲動紀錄)留開頭 160 字和結尾 400 字。 -- **「打開 App」(computer_use_open_app)**:打開或叫到最前面,顯示的名字也可以(「計算機」→ Calculator)。Bot 的電腦上:chromium(瀏覽器,就是 browser_* 在用的那個,不會開第二個)、xterm(終端機)或其他程式名稱。 +- **「打開 App」(computer_use_open_app)**:打開或叫到最前面,顯示的名字也可以(「計算機」→ Calculator)。Bot 的電腦上:chromium(瀏覽器,就是 browser_* 在用的那個,不會開第二個)、終端機(xfce4-terminal,跟工作列的「終端機」一樣;第 11 版以前是 xterm,xterm 照名字還打得開)、檔案管理員(也認「檔案總管」「Files」「Finder」等,開 Thunar,從家目錄開始)或其他程式名稱;回覆用 Bot 說的名字(「已打開「檔案管理員」」)。 - **(已拿掉)「按住或放開滑鼠」**:拖曳已經涵蓋。 - **「檢查螢幕權限」(computer_use_check_permissions)**:回報「螢幕錄製:已允許/還沒允許」「輔助使用(滑鼠和鍵盤):…」,不會跳出系統視窗。Bot 的電腦上一律可以。 diff --git a/bench/computer-use/run.py b/bench/computer-use/run.py index ee21dfb..42b0fc7 100644 --- a/bench/computer-use/run.py +++ b/bench/computer-use/run.py @@ -177,7 +177,7 @@ TASKS = [ "setup": "ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime; rm -f /etc/timezone; " "for f in /home/bot/.profile /home/bot/.bashrc /home/bot/.bash_profile /home/bot/.pam_environment /etc/environment /etc/profile.d/*tz* /etc/profile.d/*time*; do " "[ -f \"$f\" ] && sed -i '/TZ=/d;/Asia\\/Tokyo/d' \"$f\"; done; " - "grep -l 'TZ=' /proc/[0-9]*/environ 2>/dev/null | cut -d/ -f3 | xargs -r ps -o pid=,comm= -p | grep -E 'fluxbox|xterm' | awk '{print $1}' | xargs -r kill; sleep 1; " + "grep -l 'TZ=' /proc/[0-9]*/environ 2>/dev/null | cut -d/ -f3 | xargs -r ps -o pid=,comm= -p | grep -E 'fluxbox|xfce4-panel|xfce4-terminal|xterm' | awk '{print $1}' | xargs -r kill; sleep 1; " "su bot -c 'date +%Z'", "ask": "把你電腦的時區設成日本東京時間,設好後告訴我現在那台電腦顯示的時間。", "check": lambda dh, ans: "Tokyo" in dx("readlink -f /etc/localtime; cat /etc/timezone 2>/dev/null", dh)[1]}, diff --git a/box/Dockerfile b/box/Dockerfile index 23141a5..af9f41e 100644 --- a/box/Dockerfile +++ b/box/Dockerfile @@ -2,28 +2,93 @@ # (an X11 desktop driven by xdotool, watched through noVNC on port 6080). One TigerVNC server is # the screen and the VNC server; AT-SPI is on, so every app's controls (web pages included) can # be read with their places and numbered on the bot's picture (box/a11y, after XBot's box). +# The desktop is LazyBoy2's box (was fluxbox, a bare menu on a right click): a minimal XFCE +# (xfwm4 + xfdesktop + a panel with 應用程式, 瀏覽器, 終端機, the open windows and a clock), +# Arc-Dark + Papirus + jf open 粉圓, Traditional Chinese menus, Taipei time. Not on LazyBoy2's: +# 檔案管理員 (Thunar, with thumbnails), 文字編輯器 (Mousepad) and 影像檢視器 (Ristretto), so a +# file a bot made or downloaded opens with a double click. FROM debian:bookworm-slim # No TZ here: a TZ variable overrides /etc/localtime for every program, so setting the timezone -# the normal way (/etc/localtime, /etc/timezone) seemed to do nothing. /etc/localtime is UTC. +# the normal way (/etc/localtime, /etc/timezone) seemed to do nothing. /etc/localtime is Taipei. ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8 -RUN apt-get update && apt-get install -y --no-install-recommends \ - tigervnc-standalone-server tigervnc-tools xdotool x11-utils x11-xserver-utils imagemagick fluxbox xterm \ +# dpkg never unpacks docs, man pages or other languages' messages (zh_TW is kept: the XFCE menus +# are in Traditional Chinese). +RUN printf '%s\n' \ + 'path-exclude=/usr/share/doc/*' \ + 'path-include=/usr/share/doc/*/copyright' \ + 'path-exclude=/usr/share/man/*' \ + 'path-exclude=/usr/share/info/*' \ + 'path-exclude=/usr/share/gtk-doc/*' \ + 'path-exclude=/usr/share/backgrounds/*' \ + 'path-exclude=/usr/share/locale/*' \ + 'path-include=/usr/share/locale/locale.alias' \ + 'path-include=/usr/share/locale/zh_TW/*' \ + 'path-include=/usr/share/locale/zh/*' \ + > /etc/dpkg/dpkg.cfg.d/zz-anybot-slim \ + && apt-get update && apt-get install -y --no-install-recommends \ + tigervnc-standalone-server tigervnc-tools xdotool x11-utils x11-xserver-utils imagemagick xterm \ + dbus-x11 xfconf xfce4-panel xfwm4 xfdesktop4 xfce4-settings xfce4-terminal \ + thunar tumbler mousepad ristretto xdg-utils \ + arc-theme papirus-icon-theme adwaita-icon-theme gnome-themes-extra librsvg2-common \ at-spi2-core libatk-adaptor python3-gi gir1.2-atspi-2.0 libglib2.0-bin gsettings-desktop-schemas dconf-gsettings-backend \ - novnc python3-websockify chromium fonts-noto-cjk fonts-noto-color-emoji \ + novnc python3-websockify chromium chromium-l10n fonts-dejavu-core fonts-liberation fonts-noto-cjk fonts-noto-color-emoji \ + locales tzdata \ ca-certificates curl wget git jq unzip zip less nano vim-tiny procps psmisc \ - python3 python3-pip python3-venv nodejs npm sudo tini dbus-x11 xclip poppler-utils \ + python3 python3-pip python3-venv nodejs npm sudo tini xclip poppler-utils \ + && echo "zh_TW.UTF-8 UTF-8" >> /etc/locale.gen && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen \ + && ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime && echo "Asia/Taipei" > /etc/timezone \ + && rm -rf /usr/share/icons/ePapirus /usr/share/icons/ePapirus-Dark /usr/share/icons/Papirus-Light \ + && test -e /usr/share/icons/Papirus-Dark/48x48/apps/web-browser.svg \ + && test -d /usr/share/themes/Arc-Dark/xfwm4 \ + && test -f /usr/share/locale/zh_TW/LC_MESSAGES/xfce4-panel.mo \ && apt-get clean && rm -rf /var/lib/apt/lists/* \ && useradd -m -s /bin/bash bot && echo 'bot ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/bot \ && ln -sf /usr/share/novnc/vnc.html /usr/share/novnc/index.html +# jf open 粉圓 (OFL) as the desktop's font, pinned like LazyBoy2's. +RUN mkdir -p /usr/share/fonts/truetype/huninn \ + && curl -fsSL https://github.com/justfont/open-huninn-font/releases/download/v2.1/jf-openhuninn-2.1.ttf \ + -o /usr/share/fonts/truetype/huninn/jf-openhuninn-2.1.ttf \ + && echo '9d5bf4932d31fe94c18cd8cfddc98bc1b14ce10f4e354c682179db290a99c825 /usr/share/fonts/truetype/huninn/jf-openhuninn-2.1.ttf' | sha256sum -c \ + && fc-cache -f COPY start.sh /usr/local/bin/anybot-box-start COPY a11y /usr/local/bin/anybot-a11y COPY browser /usr/local/bin/anybot-browser COPY screen /usr/local/bin/anybot-screen -COPY fluxbox-init /etc/anybot/fluxbox-init -COPY overlay /etc/anybot/overlay +COPY terminal /usr/local/bin/anybot-terminal COPY Xresources /etc/anybot/Xresources -COPY menu /etc/anybot/menu -RUN chmod +x /usr/local/bin/anybot-box-start /usr/local/bin/anybot-a11y /usr/local/bin/anybot-browser /usr/local/bin/anybot-screen \ +COPY welcome.html /usr/share/anybot/welcome.html +COPY xfce/wallpaper.svg /usr/share/anybot/wallpaper.svg +COPY xfce/xfce4-panel.xml /usr/share/anybot/xfce-skel/xfce4-panel.xml +COPY xfce/xfwm4.xml /usr/share/anybot/xfce-skel/xfwm4.xml +COPY xfce/xfce4-desktop.xml /usr/share/anybot/xfce-skel/xfce4-desktop.xml +COPY xfce/helpers.rc /etc/xdg/xfce4/helpers.rc +COPY xfce/mimeapps.list /etc/xdg/mimeapps.list +COPY xfce/menu.xml /etc/xdg/menus/xfce-applications.menu +COPY xfce/xfce4-panel-lock.xml /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml +COPY xfce/helper-browser.desktop /usr/share/xfce4/helpers/anybot-browser.desktop +COPY xfce/helper-terminal.desktop /usr/share/xfce4/helpers/anybot-terminal.desktop +COPY xfce/browser.desktop /usr/share/applications/anybot-browser.desktop +COPY xfce/terminal.desktop /usr/share/applications/anybot-terminal.desktop +COPY fonts.conf /etc/fonts/conf.d/99-anybot-cjk.conf +COPY gtk3-settings.ini /etc/gtk-3.0/settings.ini +COPY licenses/huninn-OFL.txt /usr/share/licenses/huninn/OFL.txt +RUN chmod +x /usr/local/bin/anybot-box-start /usr/local/bin/anybot-a11y /usr/local/bin/anybot-browser /usr/local/bin/anybot-screen /usr/local/bin/anybot-terminal \ + # The menu shows 瀏覽器 and 終端機 once each: anybot-browser is the one way to start Chromium + # (the same profile and DevTools port as the browser tools), anybot-terminal the terminal. + # (Into [Desktop Entry]: chromium.desktop ends with its actions, where an appended line went.) + && for f in chromium xfce4-terminal debian-xterm debian-uxterm xterm uxterm; do \ + if [ -f "/usr/share/applications/$f.desktop" ]; then sed -i '/^\[Desktop Entry\]/a NoDisplay=true' "/usr/share/applications/$f.desktop"; fi; \ + done \ + # The menu's names in plain words (檔案管理員, not 「Thunar 檔案管理員」); the build stops if a + # new Debian says them differently. + && sed -i 's/^Name\[zh_TW\]=Thunar 檔案管理員$/Name[zh_TW]=檔案管理員/' /usr/share/applications/thunar.desktop \ + && sed -i 's/^Name\[zh_TW\]=Mousepad$/Name[zh_TW]=文字編輯器/' /usr/share/applications/org.xfce.mousepad.desktop \ + && sed -i 's/^Name\[zh_TW\]=Ristretto 影像檢視器$/Name[zh_TW]=影像檢視器/' /usr/share/applications/org.xfce.ristretto.desktop \ + && grep -qx 'Name\[zh_TW\]=檔案管理員' /usr/share/applications/thunar.desktop \ + && grep -qx 'Name\[zh_TW\]=文字編輯器' /usr/share/applications/org.xfce.mousepad.desktop \ + && grep -qx 'Name\[zh_TW\]=影像檢視器' /usr/share/applications/org.xfce.ristretto.desktop \ + # (Which program opens what: /etc/xdg/mimeapps.list; the browser's file says it takes web pages and PDFs.) + && { ! command -v update-desktop-database >/dev/null || update-desktop-database -q /usr/share/applications; } \ # Chromium has no sandbox inside a plain container (no user namespaces); the box itself is # the sandbox. Under gVisor (容器隔離=runsc) the box has its own virtualized kernel and # Chromium's sandbox works: AnyBot then starts the box with ANYBOT_BOX_SANDBOX=1 and the @@ -38,8 +103,10 @@ RUN chmod +x /usr/local/bin/anybot-box-start /usr/local/bin/anybot-a11y /usr/loc # Accessibility on for every app, including those started over `docker exec`. # gail too: GTK 2 apps (lxappearance, PCManFM, many older tools) offer no controls to AT-SPI # without it — no numbers at all, only a picture to guess at. GTK 3 apps ignore it. -ENV DISPLAY=:1 SCREEN_SIZE=1280x800x24 GTK_MODULES=gail:atk-bridge GTK_A11Y=atspi GNOME_ACCESSIBILITY=1 NO_AT_BRIDGE=0 +# Traditional Chinese for every program (menus, Chromium, a terminal's messages); LC_ALL stays +# unset, so one command can still ask for LANG=C. +ENV LANG=zh_TW.UTF-8 LANGUAGE=zh_TW:zh:en DISPLAY=:1 SCREEN_SIZE=1280x800x24 XDG_CURRENT_DESKTOP=XFCE GTK_MODULES=gail:atk-bridge GTK_A11Y=atspi GNOME_ACCESSIBILITY=1 NO_AT_BRIDGE=0 EXPOSE 6080 -LABEL anybot.box.version="11" +LABEL anybot.box.version="12" ENTRYPOINT ["/usr/bin/tini", "--"] CMD ["/usr/local/bin/anybot-box-start"] diff --git a/box/a11y b/box/a11y index c098c9f..d5ee37a 100644 --- a/box/a11y +++ b/box/a11y @@ -25,8 +25,9 @@ ACTIVE = { # Listed when they carry words (headings, labels, cells...). NAMED = {"heading", "label", "static", "text", "image", "table cell", "column header", "row header", "icon", "tool tip", "alert", "dialog", "paragraph"} -# The desktop's own parts are visible in the picture; the list is for the windows worked in. -SKIP_APPS = {"fluxbox", "a11y", "python3", "xterm-wrapper"} +# The desktop's own parts (the panel, the wallpaper, the window manager) are visible in the +# picture; the list is for the windows worked in. +SKIP_APPS = {"xfce4-panel", "xfdesktop", "xfwm4", "wrapper-2.0", "fluxbox", "a11y", "python3", "xterm-wrapper"} def stacked_windows(): diff --git a/box/browser b/box/browser index 245514d..9401b7e 100644 --- a/box/browser +++ b/box/browser @@ -6,6 +6,8 @@ set -euo pipefail export DISPLAY="${DISPLAY:-:1}" HOME=/home/bot export GTK_MODULES=atk-bridge GTK_A11Y=atspi GNOME_ACCESSIBILITY=1 NO_AT_BRIDGE=0 +# Chinese menus and pages asked for in Chinese first (as on LazyBoy2's box). +export LANG="${LANG:-zh_TW.UTF-8}" LANGUAGE="${LANGUAGE:-zh_TW:zh:en}" if [[ -z "${DBUS_SESSION_BUS_ADDRESS:-}" && -r /tmp/anybot-dbus.env ]]; then # shellcheck disable=SC1091 source /tmp/anybot-dbus.env @@ -64,7 +66,7 @@ FLAGS=("${SANDBOX[@]}" --user-data-dir="$PROFILE" --remote-debugging-address=127 --remote-allow-origins=http://127.0.0.1 --force-renderer-accessibility --disable-blink-features=AutomationControlled --disable-dev-shm-usage --disable-gpu --use-angle=swiftshader --enable-unsafe-swiftshader --password-store=basic --no-first-run --no-default-browser-check --disable-session-crashed-bubble --hide-crash-restore-bubble - --disable-features=TranslateUI --start-maximized) + --disable-features=TranslateUI --start-maximized --lang=zh-TW --accept-lang=zh-TW,zh,en-US,en) # Two starts in the same second (the bot and the person) would both find no browser and fight # over the profile ("in use"): one at a time until the first is listening. exec 9>"$LOCK" diff --git a/box/fluxbox-init b/box/fluxbox-init deleted file mode 100644 index a9e9be8..0000000 --- a/box/fluxbox-init +++ /dev/null @@ -1,9 +0,0 @@ -session.screen0.toolbar.visible: true -session.screen0.toolbar.placement: BottomCenter -session.screen0.toolbar.widthPercent: 100 -session.screen0.workspaces: 1 -session.screen0.workspaceNames: Bot 的電腦 -session.screen0.defaultDeco: NORMAL -session.styleOverlay: ~/.fluxbox/overlay -session.screen0.allowRemoteActions: true -session.screen0.rootCommand: xsetroot -solid '#2b2f36' diff --git a/box/fonts.conf b/box/fonts.conf new file mode 100644 index 0000000..b1faef7 --- /dev/null +++ b/box/fonts.conf @@ -0,0 +1,41 @@ + + + + + + 粉圓 + jf open 粉圓 2.1 + + + jf open 粉圓 + jf open 粉圓 2.1 + + + Huninn + jf open 粉圓 2.1 + + + + sans-serif + + jf open 粉圓 2.1 + + + + zh + sans-serif + + jf open 粉圓 2.1 + + + + + monospace + + Noto Sans Mono CJK TC + + + DejaVu Sans Mono + + + diff --git a/box/gtk3-settings.ini b/box/gtk3-settings.ini new file mode 100644 index 0000000..23cc34c --- /dev/null +++ b/box/gtk3-settings.ini @@ -0,0 +1,7 @@ +[Settings] +gtk-font-name=jf open 粉圓 2.1 12 +gtk-icon-theme-name=Papirus-Dark +gtk-theme-name=Arc-Dark +gtk-application-prefer-dark-theme=1 +gtk-dialogs-use-header=true +gtk-menu-images=true diff --git a/box/licenses/huninn-OFL.txt b/box/licenses/huninn-OFL.txt new file mode 100644 index 0000000..7058b6a --- /dev/null +++ b/box/licenses/huninn-OFL.txt @@ -0,0 +1,101 @@ +[Kosugi Maru] +Copyright (c) 2010 MOTOYA CO.,LTD. + +[Varela Round] +Copyright (c) 2011-2016 The Varela Round Project Authors (https://github.com/alefalefalef/Varela-Round-Hebrew/), with Reserved Font Names 'Varela' and 'Varela Round'. + +[jf open huninn] +Copyright (c) 2020-2024 The jf open huninn font is redistributed by justfont Co., LTD., with Reserved Font Names 'open huninn' and 'huninn'. under SIL Open Font License. The Hanzi part of this project was derived from Kosugi Maru under Apache-2.0 (https://www.apache.org/licenses/LICENSE-2.0). + + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/box/menu b/box/menu deleted file mode 100644 index 67b915d..0000000 --- a/box/menu +++ /dev/null @@ -1,7 +0,0 @@ -[begin] (Bot 的電腦) - [exec] (瀏覽器 Chromium) {anybot-browser} - [exec] (終端機) {xterm} - [separator] - [workspaces] (視窗) - [restart] (重新整理桌面) -[end] diff --git a/box/overlay b/box/overlay deleted file mode 100644 index 71e41b5..0000000 --- a/box/overlay +++ /dev/null @@ -1,2 +0,0 @@ -background: none -*.font: Noto Sans CJK TC-10 diff --git a/box/screen b/box/screen index c9c4105..aea5962 100755 --- a/box/screen +++ b/box/screen @@ -27,13 +27,13 @@ mkdir -p "$DIR" 2>/dev/null; chmod 1777 "$DIR" 2>/dev/null TOKENS=/tmp/anybot-vnc-tokens key_ok() { [[ "$1" =~ ^[A-Za-z0-9_-]{1,48}$ ]]; } -# The bot user's side of the desktop (fluxbox, the buses): as is when we are the bot user. +# The bot user's side of the desktop (XFCE, the buses): as is when we are the bot user. as_bot() { if [ "$(id -u)" = 0 ]; then su bot -c "$1"; else sh -c "$1"; fi; } token_set() { { grep -v "^$1: " "$TOKENS" 2>/dev/null; [ -n "${2:-}" ] && echo "$1: localhost:$2"; } > "$TOKENS.new"; mv -f "$TOKENS.new" "$TOKENS"; } alive() { [ -n "${1:-}" ] && kill -0 "$1" 2>/dev/null; } -# The screen's processes (Xtigervnc, its dbus, fluxbox, the accessibility bus, the browser), killed -# youngest first. +# The screen's processes (Xtigervnc, its dbus, the accessibility bus, the desktop, the browser), +# killed youngest first. close() { local d=$DIR/$1 [ -d "$d" ] || return 0 @@ -106,10 +106,18 @@ up() { [ -x "$c" ] && { as_bot "DISPLAY=:$disp DBUS_SESSION_BUS_ADDRESS=$bus setsid $c >/dev/null 2>&1 & echo \$!" 8>&- >> "$d/pids"; break; } done as_bot "DISPLAY=:$disp xrdb -nocpp -merge /home/bot/.Xresources" 2>/dev/null - as_bot "DISPLAY=:$disp DBUS_SESSION_BUS_ADDRESS=$bus setsid fluxbox >/dev/null 2>&1 & echo \$!" 8>&- >> "$d/pids" + xsetroot -display ":$disp" -solid '#2f343f' + # The same desktop as the shared screen (start.sh): window manager, wallpaper, panel. Their + # settings are the shared screen's files, read by this bus's own xfconfd. (A simple command each, + # so $! is the program itself and close() can stop it; the panel's is the loop that brings it + # back when it is closed, as on the shared screen, and ends with the screen.) + local x="DISPLAY=:$disp DBUS_SESSION_BUS_ADDRESS=$bus setsid" + as_bot "$x xfwm4 --compositor=off --sm-client-disable >/dev/null 2>&1 & echo \$!" 8>&- >> "$d/pids" + sleep 0.3 + as_bot "$x xfdesktop --disable-wm-check --sm-client-disable >/dev/null 2>&1 & echo \$!" 8>&- >> "$d/pids" + as_bot "$x sh -c 'while xdpyinfo >/dev/null 2>&1; do xfce4-panel --disable-wm-check --sm-client-disable; sleep 1; done' >/dev/null 2>&1 & echo \$!" 8>&- >> "$d/pids" # Copy and paste with the person's computer (as on the shared screen: start.sh). as_bot "DISPLAY=:$disp setsid vncconfig -nowin >/dev/null 2>&1 & echo \$!" 8>&- >> "$d/pids" - xsetroot -display ":$disp" -solid '#2b2f36' { echo "DISPLAY=:$disp" echo "DBUS_SESSION_BUS_ADDRESS=$bus" diff --git a/box/start.sh b/box/start.sh index 6e46aa8..ccd0e64 100644 --- a/box/start.sh +++ b/box/start.sh @@ -1,28 +1,40 @@ #!/bin/bash -# Boots the desktop: X server, window manager, VNC and the noVNC web viewer. +# Boots the desktop: X server, a minimal XFCE (window manager, desktop, panel; no session +# manager), VNC, the noVNC web viewer and the browser. set -u -mkdir -p /home/bot/.fluxbox /home/bot/Desktop && cp -n /etc/anybot/fluxbox-init /home/bot/.fluxbox/init 2>/dev/null -cp -n /etc/anybot/overlay /home/bot/.fluxbox/overlay 2>/dev/null +mkdir -p /home/bot/Desktop /home/bot/Downloads +# 下載 in the sidebar of 檔案管理員 and of every file window (a web page's 上傳檔案): what the bots +# download is there (/home/bot/Downloads). +BM=/home/bot/.config/gtk-3.0/bookmarks +mkdir -p "${BM%/*}" +grep -q '^file:///home/bot/Downloads' "$BM" 2>/dev/null || printf 'file:///home/bot/Downloads 下載\n' >> "$BM" cp -n /etc/anybot/Xresources /home/bot/.Xresources 2>/dev/null -cp /etc/anybot/menu /home/bot/.fluxbox/menu 2>/dev/null +# XFCE's settings come from the image on every boot (after LazyBoy2's box), so the desktop +# always looks the way the image says; the files and the browser's logins are what last. +XML=/home/bot/.config/xfce4/xfconf/xfce-perchannel-xml +mkdir -p "$XML" /home/bot/.config/xfce4/panel +for f in xfce4-panel.xml xfwm4.xml xfce4-desktop.xml; do cp -f "/usr/share/anybot/xfce-skel/$f" "$XML/$f"; done +cp -f /etc/xdg/xfce4/helpers.rc /home/bot/.config/xfce4/helpers.rc # GTK's dialogs (a web page's 上傳檔案 in Chromium, e.g. Threads' 加入相片) with 取消 and 開啟 in a # bar at the top, as on GNOME. Without GNOME's settings service GTK put them at the bottom of a # file window taller than the screen, under the taskbar: a picture could be found but never sent. +# (/etc/gtk-3.0/settings.ini says so too; a home from an older box has its own file.) GTKINI=/home/bot/.config/gtk-3.0/settings.ini mkdir -p "${GTKINI%/*}" grep -q '^\[Settings\]' "$GTKINI" 2>/dev/null || printf '[Settings]\n' >> "$GTKINI" grep -q '^gtk-dialogs-use-header' "$GTKINI" || sed -i '/^\[Settings\]/a gtk-dialogs-use-header=true' "$GTKINI" -chown -R bot:bot /home/bot rm -f /tmp/.X1-lock /tmp/.X11-unix/X1 # One TigerVNC server is the screen and the VNC server (was Xvfb + x11vnc, which polls the # screen for changes). VNC only on 127.0.0.1 inside the box, with the box's VNC password when the # app gave one (VNC_PASSWORD), as before. GEOM="${SCREEN_SIZE%x*}" +SW="${GEOM%x*}"; SH="${GEOM#*x}" +# The panel along the bottom, the screen's whole width. +sed -i "s/p=8;x=[0-9]*;y=[0-9]*/p=8;x=$((SW / 2));y=$((SH - 18))/" "$XML/xfce4-panel.xml" if [ -n "${VNC_PASSWORD:-}" ]; then mkdir -p /home/bot/.vnc printf '%s\n' "$VNC_PASSWORD" | vncpasswd -f > /home/bot/.vnc/passwd && chmod 600 /home/bot/.vnc/passwd # (The bot user opens the bots' own screens with the same password: anybot-screen.) - chown bot:bot /home/bot/.vnc /home/bot/.vnc/passwd VNC_SEC="-SecurityTypes VncAuth -rfbauth /home/bot/.vnc/passwd" else VNC_SEC="-SecurityTypes None" @@ -32,6 +44,11 @@ Xtigervnc :1 -geometry "$GEOM" -depth 24 -rfbport 5900 -localhost $VNC_SEC -Alwa >/tmp/xvnc.log 2>&1 & XVFB_PID=$! for i in $(seq 1 50); do xdpyinfo -display :1 >/dev/null 2>&1 && break; sleep 0.1; done +xsetroot -display :1 -solid '#2f343f' +# The wallpaper is kept under the screen's output name (TigerVNC's VNC-0). +OUT=$(xrandr --display :1 --query 2>/dev/null | awk '/ connected/ {print $1; exit}') +sed -i "s/@OUTPUT@/${OUT:-VNC-0}/" "$XML/xfce4-desktop.xml" +chown -R bot:bot /home/bot # The session bus and the accessibility registry; tools started later over `docker exec` # (anybot-a11y, anybot-browser) join this bus through /tmp/anybot-dbus.env. su bot -c 'cd /home/bot && dbus-launch --sh-syntax > /tmp/anybot-dbus.sh' && . /tmp/anybot-dbus.sh @@ -39,23 +56,31 @@ printf 'DBUS_SESSION_BUS_ADDRESS=%s\n' "$DBUS_SESSION_BUS_ADDRESS" > /tmp/anybot chown bot:bot /tmp/anybot-dbus.env /tmp/anybot-dbus.sh 2>/dev/null || true chmod 600 /tmp/anybot-dbus.env /tmp/anybot-dbus.sh export DBUS_SESSION_BUS_ADDRESS +AS_BOT="cd /home/bot && DISPLAY=:1 DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" for c in /usr/libexec/at-spi-bus-launcher /usr/lib/at-spi2-core/at-spi-bus-launcher; do - [ -x "$c" ] && { su bot -c "DISPLAY=:1 DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS $c --launch-immediately >/tmp/atspi-bus.log 2>&1 &"; break; } + [ -x "$c" ] && { su bot -c "$AS_BOT $c --launch-immediately >/tmp/atspi-bus.log 2>&1 &"; break; } done for c in /usr/libexec/at-spi2-registryd /usr/lib/at-spi2-core/at-spi2-registryd; do - [ -x "$c" ] && { su bot -c "DISPLAY=:1 DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS $c >/tmp/atspi-registry.log 2>&1 &"; break; } + [ -x "$c" ] && { su bot -c "$AS_BOT $c >/tmp/atspi-registry.log 2>&1 &"; break; } done -su bot -c "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS gsettings set org.gnome.desktop.interface toolkit-accessibility true" 2>/dev/null || true -# The file window opens smaller than the screen, whatever size it was left at. -SW="${GEOM%x*}"; SH="${GEOM#*x}" -su bot -c "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS gsettings set org.gtk.Settings.FileChooser window-size '($((SW * 7 / 10)), $((SH * 3 / 4)))'" 2>/dev/null || true -su bot -c "DISPLAY=:1 DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS xrdb -nocpp -merge /home/bot/.Xresources" -su bot -c "DISPLAY=:1 DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS fluxbox >/tmp/fluxbox.log 2>&1 &" +su bot -c "$AS_BOT gsettings set org.gnome.desktop.interface toolkit-accessibility true" 2>/dev/null || true +# The file window opens smaller than the screen, whatever size it was left at. (GTK takes the +# saved size only with a saved place too; without one it sized the window from the font, and with +# 粉圓 12 that was 1342×1029: 開啟 off the right edge of the screen.) +su bot -c "$AS_BOT gsettings set org.gtk.Settings.FileChooser window-size '($((SW * 7 / 10)), $((SH * 3 / 4)))'" 2>/dev/null || true +su bot -c "$AS_BOT gsettings set org.gtk.Settings.FileChooser window-position '($((SW * 15 / 100)), $((SH / 8)))'" 2>/dev/null || true +su bot -c "$AS_BOT xrdb -nocpp -merge /home/bot/.Xresources" +# The desktop: the window manager first, then the wallpaper and the panel (their settings come +# from xfconfd, which the session bus starts on the first ask). +su bot -c "$AS_BOT xfwm4 --compositor=off --sm-client-disable >/tmp/xfwm4.log 2>&1 &" +sleep 0.3 +su bot -c "$AS_BOT xfdesktop --disable-wm-check --sm-client-disable >/tmp/xfdesktop.log 2>&1 &" +# The panel comes back when it is closed: its 面板 › 登出 › 結束 quits only the panel, and nothing +# brought it back until the next boot. (Its own restart re-runs it in place.) +su bot -c "$AS_BOT sh -c 'while xdpyinfo >/dev/null 2>&1; do xfce4-panel --disable-wm-check --sm-client-disable; sleep 1; done' >/tmp/xfce4-panel.log 2>&1 &" # Copy and paste between the person's computer and this one: Xvnc hands the viewer's clipboard to # the X selections (and back) only while vncconfig runs (after LazyBoy2's box). su bot -c "DISPLAY=:1 vncconfig -nowin >/tmp/vncconfig.log 2>&1 &" -(sleep 1.5; xsetroot -display :1 -solid '#2b2f36') & -xsetroot -display :1 -solid '#2b2f36' # One web viewer for every screen: the shared one is "main"; anybot-screen adds each bot's own # (每個 Bot 一個螢幕). A viewer picks one with ?path=websockify%3Ftoken%3D. rm -rf /tmp/anybot-screens; mkdir -p /tmp/anybot-screens && chmod 1777 /tmp/anybot-screens @@ -64,6 +89,13 @@ echo "main: localhost:5900" > /tmp/anybot-vnc-tokens && chown bot:bot /tmp/anybo # only watching a still screen.) websockify --heartbeat=30 --web /usr/share/novnc --token-plugin TokenFile --token-source /tmp/anybot-vnc-tokens 6080 >/tmp/novnc.log 2>&1 & WEBSOCKIFY_PID=$! +# The browser is open on the shared screen from the start, as on LazyBoy2's box: a profile's very +# first boot shows what this computer is for, later ones an empty page. +if [ -d /home/bot/.config/anybot-profile/Default ]; then + su bot -c "$AS_BOT anybot-browser >/dev/null 2>&1 &" +else + su bot -c "$AS_BOT anybot-browser file:///usr/share/anybot/welcome.html >/dev/null 2>&1 &" +fi # Say ready only once the viewer's port listens: the app opens noVNC on this flag, and a too # early file meant the first viewer load 404'd. ( @@ -73,9 +105,28 @@ WEBSOCKIFY_PID=$! done echo "anybot-box ready" > /tmp/anybot-box.ready ) & +# `docker stop`: the browsers close the normal way first, so a login made a moment ago is on +# disk (killed outright, Chromium can lose its last cookies). Only the main processes, not their +# renderers. +stop_browsers() { + local pids="" p + for p in $(pgrep -u bot -x chromium); do + tr '\0' '\n' < "/proc/$p/cmdline" 2>/dev/null | grep -q '^--type=' || pids="$pids $p" + done + [ -n "$pids" ] || return 0 + kill -TERM $pids 2>/dev/null + for _ in $(seq 1 50); do + local alive=0 + for p in $pids; do kill -0 "$p" 2>/dev/null && alive=1; done + [ "$alive" = 0 ] && break + sleep 0.1 + done +} +trap 'stop_browsers; kill $WEBSOCKIFY_PID $XVFB_PID 2>/dev/null; exit 0' TERM INT # When the desktop's heart stops, the container ends too (it used to sit there as Running # with a dead X server, and every screen action failed forever). wait $XVFB_PID kill $WEBSOCKIFY_PID 2>/dev/null -pkill -u bot fluxbox 2>/dev/null +pkill -u bot xfce4-panel 2>/dev/null +pkill -u bot xfwm4 2>/dev/null exit 1 diff --git a/box/terminal b/box/terminal new file mode 100644 index 0000000..73ba0dc --- /dev/null +++ b/box/terminal @@ -0,0 +1,15 @@ +#!/bin/bash +# The box's terminal (after LazyBoy2's box-terminal): xfce4-terminal, one process per window +# (--disable-server), on the desktop's session bus. 工作列和選單的「終端機」, and what the bots +# open as 終端機 (computer_use_open_app). +export DISPLAY="${DISPLAY:-:1}" HOME=/home/bot +export TERM="${TERM:-xterm-256color}" COLORTERM="${COLORTERM:-truecolor}" +if [[ -z "${DBUS_SESSION_BUS_ADDRESS:-}" && -r /tmp/anybot-dbus.env ]]; then + # shellcheck disable=SC1091 + source /tmp/anybot-dbus.env + export DBUS_SESSION_BUS_ADDRESS +fi +# From the panel or `docker exec` (at /): the home folder. From 檔案管理員's 「在此開啟終端機」: +# the folder that was open there. +[[ "$PWD" = / || ! -d "$PWD" ]] && { cd /home/bot 2>/dev/null || cd /; } +exec xfce4-terminal --disable-server --geometry=100x28+40+40 --title=終端機 --working-directory="$PWD" "$@" diff --git a/box/welcome.html b/box/welcome.html new file mode 100644 index 0000000..2cec29e --- /dev/null +++ b/box/welcome.html @@ -0,0 +1,17 @@ + + + + + Bot 的電腦 + + + +

這是 Bot 的電腦

+

登入、驗證碼、付款請在這個畫面完成。帳密只在這裡輸入,對話裡看不到。

+

下方工作列有「應用程式」「瀏覽器」「檔案管理員」和「終端機」;Bot 下載的檔案在檔案管理員的「下載」。做完後回到聊天跟 Bot 說「好了」。

+ + diff --git a/box/xfce/browser.desktop b/box/xfce/browser.desktop new file mode 100644 index 0000000..42feb48 --- /dev/null +++ b/box/xfce/browser.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=瀏覽器 +Name[zh_TW]=瀏覽器 +Comment=Bot 的電腦上的 Chromium(跟 Bot 用的是同一個) +Exec=/usr/local/bin/anybot-browser %U +Icon=web-browser +Terminal=false +Categories=Network;WebBrowser;GTK; +MimeType=text/html;application/xhtml+xml;application/pdf;x-scheme-handler/http;x-scheme-handler/https; +StartupNotify=true diff --git a/box/xfce/helper-browser.desktop b/box/xfce/helper-browser.desktop new file mode 100644 index 0000000..da70fdf --- /dev/null +++ b/box/xfce/helper-browser.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Version=1.0 +Type=X-XFCE-Helper +Icon=web-browser +Name=瀏覽器 +Name[zh_TW]=瀏覽器 +StartupNotify=true +X-XFCE-Binaries=anybot-browser;chromium; +X-XFCE-Category=WebBrowser +X-XFCE-Commands=/usr/local/bin/anybot-browser; +X-XFCE-CommandsWithParameter=/usr/local/bin/anybot-browser "%s"; diff --git a/box/xfce/helper-terminal.desktop b/box/xfce/helper-terminal.desktop new file mode 100644 index 0000000..731c22d --- /dev/null +++ b/box/xfce/helper-terminal.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Version=1.0 +Type=X-XFCE-Helper +Icon=utilities-terminal +Name=終端機 +Name[zh_TW]=終端機 +StartupNotify=true +X-XFCE-Binaries=anybot-terminal;xfce4-terminal; +X-XFCE-Category=TerminalEmulator +X-XFCE-Commands=/usr/local/bin/anybot-terminal; +X-XFCE-CommandsWithParameter=/usr/local/bin/anybot-terminal -e %s; diff --git a/box/xfce/helpers.rc b/box/xfce/helpers.rc new file mode 100644 index 0000000..bc902ed --- /dev/null +++ b/box/xfce/helpers.rc @@ -0,0 +1,3 @@ +WebBrowser=anybot-browser +TerminalEmulator=anybot-terminal +FileManager=thunar diff --git a/box/xfce/menu.xml b/box/xfce/menu.xml new file mode 100644 index 0000000..d41bd8a --- /dev/null +++ b/box/xfce/menu.xml @@ -0,0 +1,49 @@ + + + + Xfce + + + + anybot-browser.desktop + anybot-terminal.desktop + thunar.desktop + org.xfce.mousepad.desktop + org.xfce.ristretto.desktop + + + anybot-browser.desktop + thunar.desktop + anybot-terminal.desktop + org.xfce.mousepad.desktop + org.xfce.ristretto.desktop + + + + + Other + xfce-other.directory + + + + + + anybot-browser.desktop + anybot-terminal.desktop + thunar.desktop + org.xfce.mousepad.desktop + org.xfce.ristretto.desktop + thunar-bulk-rename.desktop + display-im6.q16.desktop + vim.desktop + Settings + X-XFCE-SettingsDialog + X-Xfce-Toplevel + + + + diff --git a/box/xfce/mimeapps.list b/box/xfce/mimeapps.list new file mode 100644 index 0000000..f660ddb --- /dev/null +++ b/box/xfce/mimeapps.list @@ -0,0 +1,22 @@ +[Default Applications] +inode/directory=thunar.desktop +text/plain=org.xfce.mousepad.desktop +text/markdown=org.xfce.mousepad.desktop +text/csv=org.xfce.mousepad.desktop +text/x-python=org.xfce.mousepad.desktop +text/x-shellscript=org.xfce.mousepad.desktop +application/x-shellscript=org.xfce.mousepad.desktop +application/json=org.xfce.mousepad.desktop +application/xml=org.xfce.mousepad.desktop +text/xml=org.xfce.mousepad.desktop +image/png=org.xfce.ristretto.desktop +image/jpeg=org.xfce.ristretto.desktop +image/gif=org.xfce.ristretto.desktop +image/webp=org.xfce.ristretto.desktop +image/bmp=org.xfce.ristretto.desktop +image/svg+xml=org.xfce.ristretto.desktop +application/pdf=anybot-browser.desktop +text/html=anybot-browser.desktop +application/xhtml+xml=anybot-browser.desktop +x-scheme-handler/http=anybot-browser.desktop +x-scheme-handler/https=anybot-browser.desktop diff --git a/box/xfce/terminal.desktop b/box/xfce/terminal.desktop new file mode 100644 index 0000000..e0fa3bd --- /dev/null +++ b/box/xfce/terminal.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=終端機 +Name[zh_TW]=終端機 +Comment=Bot 的電腦上的終端機 +Exec=/usr/local/bin/anybot-terminal +Icon=utilities-terminal +Terminal=false +Categories=System;TerminalEmulator;GTK; +StartupNotify=true diff --git a/box/xfce/wallpaper.svg b/box/xfce/wallpaper.svg new file mode 100644 index 0000000..687bed4 --- /dev/null +++ b/box/xfce/wallpaper.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/box/xfce/xfce4-desktop.xml b/box/xfce/xfce4-desktop.xml new file mode 100644 index 0000000..62ced3a --- /dev/null +++ b/box/xfce/xfce4-desktop.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/box/xfce/xfce4-panel-lock.xml b/box/xfce/xfce4-panel-lock.xml new file mode 100644 index 0000000..83ca6c1 --- /dev/null +++ b/box/xfce/xfce4-panel-lock.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/box/xfce/xfce4-panel.xml b/box/xfce/xfce4-panel.xml new file mode 100644 index 0000000..f597270 --- /dev/null +++ b/box/xfce/xfce4-panel.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/box/xfce/xfwm4.xml b/box/xfce/xfwm4.xml new file mode 100644 index 0000000..5603ff5 --- /dev/null +++ b/box/xfce/xfwm4.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/feature-map/computers.md b/docs/feature-map/computers.md index e026a5e..d0021d9 100644 --- a/docs/feature-map/computers.md +++ b/docs/feature-map/computers.md @@ -5,7 +5,7 @@ ## 子功能 - 四種電腦,每台都用自己的名字稱呼: - - Bot 自己的電腦(「 的電腦」):一台 Linux(Debian,有桌面和 Chromium,可以 sudo 裝套件),跑在 Docker 裡,所有 Bot 共用一台,各有自己的資料夾、自己的螢幕和自己的瀏覽器(見 [screen](screen.md)),一直開著。沒有 Docker 時退回成一個封閉的資料夾,沒有桌面。 + - Bot 自己的電腦(「 的電腦」):一台 Linux(Debian 加 XFCE 桌面、Chromium,繁體中文、台北時間,可以 sudo 裝套件),跑在 Docker 裡,所有 Bot 共用一台,各有自己的資料夾、自己的螢幕和自己的瀏覽器(見 [screen](screen.md)),一直開著。沒有 Docker 時退回成一個封閉的資料夾,沒有桌面。 - 這台電腦(AnyBot 開著的這台,名字可以改):從 Bot 的「起始資料夾」開始。大腦放在伺服器上時,伺服器本身不在清單裡。 - SSH 電腦:自己加的,一個名稱加一個位址(例如 me@studio.local)。 - 帳號裡的其他電腦:登入同一個帳號、打開「讓帳號裡的其他電腦使用這台」、而且現在在線上的 AnyBot(螢幕電腦、手腳電腦),經過帳號伺服器操作檔案、指令、瀏覽器、看畫面和點擊。 @@ -20,19 +20,21 @@ - Bot 設定 ›「電腦操作」:「讓這個 Bot 查看、修改檔案和執行指令」,勾了才出現下面幾項:「做事的電腦」(旁邊寫「聊天時指名別台就會換」);「可以用的電腦」(有兩台以上才出現);「起始資料夾」。 - 設定 ›「電腦」:「你的電腦」一段(鉛筆改這台的名字、「在這台電腦上執行」、「其他電腦」展開看帳號裡的電腦和 SSH 電腦,填「SSH 電腦名稱,例如 工作站」和位址按「新增」,或「移除」,還有「讓帳號裡的其他電腦使用這台」);「Bot 的電腦」一段(狀態、「開啟電腦」看畫面和接手、快照、更新、重設、環境密鑰、Docker 主機;在大腦的螢幕上只有「在大腦上」,要到大腦那台管理)。 - 設定 › 一般 ›「手機與帳號」:「大腦」那一欄選哪台當大腦(「改用它當大腦」),「加一台電腦」按「產生配對碼」。 +- Bot 的電腦的畫面(「開啟電腦」):下方工作列由左到右是「應用程式」選單、「瀏覽器」、「檔案管理員」、「終端機」、開著的視窗、時鐘;桌面按右鍵也有應用程式選單(瀏覽器、檔案管理員、終端機、文字編輯器、影像檢視器,Bot 裝的程式在「其他」)。瀏覽器開機就開好(第一次是說明頁),跟 Bot 的瀏覽器工具是同一個、登入共用。檔案管理員側邊欄的「下載」是 Bot 下載的檔案;檔案按兩下會用對的程式開。 - 側邊欄底部名字右邊的「↑」(「傳送檔案或文字到其他裝置」)。手機:左上頭像選單 ›「傳送到其他裝置」;首頁上面一排的「電腦」。 ## 怎麼操作 - Bot:`list_computers` 看自己能用哪幾台、每台是什麼、哪台是使用者選的、選的那台有沒有連線。檔案、指令、螢幕、瀏覽器工具都有 `computer` 參數,填電腦的名字;不填就是使用者選的那台。使用者說「我的電腦」「這台」指的是他正在用的那台,不確定就先問。使用者要把檔案放到另一台裝置時才用 `send_to_device`(path、to 填裝置名稱或「手機」、computer 是檔案現在在的那台);把結果交給使用者用 `send_file`([files](files.md))。 -- 驗證:在 Bot 設定 › 電腦操作 換「做事的電腦」,問 Bot「你可以用哪些電腦」,它用 `list_computers` 回答,要有「使用者選的電腦:「…」」這一行。設定 › 電腦 把「在這台電腦上執行」設成每次詢問,請它在這台電腦跑 `pwd`,要跳出允許卡片;改成永不允許再試,要被擋下並請它改用自己的電腦。自動測試:`cargo test tools::`、`cargo test agent::`、`cargo test app::`、`cargo test remote::`、`cargo test drops::`、`cargo test cloudbox::`(要 Docker 的標 ignored)。 +- 驗證:在 Bot 設定 › 電腦操作 換「做事的電腦」,問 Bot「你可以用哪些電腦」,它用 `list_computers` 回答,要有「使用者選的電腦:「…」」這一行。設定 › 電腦 把「在這台電腦上執行」設成每次詢問,請它在這台電腦跑 `pwd`,要跳出允許卡片;改成永不允許再試,要被擋下並請它改用自己的電腦。開 Bot 的電腦的畫面,下方要有工作列(應用程式、瀏覽器、檔案管理員、終端機、時鐘),選單是中文、只有一層;工作列按右鍵沒有「移除」;檔案管理員側邊欄有「下載」;網頁上傳檔案的視窗整個在螢幕裡(看得到「開啟」)。請 Bot 打開終端機,要開出跟工作列「終端機」同一種視窗;請它打開檔案總管,要開出檔案管理員、在 bot 家目錄。自動測試:`cargo test tools::`、`cargo test agent::`、`cargo test app::`、`cargo test remote::`、`cargo test drops::`、`cargo test cloudbox::`(要 Docker 的標 ignored)。 ## 陷阱 - Bot 不能自己換電腦:工具指定了別台,但使用者最近三則訊息沒提到那台,這一步會被移回使用者選的那台,結果裡會說。真的要別台先問使用者。 - 使用者選的那台沒開機、或那台的 AnyBot 沒開沒登入,就不在清單上:Bot 先待在自己的電腦,`list_computers` 會寫那台「現在沒有連線」。 - 在 Bot 自己的電腦上做事不用問,但它看不到使用者的檔案;檔案工具只碰得到自己的資料夾(大家共用同一台)。 -- Bot 的電腦是精簡的 Linux 桌面(Debian + fluxbox):檔案視窗的「取消」「Open」在視窗最上面(第 11 版以前在最下面、被螢幕切掉,網頁上傳圖片選得到檔案卻送不出去——設定 › 電腦「更新 Bot 的電腦」換新版)。看畫面時可以跟自己的電腦互相複製貼上。 +- Bot 的電腦的桌面是第 12 版起換的(照 LazyBoy2 的 box:XFCE 工作列、深色主題、粉圓字型、繁中、台北時間);第 11 版以前是 fluxbox,只有右鍵選單和一條細工作列,設定 › 電腦「更新 Bot 的電腦」換新版。桌面設定每次開機照映像檔重放,在桌面上改的外觀、工作列不會留下;留下的是檔案和瀏覽器的登入。工作列鎖住(xfconf 的鎖要寫使用者名稱 bot,寫「*」不算數);它的「面板 › 登出 › 結束」只關掉工作列,一秒後自己回來。網頁上傳檔案的視窗開機時設好大小和位置(GTK 沒有記著位置就照字型算大小,比螢幕大)。時區是 /etc/localtime(台北),沒有 TZ 變數,Bot 改了就生效。 +- 檔案視窗的「取消」「開啟」在視窗最上面(第 11 版以前在最下面、被螢幕切掉,網頁上傳圖片選得到檔案卻送不出去——設定 › 電腦「更新 Bot 的電腦」換新版)。看畫面時可以跟自己的電腦互相複製貼上。 - 從帳號看 Bot 電腦的畫面,只要開著就不會斷;之前靜止畫面一分鐘、或看超過十分鐘會被帳號伺服器切掉,要更新帳號伺服器(make update-server)。 - 「在這台電腦上執行」設成永不允許(或被管理員鎖住)時,這台的檔案也不能傳出去、打開或發佈。 - SSH 電腦上的檔案不能直接傳到聊天、打開給使用者看或發佈網站,要先複製到 Bot 自己的電腦。 diff --git a/src/cloudbox.rs b/src/cloudbox.rs index ce2e96f..fe966dd 100644 --- a/src/cloudbox.rs +++ b/src/cloudbox.rs @@ -126,15 +126,33 @@ const CLICK_REPEAT_MS: u64 = 80; const TYPE_DELAY_MS: u64 = 12; const DOCKERFILE: &str = include_str!("../box/Dockerfile"); -const START_SH: &str = include_str!("../box/start.sh"); -const FLUXBOX_INIT: &str = include_str!("../box/fluxbox-init"); -const OVERLAY: &str = include_str!("../box/overlay"); -const XRESOURCES: &str = include_str!("../box/Xresources"); -const MENU: &str = include_str!("../box/menu"); -const A11Y: &str = include_str!("../box/a11y"); -const BROWSER: &str = include_str!("../box/browser"); -/// 每個 Bot 一個螢幕: opens, lists and closes the bots' own screens. -const SCREEN_SH: &str = include_str!("../box/screen"); +/// Every file the box image is built from (build_image writes them next to the Dockerfile), by +/// its path under box/. The desktop is LazyBoy2's: XFCE with a panel, Arc-Dark, jf open 粉圓. +const BOX_FILES: &[(&str, &str)] = &[ + ("start.sh", include_str!("../box/start.sh")), + ("a11y", include_str!("../box/a11y")), + ("browser", include_str!("../box/browser")), + // 每個 Bot 一個螢幕: opens, lists and closes the bots' own screens. + ("screen", include_str!("../box/screen")), + ("terminal", include_str!("../box/terminal")), + ("Xresources", include_str!("../box/Xresources")), + ("welcome.html", include_str!("../box/welcome.html")), + ("fonts.conf", include_str!("../box/fonts.conf")), + ("gtk3-settings.ini", include_str!("../box/gtk3-settings.ini")), + ("licenses/huninn-OFL.txt", include_str!("../box/licenses/huninn-OFL.txt")), + ("xfce/wallpaper.svg", include_str!("../box/xfce/wallpaper.svg")), + ("xfce/xfce4-panel.xml", include_str!("../box/xfce/xfce4-panel.xml")), + ("xfce/xfwm4.xml", include_str!("../box/xfce/xfwm4.xml")), + ("xfce/xfce4-desktop.xml", include_str!("../box/xfce/xfce4-desktop.xml")), + ("xfce/helpers.rc", include_str!("../box/xfce/helpers.rc")), + ("xfce/mimeapps.list", include_str!("../box/xfce/mimeapps.list")), + ("xfce/menu.xml", include_str!("../box/xfce/menu.xml")), + ("xfce/xfce4-panel-lock.xml", include_str!("../box/xfce/xfce4-panel-lock.xml")), + ("xfce/helper-browser.desktop", include_str!("../box/xfce/helper-browser.desktop")), + ("xfce/helper-terminal.desktop", include_str!("../box/xfce/helper-terminal.desktop")), + ("xfce/browser.desktop", include_str!("../box/xfce/browser.desktop")), + ("xfce/terminal.desktop", include_str!("../box/xfce/terminal.desktop")), +]; // ---------- state ---------- @@ -894,8 +912,12 @@ fn build_image(pull: bool) -> Result<(), String> { let dir = std::env::temp_dir().join(format!("anybot-box-build-{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?; - for (name, body) in [("Dockerfile", DOCKERFILE), ("start.sh", START_SH), ("fluxbox-init", FLUXBOX_INIT), ("overlay", OVERLAY), ("Xresources", XRESOURCES), ("menu", MENU), ("a11y", A11Y), ("browser", BROWSER), ("screen", SCREEN_SH)] { - std::fs::write(dir.join(name), body).map_err(|e| e.to_string())?; + for (name, body) in std::iter::once(&("Dockerfile", DOCKERFILE)).chain(BOX_FILES) { + let path = dir.join(name); + if let Some(parent) = path.parent() { + std::fs::create_dir_all(parent).map_err(|e| e.to_string())?; + } + std::fs::write(path, body).map_err(|e| e.to_string())?; } log("正在建立電腦的映像檔(第一次要幾分鐘)…"); let mut args = vec!["build", "-q", "-t", image()]; @@ -2520,14 +2542,20 @@ pub fn step_stats() -> (usize, u64, u64) { static STEP_TIMES: Mutex> = Mutex::new(Vec::new()); -/// Programs people name, as the box knows them. -fn box_program(app: &str) -> Option<&'static str> { +/// Programs people name, as the box knows them: (what starts it, its windows' class name). +fn box_program(app: &str) -> Option<(&'static str, &'static str)> { let a = app.trim().to_lowercase(); if ["chrome", "chromium", "google chrome", "browser", "瀏覽器", "網頁瀏覽器"].iter().any(|n| a == *n) { - return Some("chromium"); + return Some(("chromium", "chromium")); } - if ["terminal", "終端機", "xterm", "shell", "命令列"].iter().any(|n| a == *n) { - return Some("xterm"); + // The panel's 終端機 (xfce4-terminal through anybot-terminal: the desktop's bus, one process + // a window). xterm by its own name is still there. + if ["terminal", "終端機", "xfce4-terminal", "shell", "命令列"].iter().any(|n| a == *n) { + return Some(("anybot-terminal", "xfce4-terminal")); + } + // The panel's 檔案管理員 (Thunar), by the names people use for it. + if ["檔案總管", "檔案管理員", "檔案管理器", "檔案", "files", "file manager", "finder", "explorer", "thunar"].iter().any(|n| a == *n) { + return Some(("thunar", "thunar")); } None } @@ -2539,24 +2567,28 @@ fn open_on_box(app: &str) -> Result { if name.is_empty() { return Err("請給要打開的程式名稱".into()); } - let prog = match box_program(name) { - Some(p) => p.to_string(), - None if name.chars().all(|c| c.is_ascii_alphanumeric() || "._-".contains(c)) => name.to_lowercase(), - None => return Err(format!("這台是 Linux 桌面,沒有「{name}」。可以打開的例如 chromium(瀏覽器)、xterm(終端機),或用指令工具安裝。")), + let (prog, class) = match box_program(name) { + Some((p, c)) => (p.to_string(), c.to_string()), + None if name.chars().all(|c| c.is_ascii_alphanumeric() || "._-".contains(c)) => (name.to_lowercase(), name.to_lowercase()), + None => return Err(format!("這台是 Linux 桌面,沒有「{name}」。可以打開的例如 chromium(瀏覽器)、終端機、檔案管理員,或用指令工具安裝。")), }; if prog == "chromium" { browser_port()?; } let q = crate::tools::sh_quote(&prog); - // Front if it has a window; else start it and wait (up to 8 s) for one. + let c = crate::tools::sh_quote(&class); + // What the bot asked for, as it named it (終端機, not anybot-terminal; 檔案管理員, not thunar). + let shown = if box_program(name).is_some() { name.to_string() } else { prog.clone() }; + // Front if it has a window; else start it and wait (up to 8 s) for one. (Started in the home + // folder: 檔案管理員 opened at /, the folder `docker exec` runs in.) let script = format!( - "w=$(xdotool search --onlyvisible --classname {q} 2>/dev/null | tail -1); \ - if [ -z \"$w\" ]; then command -v {q} >/dev/null || {{ echo \"沒有 {prog} 這個程式\" >&2; exit 3; }}; (setsid {q} >/dev/null 2>&1 &); \ - for i in $(seq 1 40); do sleep 0.2; w=$(xdotool search --onlyvisible --classname {q} 2>/dev/null | tail -1); [ -n \"$w\" ] && break; done; fi; \ + "w=$(xdotool search --onlyvisible --classname {c} 2>/dev/null | tail -1); \ + if [ -z \"$w\" ]; then command -v {q} >/dev/null || {{ echo \"沒有 {prog} 這個程式\" >&2; exit 3; }}; (cd /home/bot 2>/dev/null; setsid {q} >/dev/null 2>&1 &); \ + for i in $(seq 1 40); do sleep 0.2; w=$(xdotool search --onlyvisible --classname {c} 2>/dev/null | tail -1); [ -n \"$w\" ] && break; done; fi; \ if [ -n \"$w\" ]; then xdotool windowactivate $w 2>/dev/null; echo shown; fi; true" ); let out = box_exec(&script)?; - Ok(if out.contains("shown") { format!("已打開「{prog}」,放在最前面。") } else { format!("已啟動「{prog}」,但 8 秒內還沒有出現視窗(可能還在開,看下面的畫面)。") }) + Ok(if out.contains("shown") { format!("已打開「{shown}」,放在最前面。") } else { format!("已啟動「{shown}」,但 8 秒內還沒有出現視窗(可能還在開,看下面的畫面)。") }) } /// Run a computer_use tool on the box. Returns (text, screenshot as base64 JPEG). @@ -3144,6 +3176,12 @@ mod tests { println!("typed: {out}"); assert_eq!(out.trim(), "a-b 中文 /"); let _ = box_exec("xdotool key --clearmodifiers ctrl+d"); + // 檔案管理員 (the panel's) opens in the home folder, not at / where `docker exec` runs. + let (txt, _) = computer_run("computer_use_open_app", &serde_json::json!({"app": "檔案管理員"})).unwrap(); + assert!(txt.contains("已打開「檔案管理員」"), "{txt}"); + let title = box_exec("xdotool getactivewindow getwindowname").unwrap_or_default(); + assert!(title.trim().starts_with("bot - "), "{title}"); + let _ = box_exec("pkill -x thunar"); } /// Uses the real Docker: `cargo test --release -- --ignored box_batch_in_one_round_trip --nocapture`. @@ -3388,7 +3426,7 @@ mod tests { println!("{l}"); } assert!(run_state().is_running(), "{:?}", run_state()); - let (out, ok) = run_on("shell", r#"{"command":"cat kept.txt; ls /usr/games/cowsay 2>&1 || echo no-cowsay; cat /etc/anybot/menu | head -1"}"#, &t, &cancel, &ids); + let (out, ok) = run_on("shell", r#"{"command":"cat kept.txt; ls /usr/games/cowsay 2>&1 || echo no-cowsay; grep -o 'Bot 的電腦' /usr/share/anybot/welcome.html | head -1"}"#, &t, &cancel, &ids); println!("{out}"); assert!(ok && out.contains("keep-me") && out.contains("no-cowsay") && out.contains("Bot 的電腦")); let _ = run_on("shell", r#"{"command":"cd .. && rm -rf bot-998"}"#, &t, &cancel, &ids); @@ -3423,13 +3461,22 @@ mod tests { use chrono::TimeZone; let at = chrono::Utc.with_ymd_and_hms(2026, 11, 6, 19, 0, 0).unwrap().with_timezone(&chrono_tz::Asia::Taipei); assert!(in_schedule_window("03:00", at.time())); - assert_eq!(wanted_version(), "11"); - // Every file the Dockerfile copies is one this app carries (build_image writes them). - let carried = ["start.sh", "fluxbox-init", "overlay", "Xresources", "menu", "a11y", "browser", "screen"]; - for l in DOCKERFILE.lines().filter_map(|l| l.trim().strip_prefix("COPY ")) { - let src = l.split_whitespace().next().unwrap(); - assert!(carried.contains(&src), "the Dockerfile copies {src}, which build_image doesn't write"); + assert_eq!(wanted_version(), "12"); + // Every file the Dockerfile copies is one this app carries (build_image writes them), and + // every file carried is copied. + let copied: Vec<&str> = DOCKERFILE.lines().filter_map(|l| l.trim().strip_prefix("COPY ")).map(|l| l.split_whitespace().next().unwrap()).collect(); + for src in &copied { + assert!(BOX_FILES.iter().any(|(n, _)| n == src), "the Dockerfile copies {src}, which build_image doesn't write"); } + for (n, _) in BOX_FILES { + assert!(copied.contains(n), "build_image writes {n}, which the Dockerfile never copies"); + } + // 終端機 is the panel's terminal; the browser is AnyBot's. + assert_eq!(box_program("終端機"), Some(("anybot-terminal", "xfce4-terminal"))); + assert_eq!(box_program("Chrome"), Some(("chromium", "chromium"))); + assert_eq!(box_program("xterm"), None); + assert_eq!(box_program("檔案總管"), Some(("thunar", "thunar"))); + assert_eq!(box_program("Files"), Some(("thunar", "thunar"))); // 每個 Bot 一個螢幕: a bot's folder names its screen; any other folder is the shared one. assert_eq!(screen_of_dir("/home/bot/bot-12"), "bot12"); assert_eq!(screen_of_dir("/home/bot/bot-12/"), "bot12"); diff --git a/src/facts.rs b/src/facts.rs index a16289d..2396308 100644 --- a/src/facts.rs +++ b/src/facts.rs @@ -32,7 +32,7 @@ if command -v curl >/dev/null 2>&1; then curl -s -m 4 -o /dev/null https://www.g for p in apt-get dnf yum pacman apk zypper xbps-install brew winget; do command -v $p >/dev/null 2>&1 && k pkg $p; done k desktop "${XDG_CURRENT_DESKTOP:-}" [ -n "${TZ:-}" ] && k tz "$TZ" -for w in fluxbox gnome-shell plasmashell xfce4-session mate-session cinnamon sway Hyprland; do pgrep -x $w >/dev/null 2>&1 && k wm $w; done +for w in fluxbox xfwm4 gnome-shell plasmashell xfce4-session mate-session cinnamon sway Hyprland; do pgrep -x $w >/dev/null 2>&1 && k wm $w; done t=""; for x in python3 node npm git docker curl wget jq ffmpeg xdotool wmctrl osascript shortcuts brew; do command -v $x >/dev/null 2>&1 && t="$t $x"; done; k tools "$t" if [ -d /usr/share/applications ]; then k apps "$(for f in /usr/share/applications/*.desktop; do sed -n 's/^Name=//p' "$f" | head -1; done 2>/dev/null | sort -u | head -60 | tr '\n' '|')"; fi if [ -d /Applications ]; then k apps "$(ls /Applications 2>/dev/null | sed -n 's/\.app$//p' | head -80 | tr '\n' '|')"; fi