合併: Bot 的電腦換成 XFCE 桌面,有檔案管理員、文字編輯器、影像檢視器

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uirha54sGCEGh2rRbTsSeh
This commit is contained in:
王性驊 2026-11-16 10:55:05 +08:00
commit 2610467f13
30 changed files with 757 additions and 92 deletions

View File

@ -852,6 +852,7 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。
- **健康檢查**:每 20 秒看一次,單次最多等 3 秒(原版 /health 的逾時)。 - **健康檢查**:每 20 秒看一次,單次最多等 3 秒(原版 /health 的逾時)。
- **Bot 在上面的權限**:這是它自己的電腦,所以指令、改檔案、操作螢幕都不用問你;只有「一律不允許」的指令(例如格式化)還是會擋。可以 `sudo` 安裝套件。 - **Bot 在上面的權限**:這是它自己的電腦,所以指令、改檔案、操作螢幕都不用問你;只有「一律不允許」的指令(例如格式化)還是會擋。可以 `sudo` 安裝套件。
- **開機時間**:最多等 60 秒(估計值)。 - **開機時間**:最多等 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。另外兩個: computer_use_screenshot、click、mouse_move、mouse_button(按住/放開)、drag、scroll、typing、press_key、check_permissions。另外兩個:
- **(已併入截圖)「讀 App 畫面」**:按鈕清單現在就在每張截圖裡,不再是另一個工具。很長的內容(終端機的整段捲動紀錄)留開頭 160 字和結尾 400 字。 - **(已併入截圖)「讀 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 的電腦上一律可以。 - **「檢查螢幕權限」(computer_use_check_permissions)**:回報「螢幕錄製:已允許/還沒允許」「輔助使用(滑鼠和鍵盤):…」,不會跳出系統視窗。Bot 的電腦上一律可以。

View File

@ -177,7 +177,7 @@ TASKS = [
"setup": "ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime; rm -f /etc/timezone; " "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 " "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; " "[ -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'", "su bot -c 'date +%Z'",
"ask": "把你電腦的時區設成日本東京時間,設好後告訴我現在那台電腦顯示的時間。", "ask": "把你電腦的時區設成日本東京時間,設好後告訴我現在那台電腦顯示的時間。",
"check": lambda dh, ans: "Tokyo" in dx("readlink -f /etc/localtime; cat /etc/timezone 2>/dev/null", dh)[1]}, "check": lambda dh, ans: "Tokyo" in dx("readlink -f /etc/localtime; cat /etc/timezone 2>/dev/null", dh)[1]},

View File

@ -2,28 +2,93 @@
# (an X11 desktop driven by xdotool, watched through noVNC on port 6080). One TigerVNC server is # (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 # 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). # 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 FROM debian:bookworm-slim
# No TZ here: a TZ variable overrides /etc/localtime for every program, so setting the timezone # 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 ENV DEBIAN_FRONTEND=noninteractive LANG=C.UTF-8
RUN apt-get update && apt-get install -y --no-install-recommends \ # dpkg never unpacks docs, man pages or other languages' messages (zh_TW is kept: the XFCE menus
tigervnc-standalone-server tigervnc-tools xdotool x11-utils x11-xserver-utils imagemagick fluxbox xterm \ # 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 \ 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 \ 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/* \ && 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 \ && 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 && 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 start.sh /usr/local/bin/anybot-box-start
COPY a11y /usr/local/bin/anybot-a11y COPY a11y /usr/local/bin/anybot-a11y
COPY browser /usr/local/bin/anybot-browser COPY browser /usr/local/bin/anybot-browser
COPY screen /usr/local/bin/anybot-screen COPY screen /usr/local/bin/anybot-screen
COPY fluxbox-init /etc/anybot/fluxbox-init COPY terminal /usr/local/bin/anybot-terminal
COPY overlay /etc/anybot/overlay
COPY Xresources /etc/anybot/Xresources COPY Xresources /etc/anybot/Xresources
COPY menu /etc/anybot/menu COPY welcome.html /usr/share/anybot/welcome.html
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 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 # 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 # 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 # 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`. # 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 # 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. # 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 EXPOSE 6080
LABEL anybot.box.version="11" LABEL anybot.box.version="12"
ENTRYPOINT ["/usr/bin/tini", "--"] ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/local/bin/anybot-box-start"] CMD ["/usr/local/bin/anybot-box-start"]

View File

