AnyBot/src/notify.rs

428 lines
19 KiB
Rust
Raw Normal View History

// Getting the person's attention when a bot needs them (or finished) while they're away.
//
// Behaviour spec:
// - macOS 10.14+ and a real .app bundle: ask UNUserNotificationCenter, waiting at most 3 s.
// authorizationStatus 0..4 = notDetermined/denied/authorized/provisional/ephemeral (else "unknown");
// alertSetting 0..2 = notSupported/disabled/enabled (else "unknown").
// - authorized/provisional/ephemeral → granted, denied → denied, notDetermined → undetermined.
// Banners only when authorized and alerts enabled.
// - The desktop counts as present only when not locked, not idle for 90 s and the window is
// alive; re-checked every 10 s.
use std::process::{Command, Stdio};
/// Away after this much keyboard/mouse silence `Z_e=9e4`).
pub const IDLE_THRESHOLD_SECS: f64 = 90.0;
/// How often presence is re-read `uBt=1e4`).
pub const PRESENCE_POLL_SECS: f64 = 10.0;
/// Seconds since the last keyboard or mouse input (macOS `HIDIdleTime`, in nanoseconds).
pub fn parse_hid_idle(ioreg: &str) -> Option<f64> {
let line = ioreg.lines().find(|l| l.contains("\"HIDIdleTime\""))?;
let n: f64 = line.rsplit('=').next()?.trim().parse().ok()?;
Some(n / 1e9)
}
pub fn system_idle_secs() -> Option<f64> {
#[cfg(target_os = "linux")]
return crate::desk::idle_secs();
#[allow(unreachable_code)]
if !cfg!(target_os = "macos") {
return None;
}
let out = Command::new("ioreg").args(["-c", "IOHIDSystem", "-d", "4"]).stderr(Stdio::null()).output().ok()?;
parse_hid_idle(&String::from_utf8_lossy(&out.stdout))
}
perf+fix: 舊電腦也輕、連上才進去、送出不重複、小模型說了就做、智慧模式常開、提早壓縮 畫面省資源(舊 Intel Mac) - 聊天紀錄改成共用、寫入時才複製(src/shared.rs):側欄和聊天每一格不再複製整份聊天(約 13 MB/格) - Markdown 解析、程式碼上色依內容快取,只有串流中的那則重算 - 用內建顯示晶片(wgpu LowPower),雙 GPU 的 Mac 不再喚醒獨顯;WGPU_POWER_PREF 照樣優先 - 所有轉圈圖示限每秒 20 次(egui 內建 Spinner 跑滿刷新率);淡入、彩帶、跳轉高亮也限速 - 頭像共用一個眨眼時鐘、捲出畫面的不畫;你不在(視窗不在前面或 90 秒沒動)不眨眼 - ioreg 移出畫面執行緒;Bot 工作中每 5 秒存一次(原 2 秒) - 螢幕電腦的大腦副本每 5 秒在背景寫一次(原本每次同步都在畫面執行緒寫整份) - 手機狀態裡的指令輸出先截短再遮罩金鑰 連線(螢幕電腦 ↔ 大腦) - 連上、拿到最新資料才進去:之前整個視窗停在「正在連到「…」…」,連不上 10 秒以上可改回這台自己的 Bot - 重開只補差異:副本旁記下版本與這台在大腦的名字;第一次拉取帶 config=1、不等新消息 - 漏收一次回應只補差異(大腦保留上一份 Seen),不再整份重抓 - 送出不重複:POST 只在根本沒送出去時才重試;訊息與動作帶編號、斷線自己重送約 100 秒,大腦同一個只做一次;改動依 (client, seq) 只做一次,seq 從時鐘起算 - 斷一下還能送(排隊),真的送不到文字放回輸入框;按過的允許卡片 30 秒內不再跳出 - 獨立審查修正:動作編號加上這次啟動的標記(沿用 client 時不再撞號被當重送);等待頁以「收到第一個回答」為準、設定讀不出來照樣進去並說原因、等滿 10 秒就有離開鈕;整份重抓失敗會再要;上一次拉取失敗時帶 retry,大腦從上一份算差異;去重表滿了淘汰最舊的 - 手機頁在背景時不重畫訊息,回到前景再畫 小模型持續做(src/agent/followthrough.rs) - 回答說了要做什麼卻沒呼叫工具、或問「要我現在就開始嗎?」:告訴模型、下一步安靜地跑;動手才顯示,標記「〔到此為止〕」或又只說一次都不顯示;連兩次、一輪 12 次為限;最後一句提到刪除、付款、寄出、關機這類收不回來的事一律不提醒 - OpenCode Go 模型清單改讀新格式 api/recommended_api(舊的 endpoint 照讀) 智慧模式常開 - 預設開、/smart off 與手機都關不掉(只有管理員鎖時關);設定頁只剩逾時滑桿 30–1800 秒;輸入列不再有它的圖示 token 壓縮提早 - 門檻 70→60%(進行中 65%);估算改成英數 3.5 字元一 token;一個要求做很多步時主動把這一輪較早的步驟寫成摘要(至少 10 則),不等模型說太長 feature-map:chat.md 新增 chat-followthrough(含步驟)、chat-compact 6 成、chat-steps;autonomy.md 智慧模式一直開著(步驟改寫);account.md 連上才進去、重送與去重;settings/safety/phone 同步。FEATURES.md 同步。 已驗證: cargo test 739 通過、clippy 無新警告(含 featuremap:: 11 項、layout_audit::、新增 followthrough/shared/mirror 去重與漏收補差異測試);verify-anybot:chat.md「/ 指令」(/context 寫「到 60% 會自動」)、「說了就做」(只說「我把它整理成一頁做法文件。」後同一輪接著執行 echo ft-done 並收尾,模型那層收到提醒)、autonomy.md「智慧模式一直開著」(/smart off 回不能關,重開後 smart_mode 仍 true);審查修正後三步重跑結果相同;ctl down 無殘留;乾淨脈絡獨立審查 1 次(P0×1、P1×1 已修) 未驗證: 手機頁面畫面那一層(這台沒有 Google Chrome,無頭手機頁面開不起來,改走同一個大腦的手機 API);螢幕電腦連大腦的實際路徑(要帳號伺服器與第二台電腦:等待頁、重開續傳、斷線重送只在單元測試);真 Intel Mac 的 CPU/風扇與 LowPower GPU 實測;真的小模型(muse-spark 等)是否照提醒動手;動到審批路徑(智慧模式常開)需實機測試+人類簽名,本輪不發佈 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 14:28:31 +00:00
/// system_idle_secs read on a thread of its own, for the window: `ioreg` is a new process each
/// time (30–80 ms on an older Mac — a hitch every 10 s on the window's thread). Returns the last
/// reading (at most one poll old) and starts the next one unless one is still running.
pub fn idle_secs_in_background() -> Option<f64> {
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Mutex;
static LAST: Mutex<Option<f64>> = Mutex::new(None);
static READING: AtomicBool = AtomicBool::new(false);
if !READING.swap(true, Ordering::AcqRel) {
std::thread::spawn(|| {
let v = system_idle_secs();
*LAST.lock().unwrap_or_else(|e| e.into_inner()) = v;
READING.store(false, Ordering::Release);
});
}
*LAST.lock().unwrap_or_else(|e| e.into_inner())
}
/// Notify unless the person is looking at AnyBot right now: the window is in front and they
/// were active within the last 90 s.
pub fn should_notify(window_focused: bool, idle_secs: Option<f64>) -> bool {
!window_focused || idle_secs.map(|s| s >= IDLE_THRESHOLD_SECS).unwrap_or(false)
}
// ---------- applying a new version while you're away ----------
// Behaviour spec: apply when 自動更新 is on (default) and an update is staged, and the machine
// is idle: (screen locked || screensaver on) and idle for >= 600 s, and no bot work running.
// Checks: first 30 s after launch, then every 3600 s plus up to 300 s of random jitter.
pub const AUTO_UPDATE_IDLE_SECS: f64 = 600.0;
pub const UPDATE_FIRST_CHECK_SECS: u64 = 30;
pub const UPDATE_CHECK_INTERVAL_SECS: u64 = 3600;
pub const UPDATE_CHECK_JITTER_SECS: u64 = 300;
/// Every input of the idle-update rule, in one place.
pub fn should_apply_update_now(enabled: bool, update_ready: bool, screen_locked: bool, screensaver: bool, idle_secs: Option<f64>, bots_idle: bool) -> bool {
enabled && update_ready && (screen_locked || screensaver) && idle_secs.map(|s| s >= AUTO_UPDATE_IDLE_SECS).unwrap_or(false) && bots_idle
}
/// The screen is locked (Electron's `getSystemIdleState` "locked"; here the session flag).
pub fn screen_locked() -> bool {
if !cfg!(target_os = "macos") {
// systemd-logind knows when the session is locked.
let id = std::env::var("XDG_SESSION_ID").unwrap_or_default();
let mut c = Command::new("loginctl");
c.arg("show-session");
if !id.is_empty() {
c.arg(&id);
}
return c.args(["-p", "LockedHint"]).stderr(Stdio::null()).output().map(|o| String::from_utf8_lossy(&o.stdout).trim() == "LockedHint=yes").unwrap_or(false);
}
Command::new("ioreg").args(["-n", "Root", "-d1"]).stderr(Stdio::null()).output().map(|o| String::from_utf8_lossy(&o.stdout).contains("\"CGSSessionScreenIsLocked\" = Yes")).unwrap_or(false)
}
/// The screensaver is running: the original's `NRn` runs `pgrep -x ScreenSaverEngine` (2 s timeout).
pub fn screensaver_active() -> bool {
#[cfg(target_os = "linux")]
return crate::desk::screensaver_on();
#[allow(unreachable_code)]
if !cfg!(target_os = "macos") {
return false;
}
let Ok(mut c) = Command::new("pgrep").args(["-x", "ScreenSaverEngine"]).stdout(Stdio::null()).stderr(Stdio::null()).spawn() else { return false };
let start = std::time::Instant::now();
while start.elapsed() < std::time::Duration::from_secs(2) {
if let Ok(Some(st)) = c.try_wait() {
return st.success();
}
std::thread::sleep(std::time::Duration::from_millis(20));
}
let _ = c.kill();
let _ = c.wait();
false
}
/// Next periodic check: one hour plus a random part of five minutes.
pub fn next_update_check_secs(random_0_1: f64) -> u64 {
UPDATE_CHECK_INTERVAL_SECS + (random_0_1.clamp(0.0, 1.0) * UPDATE_CHECK_JITTER_SECS as f64).floor() as u64
}
fn applescript_quote(s: &str) -> String {
let clean: String = s.chars().filter(|c| !c.is_control() || *c == ' ').collect();
format!("\"{}\"", clean.replace('\\', "\\\\").replace('"', "\\\""))
}
/// The AppleScript line for a banner (title + message), with text safely quoted.
安全、修正: harden sandboxes, approval gates, vault, relay roles, and fix protocol/UI bugs - macOS 沙盒與工具 (tools.rs, policy.rs, docindex.rs): block AppleScript raw events and concatenation outside the sandbox; stop exposing ~/.ssh or localhost sockets in Sealed mode; deny writes to shell profiles, LaunchAgents and .git/hooks; expand secret-file ignores and enforce symlink/policy checks across SSH, device and document search. - 電腦操作與遮罩 (computer.rs, agent.rs, marks.rs, desktop.rs, cloudbox.rs, portal.rs): forbid clicking or typing into AnyBot's own windows; extend the sensitive-action hard gate to raw coordinates, Return/Delete submits and remote devices; stop batch steps if the front app changes; black out secrets on zoom, show, >600-node trees, adjacent OTP labels, box screenshots and control text lists; preserve non-text Wayland clipboards. - 保險庫與瀏覽器 (vault.rs, vault_store.rs, browser.rs, botbrowser.rs, web.rs, box/browser): verify tab host and HTTPS atomically at fill time; taint filled tabs against browser_eval and PDF export while masking card/CVC values and screenshots; remember sites only on always-allow; drop --remote-allow-origins=*; gate private URLs and block metadata/Docker ports, OrbStack 198.18/15 and IPv6 transition ranges. - 帳號伺服器、同步與傳送 (relay/, remote.rs, mirror_ui.rs, share.rs, drops.rs): isolate paired hands hosts from brain sync, tickets, pairing and backup overwrites; redact routine trigger secrets and clear REDACTED when endpoints change; isolate channel and team-member turns from owner memories, appctl and grants; scrub shared bot exports and reset grants/routines on import; validate drop IDs and serialize chunk writes. - 網路與協定穩定性 (httpd.rs, tunnel.rs, vnc.rs, Caddyfile*): fix chunked integer overflow and CRLF header injection; enforce Origin checks, connection/job caps, 200 MB backup reads, unique atomic temp files and ASCII hex guards; bound deflate unzip and VNC sniff buffers; move VNC stdin/text off the tunnel loop. - 介面、排程、語言與其他修正 (app.rs, i18n.rs, providers.rs, skills.rs, routines.rs, setup.rs, store.rs, preview.rs, attach.rs, speech.rs, teams.rs, mcp.rs, voice.rs): wire up the delete-routine confirmation dialog and mirror run-now; preserve unsaved mirror edits across brief disconnects; give Chinese skills distinct folders and approval gates; convert parsed tool JSON fields without corrupting code fences, URLs or paths; fix Hourly DST offsets and time out unattended routine approvals; lock --install-skill, cap docx/xlsx unzip sizes, isolate test env keys, and tighten local file permissions. Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-12 06:34:10 +00:00
#[cfg(test)]
pub fn banner_script(title: &str, body: &str) -> String {
banner_script_with(title, body, true)
}
/// Same, with or without macOS's own sound (none when AnyBot rings its 提示音 itself).
pub fn banner_script_with(title: &str, body: &str, sound: bool) -> String {
let body: String = body.chars().take(180).collect();
let line = format!("display notification {} with title {}", applescript_quote(&body), applescript_quote(title));
if sound {
format!("{line} sound name \"Glass\"")
} else {
line
}
}
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
/// Show a banner, with the system's sound. Doesn't wait.
pub fn banner(title: &str, body: &str) {
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
banner_for(title, body, true, None, None)
}
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
/// A banner about one bot: a click on it opens that bot's chat (`take_clicked`).
///
/// - macOS, inside AnyBot.app: the app's own banner (`center`), with AnyBot's icon (the cat on
/// yellow); a click brings AnyBot to the front on that bot. Run from a build folder (no bundle),
/// macOS's `display notification` instead (that banner shows Script Editor's icon).
/// - Linux: the desktop's notification service through notify-send, with AnyBot's icon.
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
pub fn banner_for(title: &str, body: &str, sound: bool, bot: Option<u64>, picture: Option<std::path::PathBuf>) {
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
let body: String = body.chars().take(180).collect();
if !cfg!(target_os = "macos") {
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
// The desktop's notification service (GNOME, KDE, XFCE…) through notify-send. Its icon,
// at the left, is the bot's avatar when it is the bot speaking (AnyBot's otherwise).
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
let mut cmd = Command::new("notify-send");
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
cmd.args(notify_send_args(title, &body, picture.clone().or_else(icon_png)));
let _ = crate::computer::spawn_reaped(cmd.stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null()));
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
return;
}
#[cfg(target_os = "macos")]
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
if center::post(title, &body, sound, bot, picture.as_deref()) {
return;
}
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
let _ = &picture;
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
let _ = bot;
let _ = crate::computer::spawn_reaped(Command::new("osascript").arg("-e").arg(banner_script_with(title, &body, sound)).stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null()));
}
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
/// notify-send's words: the app, the icon at the left (the bot's avatar, or AnyBot's), the title,
/// the text.
fn notify_send_args(title: &str, body: &str, icon: Option<std::path::PathBuf>) -> Vec<std::ffi::OsString> {
let mut a: Vec<std::ffi::OsString> = vec!["-a".into(), "AnyBot".into()];
if let Some(i) = icon {
a.push("-i".into());
a.push(i.into());
}
a.push(title.into());
a.push(body.into());
a
}
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
/// One banner from a command (`anybot --banner`): sends it and says which way it went.
pub fn banner_now(title: &str, body: &str) -> String {
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
banner_for(title, body, true, None, None);
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
#[cfg(target_os = "macos")]
{
if !center::usable() {
return "不在 AnyBot.app 裡:用 display notification 送出(圖示會是「工序指令編寫程式」)".into();
}
// (A moment for the system to take it before the program ends.)
std::thread::sleep(std::time::Duration::from_secs(1));
format!("AnyBot 自己的通知,通知中心裡有 {} 則 AnyBot 的通知", center::delivered())
}
#[cfg(not(target_os = "macos"))]
{
"notify-send".into()
}
}
/// Get ready to show banners (macOS: hear clicks on them, and show them while AnyBot is in front
/// but the person is idle). Call once at start, on the main thread.
pub fn prepare() {
#[cfg(target_os = "macos")]
center::prepare();
}
/// Bots whose banner the person clicked since the last call (the app opens that chat).
pub fn take_clicked() -> Vec<u64> {
#[cfg(target_os = "macos")]
{
center::take_clicked()
}
#[cfg(not(target_os = "macos"))]
{
vec![]
}
}
/// The identifier a banner gets: which bot it is about, and a number so each one is its own.
pub fn banner_id(bot: Option<u64>, n: u64) -> String {
format!("anybot-{}-{n}", bot.map(|b| b.to_string()).unwrap_or_else(|| "-".into()))
}
/// The bot a banner identifier is about.
pub fn bot_of_banner(id: &str) -> Option<u64> {
id.strip_prefix("anybot-")?.split('-').next()?.parse().ok()
}
/// AnyBot's icon as a PNG file for notify-send (drawn once into the data folder).
#[cfg_attr(target_os = "macos", allow(dead_code))]
fn icon_png() -> Option<std::path::PathBuf> {
static PATH: std::sync::OnceLock<Option<std::path::PathBuf>> = std::sync::OnceLock::new();
PATH.get_or_init(|| {
let path = crate::model::State::path().parent()?.join("anybot-icon.png");
if path.exists() {
return Some(path);
}
let icon = crate::app_icon_rgba(128);
image::RgbaImage::from_raw(128, 128, icon)?.save(&path).ok()?;
Some(path)
})
.clone()
}
/// AnyBot.app's own banners: NSUserNotificationCenter. The newer UNUserNotificationCenter only
/// lets apps signed by an Apple developer team send notifications (it answers "Notifications are
/// not allowed for this application"); AnyBot signs itself on each Mac (deploy/mac/sign.sh), and
/// the older center takes its banners, with the app's icon, without asking first. 系統設定 › 通知
/// › AnyBot still decides whether and how they show.
#[cfg(target_os = "macos")]
mod center {
use objc2::rc::Retained;
use objc2::runtime::{AnyClass, NSObject, NSObjectProtocol, ProtocolObject};
use objc2::{define_class, msg_send, ClassType};
#[allow(deprecated)]
use objc2_foundation::{NSBundle, NSString, NSUserNotification, NSUserNotificationCenter, NSUserNotificationCenterDelegate};
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
use std::sync::{Mutex, Once};
static PREPARED: Once = Once::new();
static USABLE: AtomicBool = AtomicBool::new(false);
static NEXT: AtomicU64 = AtomicU64::new(1);
static CLICKED: Mutex<Vec<u64>> = Mutex::new(Vec::new());
define_class!(
// Shows AnyBot's banners while AnyBot is in front too (they're only sent when the person
// is away, and idle in front of it counts), and hears which banner was clicked.
#[unsafe(super(NSObject))]
#[name = "AnyBotBannerDelegate"]
struct Delegate;
unsafe impl NSObjectProtocol for Delegate {}
#[allow(deprecated)]
unsafe impl NSUserNotificationCenterDelegate for Delegate {
#[unsafe(method(userNotificationCenter:shouldPresentNotification:))]
fn should_present(&self, _center: &NSUserNotificationCenter, _n: &NSUserNotification) -> bool {
true
}
#[unsafe(method(userNotificationCenter:didActivateNotification:))]
fn did_activate(&self, _center: &NSUserNotificationCenter, n: &NSUserNotification) {
if let Some(bot) = n.identifier().and_then(|id| super::bot_of_banner(&id.to_string())) {
if let Ok(mut c) = CLICKED.lock() {
c.push(bot);
}
}
}
}
);
/// Inside a real .app with an identifier (the center is nil for a bare program), on a macOS
/// that still has the center.
fn in_bundle() -> bool {
let b = NSBundle::mainBundle();
AnyClass::get(c"NSUserNotificationCenter").is_some() && b.bundleIdentifier().is_some() && b.bundlePath().to_string().ends_with(".app")
}
pub fn prepare() {
PREPARED.call_once(|| {
if !in_bundle() {
return;
}
USABLE.store(true, Ordering::SeqCst);
let delegate: Retained<Delegate> = unsafe { msg_send![Delegate::class(), new] };
#[allow(deprecated)]
unsafe {
NSUserNotificationCenter::defaultUserNotificationCenter().setDelegate(Some(ProtocolObject::from_ref(&*delegate)));
}
// The center keeps only a weak reference: the delegate lives as long as AnyBot.
std::mem::forget(delegate);
});
}
pub fn usable() -> bool {
prepare();
USABLE.load(Ordering::SeqCst)
}
/// Show the banner. False: not inside AnyBot.app (the caller uses display notification).
#[allow(deprecated)]
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
pub fn post(title: &str, body: &str, sound: bool, bot: Option<u64>, picture: Option<&std::path::Path>) -> bool {
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
if !usable() {
return false;
}
let n = NSUserNotification::new();
n.setTitle(Some(&NSString::from_str(title)));
n.setInformativeText(Some(&NSString::from_str(body)));
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
// The bot's avatar, at the banner's right (the left is always the app's own icon).
if let Some(img) = picture.and_then(image_at) {
let _: () = unsafe { msg_send![&*n, setContentImage: &*img] };
}
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
n.setIdentifier(Some(&NSString::from_str(&super::banner_id(bot, NEXT.fetch_add(1, Ordering::SeqCst)))));
if sound {
n.setSoundName(Some(&NSString::from_str("Glass")));
}
NSUserNotificationCenter::defaultUserNotificationCenter().deliverNotification(&n);
true
}
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
/// An NSImage of a picture file (AppKit is in every window app; no bindings needed for one call).
pub(super) fn image_at(path: &std::path::Path) -> Option<Retained<objc2::runtime::AnyObject>> {
let cls = AnyClass::get(c"NSImage")?;
let p = NSString::from_str(&path.to_string_lossy());
unsafe {
let a: objc2::rc::Allocated<objc2::runtime::AnyObject> = msg_send![cls, alloc];
msg_send![a, initWithContentsOfFile: &*p]
}
}
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
/// How many of AnyBot's banners the system is keeping (`anybot --banner`'s check).
#[allow(deprecated)]
pub fn delivered() -> usize {
if !usable() {
return 0;
}
NSUserNotificationCenter::defaultUserNotificationCenter().deliveredNotifications().count()
}
pub fn take_clicked() -> Vec<u64> {
CLICKED.lock().map(|mut c| std::mem::take(&mut *c)).unwrap_or_default()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn presence_rule() {
assert!(!should_notify(true, Some(5.0)));
assert!(should_notify(true, Some(90.0)));
assert!(should_notify(false, Some(1.0)));
assert!(!should_notify(true, None));
let sample = " | | \"HIDIdleTime\" = 123000000000\n";
assert_eq!(parse_hid_idle(sample), Some(123.0));
}
#[test]
fn update_applies_only_when_truly_away() {
assert!(should_apply_update_now(true, true, true, false, Some(600.0), true));
assert!(should_apply_update_now(true, true, false, true, Some(900.0), true));
assert!(!should_apply_update_now(true, true, false, false, Some(900.0), true), "screen in use");
assert!(!should_apply_update_now(true, true, true, false, Some(599.0), true), "not idle long enough");
assert!(!should_apply_update_now(true, true, true, false, Some(900.0), false), "a bot is working");
assert!(!should_apply_update_now(false, true, true, false, Some(900.0), true), "turned off");
assert!(!should_apply_update_now(true, false, true, false, Some(900.0), true), "nothing to apply");
assert_eq!(next_update_check_secs(0.0), 3600);
assert_eq!(next_update_check_secs(0.999), 3899);
}
電腦版的通知也像那個 Bot 傳來的訊息:標題是 Bot 的名字,內容就是那句話(回答的第一行、「需要你允許:修改 Bot 自己:名稱 → 新名字」、問的問題、例行任務「…」暫停、目標達成/暫停),帶著那個 Bot 的頭像。以前標題是「○○ 完成了」「○○ 需要你允許」,圖示是 AnyBot 的貓。 - Linux(notify-send):通知左邊的圖示就是 Bot 的頭像(Jenny 的 jenny-Host 是這種)。 - Mac(AnyBot.app 的 NSUserNotification):頭像在右邊(contentImage);左邊固定是 App 的圖示,系統不讓換。NSImage 用 AnyClass::get("NSImage") 直接叫,不多加 AppKit 的套件。 - 頭像圖:avatar::rgba 用畫面上同一個 paint 畫——egui 把它切成三角形(邊緣已經柔化),一格一格填成 RGBA(預乘 alpha、over),再轉成一般 alpha 存 PNG;avatar::png_file 照形狀、顏色、大小存在資料夾的 avatars/,只畫一次。14 種形狀都畫過(測試會檢查身體的顏色、四角透明、兩隻眼睛、柔化的邊)。 - notify-send 的參數抽成 notify_send_args(可以測);banner_for 多一個 picture。 已驗證: cargo test 841 過(新:avatars_become_pictures_for_notifications——14 種形狀各畫 96px,身體是那個顏色、四角透明、有眼睛、有柔化的邊,另外存出來看過一張總表;a_bots_banner_wears_its_avatar——notify-send 是 -a AnyBot -i <頭像> 名字 內容,沒圖就沒 -i;Mac 上 NSImage 讀得到那張 PNG、讀不存在的檔回 None);clippy 維持 12。 未驗證: 真的跳出來的通知長怎樣——Mac 要 AnyBot.app 才用得到 NSUserNotification(scratch 跑的不是 .app,會改用 display notification、沒圖),使用者真的 App 不能跑;Linux 要 Jenny 的桌面(等她的 AnyBot 更新)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha2uBHmbnuWBhNzjbJm
2026-11-21 09:08:11 +00:00
/// A bot's banner: its name, what it says, its avatar — at the left on Linux (notify-send's
/// icon), at the right on a Mac (an NSImage of the same picture).
#[test]
fn a_bots_banner_wears_its_avatar() {
let pic = std::env::temp_dir().join("anybot-banner-avatar.png");
image::RgbaImage::from_raw(64, 64, crate::avatar::rgba("pebble", crate::avatar::color("green"), 64)).unwrap().save(&pic).unwrap();
let a = notify_send_args("賴桑a炭吉貓", "回好了 3 則留言", Some(pic.clone()));
let words: Vec<String> = a.iter().map(|x| x.to_string_lossy().into_owned()).collect();
assert_eq!(words, ["-a", "AnyBot", "-i", &pic.to_string_lossy(), "賴桑a炭吉貓", "回好了 3 則留言"]);
assert_eq!(notify_send_args("t", "b", None).len(), 4, "no picture: no -i");
#[cfg(target_os = "macos")]
assert!(center::image_at(&pic).is_some(), "the Mac reads the avatar as an NSImage");
#[cfg(target_os = "macos")]
assert!(center::image_at(std::path::Path::new("/nonexistent/x.png")).is_none());
}
#[test]
fn banner_text_is_quoted() {
let s = banner_script("電腦助手 需要你允許", "執行 \"rm\" \\ 指令\n下一行");
assert_eq!(s, "display notification \"執行 \\\"rm\\\" \\\\ 指令下一行\" with title \"電腦助手 需要你允許\" sound name \"Glass\"");
}
feat: 電腦版不再破版、通知用 AnyBot 的貓、手機網頁像 App;從帳號看畫面不再斷線 電腦版:右側「進行中」的長重試訊息蓋過「停止」、衝出卡片,現在以「…」結尾(滑鼠移上去看 全文);Bot 設定的「團隊成員可以使用…」疊到儲存/取消、權限規則疊到「刪除」、「新增規則」 被切掉、電腦分頁的時間欄被切掉、窄視窗裡允許卡片的按鈕、「已排入…」和輸入框提示被切掉, 都修好。粉圓體比思源黑體寬,寫死寬度的地方用它就擠爆。新的 layout_audit 測試用三種字型、 最窄/一般/寬的視窗、示範和很長的資料,把每個設定分頁、Bot 設定、例行任務、右側面板畫一遍, 字被切掉或疊在一起就失敗(截圖模式也多了 ANYBOT_SHOT_PANEL/STATUS/TAB/SCROLL)。 通知:Mac 上原本用 osascript 的 display notification,橫幅是「工序指令編寫程式」的圖示、 點了還打開它。現在是 AnyBot.app 自己發的(NSUserNotificationCenter:新的 UNUserNotificationCenter 只給有 Apple 開發者簽章的 App 用,AnyBot 自簽),圖示是貓,點一 下打開那個 Bot;不在 .app 裡才退回 osascript。Linux 的 notify-send 帶上 AnyBot 的圖示。 anybot --banner 標題 內文 可以送一則試試。 手機(PWA):manifest 和 service worker 改成 mobile/ 裡一份,帳號伺服器和這台共用;加滿版的 maskable 圖示和 Android 狀態列用的單色貓(原本彩色圖變成白方塊)。每支手機滿版(左右安全 區域、狀態列跟著畫面顏色)、首頁提示裝成 App、換畫面左右滑、iPhone 主畫面 App 從左邊緣滑回 上一頁、按鈕長按不選字、搜尋框不放大。通知可以選要哪幾種(需要你/做完了/例行任務暫停/ 收到檔案)、送測試通知,App 圖示上的數字是正在等你的 Bot。 帳號伺服器:看 Bot 電腦畫面時,瀏覽器回的 Pong 沒算成還活著,靜止畫面一分鐘就被切;看畫面 的票證十分鐘一到就切斷、重連又拿同一張過期的票回不來。現在票證記得誰申請的(那支手機的 登入、帳號裡那台電腦),申請者還有效就一直連著,使用中的票證會續期。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:06:12 +00:00
#[test]
fn a_banner_click_finds_its_bot() {
assert_eq!(bot_of_banner(&banner_id(Some(42), 7)), Some(42));
assert_eq!(bot_of_banner(&banner_id(None, 7)), None);
assert_eq!(bot_of_banner("something-else"), None);
}
#[test]
fn a_banner_can_be_silent() {
// (When AnyBot plays its own 提示音, the banner doesn't add a second sound.)
assert_eq!(banner_script_with("標題", "內文", false), "display notification \"內文\" with title \"標題\"");
assert!(banner_script_with("標題", "內文", true).ends_with("sound name \"Glass\""));
}
}