@ -25,8 +25,9 @@ ACTIVE = {
# Listed when they carry words (headings, labels, cells...). # Listed when they carry words (headings, labels, cells...).
NAMED = {"heading", "label", "static", "text", "image", "table cell", "column header", "row header", "icon", NAMED = {"heading", "label", "static", "text", "image", "table cell", "column header", "row header", "icon",
"tool tip", "alert", "dialog", "paragraph"} "tool tip", "alert", "dialog", "paragraph"}
# The desktop's own parts are visible in the picture; the list is for the windows worked in. # The desktop's own parts (the panel, the wallpaper, the window manager) are visible in the
SKIP_APPS = {"fluxbox", "a11y", "python3", "xterm-wrapper"} # 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(): def stacked_windows():

View File

@ -6,6 +6,8 @@
set -euo pipefail set -euo pipefail
export DISPLAY="${DISPLAY:-:1}" HOME=/home/bot export DISPLAY="${DISPLAY:-:1}" HOME=/home/bot
export GTK_MODULES=atk-bridge GTK_A11Y=atspi GNOME_ACCESSIBILITY=1 NO_AT_BRIDGE=0 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 if [[ -z "${DBUS_SESSION_BUS_ADDRESS:-}" && -r /tmp/anybot-dbus.env ]]; then
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source /tmp/anybot-dbus.env 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 --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 --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 --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 # 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. # over the profile ("in use"): one at a time until the first is listening.
exec 9>"$LOCK" exec 9>"$LOCK"

View File

@ -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'

41
box/fonts.conf Normal file
View File

@ -0,0 +1,41 @@
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- System UI: jf open 粉圓 (same as lazyBoy). Terminal: DejaVu Sans Mono + Noto Sans Mono CJK TC. -->
<match target="pattern">
<test name="family"><string>粉圓</string></test>
<edit name="family" mode="assign" binding="same"><string>jf open 粉圓 2.1</string></edit>
</match>
<match target="pattern">
<test name="family"><string>jf open 粉圓</string></test>
<edit name="family" mode="assign" binding="same"><string>jf open 粉圓 2.1</string></edit>
</match>
<match target="pattern">
<test name="family"><string>Huninn</string></test>
<edit name="family" mode="assign" binding="same"><string>jf open 粉圓 2.1</string></edit>
</match>
<match target="pattern">
<test name="family"><string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="strong">
<string>jf open 粉圓 2.1</string>
</edit>
</match>
<match target="pattern">
<test name="lang" compare="contains"><string>zh</string></test>
<test name="family"><string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="strong">
<string>jf open 粉圓 2.1</string>
</edit>
</match>
<match target="pattern">
<test name="family"><string>monospace</string></test>
<edit name="family" mode="prepend" binding="strong">
<string>Noto Sans Mono CJK TC</string>
</edit>
<edit name="family" mode="prepend" binding="strong">
<string>DejaVu Sans Mono</string>
</edit>
</match>
</fontconfig>

7
box/gtk3-settings.ini Normal file
View File

@ -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

101
box/licenses/huninn-OFL.txt Normal file
View File

@ -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.

View File

@ -1,7 +0,0 @@
[begin] (Bot 的電腦)
[exec] (瀏覽器 Chromium) {anybot-browser}
[exec] (終端機) {xterm}
[separator]
[workspaces] (視窗)
[restart] (重新整理桌面)
[end]

View File

@ -1,2 +0,0 @@
background: none
*.font: Noto Sans CJK TC-10

View File

@ -27,13 +27,13 @@ mkdir -p "$DIR" 2>/dev/null; chmod 1777 "$DIR" 2>/dev/null
TOKENS=/tmp/anybot-vnc-tokens TOKENS=/tmp/anybot-vnc-tokens
key_ok() { [[ "$1" =~ ^[A-Za-z0-9_-]{1,48}$ ]]; } 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; } 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"; } 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; } alive() { [ -n "${1:-}" ] && kill -0 "$1" 2>/dev/null; }
# The screen's processes (Xtigervnc, its dbus, fluxbox, the accessibility bus, the browser), killed # The screen's processes (Xtigervnc, its dbus, the accessibility bus, the desktop, the browser),
# youngest first. # killed youngest first.
close() { close() {
local d=$DIR/$1 local d=$DIR/$1
[ -d "$d" ] || return 0 [ -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; } [ -x "$c" ] && { as_bot "DISPLAY=:$disp DBUS_SESSION_BUS_ADDRESS=$bus setsid $c >/dev/null 2>&1 & echo \$!" 8>&- >> "$d/pids"; break; }
done done
as_bot "DISPLAY=:$disp xrdb -nocpp -merge /home/bot/.Xresources" 2>/dev/null 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). # 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" as_bot "DISPLAY=:$disp setsid vncconfig -nowin >/dev/null 2>&1 & echo \$!" 8>&- >> "$d/pids"
xsetroot -display ":$disp" -solid '#2b2f36'
{ {
echo "DISPLAY=:$disp" echo "DISPLAY=:$disp"
echo "DBUS_SESSION_BUS_ADDRESS=$bus" echo "DBUS_SESSION_BUS_ADDRESS=$bus"

View File

@ -1,28 +1,40 @@
#!/bin/bash #!/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 set -u
mkdir -p /home/bot/.fluxbox /home/bot/Desktop && cp -n /etc/anybot/fluxbox-init /home/bot/.fluxbox/init 2>/dev/null mkdir -p /home/bot/Desktop /home/bot/Downloads
cp -n /etc/anybot/overlay /home/bot/.fluxbox/overlay 2>/dev/null # 下載 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 -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 # 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 # 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. # 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 GTKINI=/home/bot/.config/gtk-3.0/settings.ini
mkdir -p "${GTKINI%/*}" mkdir -p "${GTKINI%/*}"
grep -q '^\[Settings\]' "$GTKINI" 2>/dev/null || printf '[Settings]\n' >> "$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" 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 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 # 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 # 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. # app gave one (VNC_PASSWORD), as before.
GEOM="${SCREEN_SIZE%x*}" 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 if [ -n "${VNC_PASSWORD:-}" ]; then
mkdir -p /home/bot/.vnc mkdir -p /home/bot/.vnc
printf '%s\n' "$VNC_PASSWORD" | vncpasswd -f > /home/bot/.vnc/passwd && chmod 600 /home/bot/.vnc/passwd 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.) # (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" VNC_SEC="-SecurityTypes VncAuth -rfbauth /home/bot/.vnc/passwd"
else else
VNC_SEC="-SecurityTypes None" 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 & >/tmp/xvnc.log 2>&1 &
XVFB_PID=$! XVFB_PID=$!
for i in $(seq 1 50); do xdpyinfo -display :1 >/dev/null 2>&1 && break; sleep 0.1; done 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` # 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. # (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 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 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 chmod 600 /tmp/anybot-dbus.env /tmp/anybot-dbus.sh
export DBUS_SESSION_BUS_ADDRESS 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 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 done
for c in /usr/libexec/at-spi2-registryd /usr/lib/at-spi2-core/at-spi2-registryd; do 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 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 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. # The file window opens smaller than the screen, whatever size it was left at. (GTK takes the
SW="${GEOM%x*}"; SH="${GEOM#*x}" # saved size only with a saved place too; without one it sized the window from the font, and with
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 # 粉圓 12 that was 1342×1029: 開啟 off the right edge of the screen.)
su bot -c "DISPLAY=:1 DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS xrdb -nocpp -merge /home/bot/.Xresources" 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 "DISPLAY=:1 DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS fluxbox >/tmp/fluxbox.log 2>&1 &" 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 # 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). # 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 &" 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 # 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<key>. # (每個 Bot 一個螢幕). A viewer picks one with ?path=websockify%3Ftoken%3D<key>.
rm -rf /tmp/anybot-screens; mkdir -p /tmp/anybot-screens && chmod 1777 /tmp/anybot-screens 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.) # 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 --heartbeat=30 --web /usr/share/novnc --token-plugin TokenFile --token-source /tmp/anybot-vnc-tokens 6080 >/tmp/novnc.log 2>&1 &
WEBSOCKIFY_PID=$! 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 # 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. # early file meant the first viewer load 404'd.
( (
@ -73,9 +105,28 @@ WEBSOCKIFY_PID=$!
done done
echo "anybot-box ready" > /tmp/anybot-box.ready 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 # 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). # with a dead X server, and every screen action failed forever).
wait $XVFB_PID wait $XVFB_PID
kill $WEBSOCKIFY_PID 2>/dev/null 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 exit 1

15
box/terminal Normal file
View File

@ -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" "$@"

17
box/welcome.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="utf-8">
<title>Bot 的電腦</title>
<style>
body { font-family: "jf open 粉圓 2.1", "Noto Sans CJK TC", "Noto Sans", sans-serif; margin: 3rem; background: #2f343f; color: #d3dae3; }
h1 { font-size: 1.6rem; }
.hint { color: #5294e2; }
</style>
</head>
<body>
<h1>這是 Bot 的電腦</h1>
<p>登入、驗證碼、付款請在這個畫面完成。帳密只在這裡輸入,對話裡看不到。</p>
<p class="hint">下方工作列有「應用程式」「瀏覽器」「檔案管理員」和「終端機」;Bot 下載的檔案在檔案管理員的「下載」。做完後回到聊天跟 Bot 說「好了」。</p>
</body>
</html>

12
box/xfce/browser.desktop Normal file
View File

@ -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

View File

@ -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";

View File

@ -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;

3
box/xfce/helpers.rc Normal file
View File

@ -0,0 +1,3 @@
WebBrowser=anybot-browser
TerminalEmulator=anybot-terminal
FileManager=thunar

49
box/xfce/menu.xml Normal file
View File

@ -0,0 +1,49 @@
<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN"
"http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd">
<!-- 應用程式 (the panel's menu and the desktop's right click): the box's few programs in one
list, no XFCE settings (the desktop comes from the image on every boot, and most of those
settings need XFCE's settings service, which the box doesn't run). A program a bot installs
shows up under 其他. Replaces Debian's /etc/xdg/menus/xfce-applications.menu. -->
<Menu>
<Name>Xfce</Name>
<DefaultAppDirs/>
<DefaultDirectoryDirs/>
<Include>
<Filename>anybot-browser.desktop</Filename>
<Filename>anybot-terminal.desktop</Filename>
<Filename>thunar.desktop</Filename>
<Filename>org.xfce.mousepad.desktop</Filename>
<Filename>org.xfce.ristretto.desktop</Filename>
</Include>
<Layout>
<Filename>anybot-browser.desktop</Filename>
<Filename>thunar.desktop</Filename>
<Filename>anybot-terminal.desktop</Filename>
<Filename>org.xfce.mousepad.desktop</Filename>
<Filename>org.xfce.ristretto.desktop</Filename>
<Separator/>
<Merge type="menus"/>
</Layout>
<Menu>
<Name>Other</Name>
<Directory>xfce-other.directory</Directory>
<Include>
<All/>
</Include>
<Exclude>
<Or>
<Filename>anybot-browser.desktop</Filename>
<Filename>anybot-terminal.desktop</Filename>
<Filename>thunar.desktop</Filename>
<Filename>org.xfce.mousepad.desktop</Filename>
<Filename>org.xfce.ristretto.desktop</Filename>
<Filename>thunar-bulk-rename.desktop</Filename>
<Filename>display-im6.q16.desktop</Filename>
<Filename>vim.desktop</Filename>
<Category>Settings</Category>
<Category>X-XFCE-SettingsDialog</Category>
<Category>X-Xfce-Toplevel</Category>
</Or>
</Exclude>
</Menu>
</Menu>

22
box/xfce/mimeapps.list Normal file
View File

@ -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

11
box/xfce/terminal.desktop Normal file
View File

@ -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

32
box/xfce/wallpaper.svg Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="1920" height="1200" viewBox="0 0 1920 1200">
<defs>
<linearGradient id="base" x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stop-color="#383c4a"/>
<stop offset="0.55" stop-color="#2f343f"/>
<stop offset="1" stop-color="#1b1e24"/>
</linearGradient>
<radialGradient id="glowBlue" cx="0.78" cy="0.22" r="0.55">
<stop offset="0" stop-color="#5294e2" stop-opacity="0.38"/>
<stop offset="0.5" stop-color="#5294e2" stop-opacity="0.10"/>
<stop offset="1" stop-color="#5294e2" stop-opacity="0"/>
</radialGradient>
<radialGradient id="glowTeal" cx="0.12" cy="0.88" r="0.5">
<stop offset="0" stop-color="#4dd0c4" stop-opacity="0.22"/>
<stop offset="0.6" stop-color="#4dd0c4" stop-opacity="0.05"/>
<stop offset="1" stop-color="#4dd0c4" stop-opacity="0"/>
</radialGradient>
</defs>
<rect width="1920" height="1200" fill="url(#base)"/>
<rect width="1920" height="1200" fill="url(#glowBlue)"/>
<rect width="1920" height="1200" fill="url(#glowTeal)"/>
<g fill="none" stroke="#5294e2" stroke-opacity="0.16" stroke-width="2">
<circle cx="1500" cy="260" r="220"/>
<circle cx="1500" cy="260" r="340"/>
<circle cx="1500" cy="260" r="470"/>
</g>
<g fill="none" stroke="#ffffff" stroke-opacity="0.05" stroke-width="1.5">
<path d="M0 900 C 400 780, 800 1020, 1200 880 S 1700 760, 1920 840"/>
<path d="M0 980 C 420 860, 820 1100, 1220 960 S 1720 840, 1920 920"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xfce4-desktop" version="1.0">
<property name="desktop-icons" type="empty">
<property name="style" type="int" value="0"/>
<property name="file-icons" type="empty">
<property name="show-home" type="bool" value="false"/>
<property name="show-filesystem" type="bool" value="false"/>
<property name="show-trash" type="bool" value="false"/>
<property name="show-removable" type="bool" value="false"/>
</property>
</property>
<property name="desktop-menu" type="empty">
<property name="show" type="bool" value="true"/>
<property name="show-icons" type="bool" value="true"/>
</property>
<property name="windowlist-menu" type="empty">
<property name="show" type="bool" value="true"/>
<property name="show-icons" type="bool" value="true"/>
<property name="show-workspace-names" type="bool" value="false"/>
</property>
<!-- xfdesktop reads the backdrop under the screen's RANDR output name: TigerVNC's (start.sh
writes it for @OUTPUT@; the bots' own screens are TigerVNC too), Xvfb's "screen", or a numbered one. -->
<property name="backdrop" type="empty">
<property name="screen0" type="empty">
<property name="monitorscreen" type="empty">
<property name="workspace0" type="empty">
<property name="color-style" type="int" value="0"/>
<property name="image-style" type="int" value="5"/>
<property name="last-image" type="string" value="/usr/share/anybot/wallpaper.svg"/>
<property name="rgba1" type="array">
<value type="double" value="0.184314"/>
<value type="double" value="0.203922"/>
<value type="double" value="0.247059"/>
<value type="double" value="1"/>
</property>
</property>
</property>
<property name="monitor0" type="empty">
<property name="workspace0" type="empty">
<property name="color-style" type="int" value="0"/>
<property name="image-style" type="int" value="5"/>
<property name="last-image" type="string" value="/usr/share/anybot/wallpaper.svg"/>
<property name="rgba1" type="array">
<value type="double" value="0.184314"/>
<value type="double" value="0.203922"/>
<value type="double" value="0.247059"/>
<value type="double" value="1"/>
</property>
</property>
</property>
<property name="monitor@OUTPUT@" type="empty">
<property name="workspace0" type="empty">
<property name="color-style" type="int" value="0"/>
<property name="image-style" type="int" value="5"/>
<property name="last-image" type="string" value="/usr/share/anybot/wallpaper.svg"/>
<property name="rgba1" type="array">
<value type="double" value="0.184314"/>
<value type="double" value="0.203922"/>
<value type="double" value="0.247059"/>
<value type="double" value="1"/>
</property>
</property>
</property>
</property>
</property>
</channel>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- The panel stays as the image has it: a right click on it has no 移除/移動/屬性/面板偏好設定
(a stray click took the browser or the clock off the panel until the next boot). A panel
whose /panels/panel-N is locked here is locked; xfconf only honors a lock that names the user
("*" is ignored). The panel itself is the user's file (start.sh). -->
<channel name="xfce4-panel" version="1.0">
<property name="panels" type="array">
<value type="int" value="1"/>
<property name="panel-1" type="empty" locked="bot"/>
</property>
</channel>

71
box/xfce/xfce4-panel.xml Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xfce4-panel" version="1.0">
<property name="configver" type="int" value="2"/>
<property name="panels" type="array">
<value type="int" value="1"/>
<property name="dark-mode" type="bool" value="true"/>
<property name="panel-1" type="empty">
<!-- The bottom edge, the full width; start.sh puts x/y on the screen's real size. -->
<property name="position" type="string" value="p=8;x=640;y=782"/>
<property name="length" type="uint" value="100"/>
<property name="position-locked" type="bool" value="true"/>
<property name="size" type="uint" value="36"/>
<property name="icon-size" type="uint" value="22"/>
<property name="background-style" type="uint" value="0"/>
<property name="autohide-behavior" type="uint" value="0"/>
<property name="mode" type="uint" value="0"/>
<property name="plugin-ids" type="array">
<value type="int" value="1"/>
<value type="int" value="6"/>
<value type="int" value="8"/>
<value type="int" value="7"/>
<value type="int" value="2"/>
<value type="int" value="3"/>
<value type="int" value="4"/>
<value type="int" value="5"/>
</property>
</property>
</property>
<property name="plugins" type="empty">
<property name="plugin-1" type="string" value="applicationsmenu">
<property name="show-generic-names" type="bool" value="false"/>
<property name="show-button-icon" type="bool" value="true"/>
<property name="show-button-title" type="bool" value="true"/>
<property name="button-title" type="string" value="應用程式"/>
</property>
<property name="plugin-6" type="string" value="launcher">
<property name="items" type="array">
<value type="string" value="anybot-browser.desktop"/>
</property>
</property>
<property name="plugin-7" type="string" value="launcher">
<property name="items" type="array">
<value type="string" value="anybot-terminal.desktop"/>
</property>
</property>
<property name="plugin-8" type="string" value="launcher">
<property name="items" type="array">
<value type="string" value="thunar.desktop"/>
</property>
</property>
<property name="plugin-2" type="string" value="tasklist">
<property name="show-handle" type="bool" value="false"/>
<property name="show-labels" type="bool" value="true"/>
<property name="flat-buttons" type="bool" value="true"/>
<property name="grouping" type="uint" value="0"/>
<property name="include-all-workspaces" type="bool" value="true"/>
</property>
<property name="plugin-3" type="string" value="separator">
<property name="expand" type="bool" value="true"/>
<property name="style" type="uint" value="0"/>
</property>
<property name="plugin-4" type="string" value="systray"/>
<property name="plugin-5" type="string" value="clock">
<property name="mode" type="uint" value="2"/>
<property name="digital-format" type="string" value="%H:%M"/>
<property name="digital-layout" type="uint" value="3"/>
<property name="digital-time-format" type="string" value="%H:%M"/>
<property name="digital-date-format" type="string" value="%m/%d"/>
</property>
</property>
</channel>

24
box/xfce/xfwm4.xml Normal file
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xfwm4" version="1.0">
<property name="general" type="empty">
<property name="use_compositing" type="bool" value="false"/>
<property name="workspace_count" type="int" value="1"/>
<property name="wrap_windows" type="bool" value="false"/>
<property name="wrap_workspaces" type="bool" value="false"/>
<property name="click_to_focus" type="bool" value="true"/>
<property name="focus_new" type="bool" value="true"/>
<property name="raise_on_click" type="bool" value="true"/>
<property name="box_move" type="bool" value="false"/>
<property name="box_resize" type="bool" value="false"/>
<property name="snap_to_border" type="bool" value="true"/>
<property name="snap_to_windows" type="bool" value="true"/>
<property name="title_font" type="string" value="jf open 粉圓 2.1 11"/>
<property name="button_layout" type="string" value="O|HMC"/>
<property name="theme" type="string" value="Arc-Dark"/>
<property name="double_click_action" type="string" value="maximize"/>
<!-- New windows open in the middle of the screen (XFCE put a big one in the top-left corner,
over the browser's tabs). A window that asks for a place still gets it. -->
<property name="placement_ratio" type="int" value="100"/>
<property name="placement_mode" type="string" value="center"/>
</property>
</channel>

View File

@ -5,7 +5,7 @@
## 子功能 ## 子功能
- 四種電腦,每台都用自己的名字稱呼: - 四種電腦,每台都用自己的名字稱呼:
- Bot 自己的電腦(「<Bot 名字> 的電腦」):一台 Linux(Debian,有桌面和 Chromium,可以 sudo 裝套件),跑在 Docker 裡,所有 Bot 共用一台,各有自己的資料夾、自己的螢幕和自己的瀏覽器(見 [screen](screen.md)),一直開著。沒有 Docker 時退回成一個封閉的資料夾,沒有桌面。 - Bot 自己的電腦(「<Bot 名字> 的電腦」):一台 Linux(Debian 加 XFCE 桌面、Chromium,繁體中文、台北時間,可以 sudo 裝套件),跑在 Docker 裡,所有 Bot 共用一台,各有自己的資料夾、自己的螢幕和自己的瀏覽器(見 [screen](screen.md)),一直開著。沒有 Docker 時退回成一個封閉的資料夾,沒有桌面。
- 這台電腦(AnyBot 開著的這台,名字可以改):從 Bot 的「起始資料夾」開始。大腦放在伺服器上時,伺服器本身不在清單裡。 - 這台電腦(AnyBot 開著的這台,名字可以改):從 Bot 的「起始資料夾」開始。大腦放在伺服器上時,伺服器本身不在清單裡。
- SSH 電腦:自己加的,一個名稱加一個位址(例如 me@studio.local)。 - SSH 電腦:自己加的,一個名稱加一個位址(例如 me@studio.local)。
- 帳號裡的其他電腦:登入同一個帳號、打開「讓帳號裡的其他電腦使用這台」、而且現在在線上的 AnyBot(螢幕電腦、手腳電腦),經過帳號伺服器操作檔案、指令、瀏覽器、看畫面和點擊。 - 帳號裡的其他電腦:登入同一個帳號、打開「讓帳號裡的其他電腦使用這台」、而且現在在線上的 AnyBot(螢幕電腦、手腳電腦),經過帳號伺服器操作檔案、指令、瀏覽器、看畫面和點擊。
@ -20,19 +20,21 @@
- Bot 設定 ›「電腦操作」:「讓這個 Bot 查看、修改檔案和執行指令」,勾了才出現下面幾項:「做事的電腦」(旁邊寫「聊天時指名別台就會換」);「可以用的電腦」(有兩台以上才出現);「起始資料夾」。 - Bot 設定 ›「電腦操作」:「讓這個 Bot 查看、修改檔案和執行指令」,勾了才出現下面幾項:「做事的電腦」(旁邊寫「聊天時指名別台就會換」);「可以用的電腦」(有兩台以上才出現);「起始資料夾」。
- 設定 ›「電腦」:「你的電腦」一段(鉛筆改這台的名字、「在這台電腦上執行」、「其他電腦」展開看帳號裡的電腦和 SSH 電腦,填「SSH 電腦名稱,例如 工作站」和位址按「新增」,或「移除」,還有「讓帳號裡的其他電腦使用這台」);「Bot 的電腦」一段(狀態、「開啟電腦」看畫面和接手、快照、更新、重設、環境密鑰、Docker 主機;在大腦的螢幕上只有「在大腦上」,要到大腦那台管理)。 - 設定 ›「電腦」:「你的電腦」一段(鉛筆改這台的名字、「在這台電腦上執行」、「其他電腦」展開看帳號裡的電腦和 SSH 電腦,填「SSH 電腦名稱,例如 工作站」和位址按「新增」,或「移除」,還有「讓帳號裡的其他電腦使用這台」);「Bot 的電腦」一段(狀態、「開啟電腦」看畫面和接手、快照、更新、重設、環境密鑰、Docker 主機;在大腦的螢幕上只有「在大腦上」,要到大腦那台管理)。
- 設定 › 一般 ›「手機與帳號」:「大腦」那一欄選哪台當大腦(「改用它當大腦」),「加一台電腦」按「產生配對碼」。 - 設定 › 一般 ›「手機與帳號」:「大腦」那一欄選哪台當大腦(「改用它當大腦」),「加一台電腦」按「產生配對碼」。
- Bot 的電腦的畫面(「開啟電腦」):下方工作列由左到右是「應用程式」選單、「瀏覽器」、「檔案管理員」、「終端機」、開著的視窗、時鐘;桌面按右鍵也有應用程式選單(瀏覽器、檔案管理員、終端機、文字編輯器、影像檢視器,Bot 裝的程式在「其他」)。瀏覽器開機就開好(第一次是說明頁),跟 Bot 的瀏覽器工具是同一個、登入共用。檔案管理員側邊欄的「下載」是 Bot 下載的檔案;檔案按兩下會用對的程式開。
- 側邊欄底部名字右邊的「↑」(「傳送檔案或文字到其他裝置」)。手機:左上頭像選單 ›「傳送到其他裝置」;首頁上面一排的「電腦」。 - 側邊欄底部名字右邊的「↑」(「傳送檔案或文字到其他裝置」)。手機:左上頭像選單 ›「傳送到其他裝置」;首頁上面一排的「電腦」。
## 怎麼操作 ## 怎麼操作
- Bot:`list_computers` 看自己能用哪幾台、每台是什麼、哪台是使用者選的、選的那台有沒有連線。檔案、指令、螢幕、瀏覽器工具都有 `computer` 參數,填電腦的名字;不填就是使用者選的那台。使用者說「我的電腦」「這台」指的是他正在用的那台,不確定就先問。使用者要把檔案放到另一台裝置時才用 `send_to_device`(path、to 填裝置名稱或「手機」、computer 是檔案現在在的那台);把結果交給使用者用 `send_file`([files](files.md))。 - 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 不能自己換電腦:工具指定了別台,但使用者最近三則訊息沒提到那台,這一步會被移回使用者選的那台,結果裡會說。真的要別台先問使用者。 - Bot 不能自己換電腦:工具指定了別台,但使用者最近三則訊息沒提到那台,這一步會被移回使用者選的那台,結果裡會說。真的要別台先問使用者。
- 使用者選的那台沒開機、或那台的 AnyBot 沒開沒登入,就不在清單上:Bot 先待在自己的電腦,`list_computers` 會寫那台「現在沒有連線」。 - 使用者選的那台沒開機、或那台的 AnyBot 沒開沒登入,就不在清單上:Bot 先待在自己的電腦,`list_computers` 會寫那台「現在沒有連線」。
- 在 Bot 自己的電腦上做事不用問,但它看不到使用者的檔案;檔案工具只碰得到自己的資料夾(大家共用同一台)。 - 在 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)。 - 從帳號看 Bot 電腦的畫面,只要開著就不會斷;之前靜止畫面一分鐘、或看超過十分鐘會被帳號伺服器切掉,要更新帳號伺服器(make update-server)。
- 「在這台電腦上執行」設成永不允許(或被管理員鎖住)時,這台的檔案也不能傳出去、打開或發佈。 - 「在這台電腦上執行」設成永不允許(或被管理員鎖住)時,這台的檔案也不能傳出去、打開或發佈。
- SSH 電腦上的檔案不能直接傳到聊天、打開給使用者看或發佈網站,要先複製到 Bot 自己的電腦。 - SSH 電腦上的檔案不能直接傳到聊天、打開給使用者看或發佈網站,要先複製到 Bot 自己的電腦。

View File

@ -126,15 +126,33 @@ const CLICK_REPEAT_MS: u64 = 80;
const TYPE_DELAY_MS: u64 = 12; const TYPE_DELAY_MS: u64 = 12;
const DOCKERFILE: &str = include_str!("../box/Dockerfile"); const DOCKERFILE: &str = include_str!("../box/Dockerfile");
const START_SH: &str = include_str!("../box/start.sh"); /// Every file the box image is built from (build_image writes them next to the Dockerfile), by
const FLUXBOX_INIT: &str = include_str!("../box/fluxbox-init"); /// its path under box/. The desktop is LazyBoy2's: XFCE with a panel, Arc-Dark, jf open 粉圓.
const OVERLAY: &str = include_str!("../box/overlay"); const BOX_FILES: &[(&str, &str)] = &[
const XRESOURCES: &str = include_str!("../box/Xresources"); ("start.sh", include_str!("../box/start.sh")),
const MENU: &str = include_str!("../box/menu"); ("a11y", include_str!("../box/a11y")),
const A11Y: &str = include_str!("../box/a11y"); ("browser", include_str!("../box/browser")),
const BROWSER: &str = include_str!("../box/browser"); // 每個 Bot 一個螢幕: opens, lists and closes the bots' own screens.
/// 每個 Bot 一個螢幕: opens, lists and closes the bots' own screens. ("screen", include_str!("../box/screen")),
const SCREEN_SH: &str = 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 ---------- // ---------- 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 dir = std::env::temp_dir().join(format!("anybot-box-build-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir); let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?; 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)] { for (name, body) in std::iter::once(&("Dockerfile", DOCKERFILE)).chain(BOX_FILES) {
std::fs::write(dir.join(name), body).map_err(|e| e.to_string())?; 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("正在建立電腦的映像檔(第一次要幾分鐘)…"); log("正在建立電腦的映像檔(第一次要幾分鐘)…");
let mut args = vec!["build", "-q", "-t", image()]; let mut args = vec!["build", "-q", "-t", image()];
@ -2520,14 +2542,20 @@ pub fn step_stats() -> (usize, u64, u64) {
static STEP_TIMES: Mutex<Vec<(u64, u64)>> = Mutex::new(Vec::new()); static STEP_TIMES: Mutex<Vec<(u64, u64)>> = Mutex::new(Vec::new());
/// Programs people name, as the box knows them. /// Programs people name, as the box knows them: (what starts it, its windows' class name).
fn box_program(app: &str) -> Option<&'static str> { fn box_program(app: &str) -> Option<(&'static str, &'static str)> {
let a = app.trim().to_lowercase(); let a = app.trim().to_lowercase();
if ["chrome", "chromium", "google chrome", "browser", "瀏覽器", "網頁瀏覽器"].iter().any(|n| a == *n) { 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) { // The panel's 終端機 (xfce4-terminal through anybot-terminal: the desktop's bus, one process
return Some("xterm"); // 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 None
} }
@ -2539,24 +2567,28 @@ fn open_on_box(app: &str) -> Result<String, String> {
if name.is_empty() { if name.is_empty() {
return Err("請給要打開的程式名稱".into()); return Err("請給要打開的程式名稱".into());
} }
let prog = match box_program(name) { let (prog, class) = match box_program(name) {
Some(p) => p.to_string(), Some((p, c)) => (p.to_string(), c.to_string()),
None if name.chars().all(|c| c.is_ascii_alphanumeric() || "._-".contains(c)) => name.to_lowercase(), 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(瀏覽器)、xterm(終端機),或用指令工具安裝。")), None => return Err(format!("這台是 Linux 桌面,沒有「{name}」。可以打開的例如 chromium(瀏覽器)、終端機、檔案管理員,或用指令工具安裝。")),
}; };
if prog == "chromium" { if prog == "chromium" {
browser_port()?; browser_port()?;
} }
let q = crate::tools::sh_quote(&prog); 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!( let script = format!(
"w=$(xdotool search --onlyvisible --classname {q} 2>/dev/null | tail -1); \ "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; }}; (setsid {q} >/dev/null 2>&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 {q} 2>/dev/null | tail -1); [ -n \"$w\" ] && break; done; fi; \ 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" if [ -n \"$w\" ]; then xdotool windowactivate $w 2>/dev/null; echo shown; fi; true"
); );
let out = box_exec(&script)?; 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). /// Run a computer_use tool on the box. Returns (text, screenshot as base64 JPEG).
@ -3144,6 +3176,12 @@ mod tests {
println!("typed: {out}"); println!("typed: {out}");
assert_eq!(out.trim(), "a-b 中文 /"); assert_eq!(out.trim(), "a-b 中文 /");
let _ = box_exec("xdotool key --clearmodifiers ctrl+d"); 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`. /// Uses the real Docker: `cargo test --release -- --ignored box_batch_in_one_round_trip --nocapture`.
@ -3388,7 +3426,7 @@ mod tests {
println!("{l}"); println!("{l}");
} }
assert!(run_state().is_running(), "{:?}", run_state()); 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}"); println!("{out}");
assert!(ok && out.contains("keep-me") && out.contains("no-cowsay") && out.contains("Bot 的電腦")); 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); let _ = run_on("shell", r#"{"command":"cd .. && rm -rf bot-998"}"#, &t, &cancel, &ids);
@ -3423,13 +3461,22 @@ mod tests {
use chrono::TimeZone; use chrono::TimeZone;
let at = chrono::Utc.with_ymd_and_hms(2026, 11, 6, 19, 0, 0).unwrap().with_timezone(&chrono_tz::Asia::Taipei); 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!(in_schedule_window("03:00", at.time()));
assert_eq!(wanted_version(), "11"); assert_eq!(wanted_version(), "12");
// Every file the Dockerfile copies is one this app carries (build_image writes them). // Every file the Dockerfile copies is one this app carries (build_image writes them), and
let carried = ["start.sh", "fluxbox-init", "overlay", "Xresources", "menu", "a11y", "browser", "screen"]; // every file carried is copied.
for l in DOCKERFILE.lines().filter_map(|l| l.trim().strip_prefix("COPY ")) { let copied: Vec<&str> = DOCKERFILE.lines().filter_map(|l| l.trim().strip_prefix("COPY ")).map(|l| l.split_whitespace().next().unwrap()).collect();
let src = l.split_whitespace().next().unwrap(); for src in &copied {
assert!(carried.contains(&src), "the Dockerfile copies {src}, which build_image doesn't write"); 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. // 每個 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");
assert_eq!(screen_of_dir("/home/bot/bot-12/"), "bot12"); assert_eq!(screen_of_dir("/home/bot/bot-12/"), "bot12");

View File

@ -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 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:-}" k desktop "${XDG_CURRENT_DESKTOP:-}"
[ -n "${TZ:-}" ] && k tz "$TZ" [ -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" 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 /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 if [ -d /Applications ]; then k apps "$(ls /Applications 2>/dev/null | sed -n 's/\.app$//p' | head -80 | tr '\n' '|')"; fi