diff --git a/docs/feature-map/computers.md b/docs/feature-map/computers.md index 936b47a..edb75ca 100644 --- a/docs/feature-map/computers.md +++ b/docs/feature-map/computers.md @@ -17,10 +17,10 @@ ## 使用者怎麼到 -- Bot 設定 ›「電腦操作」:「讓這個 Bot 查看、修改檔案和執行指令」,勾了才出現下面幾項:「做事的電腦」(旁邊寫「聊天時指名別台就會換」);「可以用的電腦」(有兩台以上才出現);「起始資料夾」。 +- Bot 設定 ›「電腦操作」:「讓這個 Bot 查看、修改檔案和執行指令」,勾了(或直接操作開著)才出現下面幾項;右側面板的「做事的電腦」只顯示,點了打開這裡:「做事的電腦」(旁邊寫「聊天時指名別台就會換」);「可以用的電腦」(有兩台以上才出現);「起始資料夾」。 - 設定 ›「電腦」›「你的電腦」:鉛筆改這台的名字、「在這台電腦上執行」、「其他電腦」展開看帳號裡的電腦和 SSH 電腦,填「SSH 電腦名稱,例如 工作站」和位址按「新增」,或「移除」,還有「讓帳號裡的其他電腦使用這台」。 - 設定 › 一般 ›「手機與帳號」:「大腦」那一欄選哪台當大腦(「改用它當大腦」),「加一台電腦」按「產生配對碼」([account](account.md))。 -- 側邊欄底部名字右邊的「↑」(「傳送檔案或文字到其他裝置」)。手機:首頁上面一排的「電腦」;聊天「⋯」›「對話詳細資訊」›「電腦」(做事的電腦、電腦清單);帳戶選單 ›「傳送到其他裝置」。 +- 側邊欄底部名字右邊的「↑」(「傳送檔案或文字到其他裝置」)。手機:首頁上面一排的「電腦」;聊天「⋯」›「對話詳細資訊」›「電腦」(做事的電腦——只顯示,點了到 Bot 設定改——和電腦清單);帳戶選單 ›「傳送到其他裝置」。 ## 怎麼操作(verify-anybot) @@ -32,7 +32,7 @@ - scratch 的大腦是 `--serve`(伺服器上的大腦),沒有 Docker、沒有登入帳號:Bot 只有它自己的電腦(封閉資料夾)。 - **你可以用哪些電腦**(covers `computers-kinds`、`computers-default`):問 Bot,點開那一步。指令:`$CTL phone send '你可以用哪些電腦 [[call list_computers {}]]' && $CTL phone click '.step.done .h' --text 查看電腦 && $CTL phone wait-text '使用者選的電腦:「驗證小幫手 的電腦」' --in '#msgs' && $CTL phone shot computers-list && $CTL api GET '/api/state?since=0' --jq '.bots[0].computers'`。看到:「「驗證小幫手 的電腦」:你自己的電腦(獨立資料夾 …/AnyBot 工作區/bot-1,看不到使用者的檔案;沒有螢幕),一律可用。」和「使用者選的電腦:「驗證小幫手 的電腦」」,沒有伺服器本身;API 只有一台 own。 -- **手機的做事的電腦**(covers `computers-default`、`computers-allowed`):聊天「⋯」›「對話詳細資訊」›「電腦」,點「預設在這台做事」選它;再看 Bot 設定。指令:`$CTL phone click '#b-chatmore' && $CTL phone click '#sheet-in .opt' --text 對話詳細資訊 && $CTL phone click '[data-tab="computer"]' && $CTL phone wait-text '離線 · 預設' --in '#details' && $CTL phone click '[data-d="pickcomp"]' && $CTL phone click '#sheet-in .opt' --text '驗證小幫手 的電腦' && $CTL phone wait-text '之後預設在「驗證小幫手 的電腦」做事' && $CTL phone click '#b-botset' && $CTL phone wait '[data-e="comp"]' && $CTL phone wait-gone '.gt' --text 可以用的電腦 && $CTL phone click '[data-back]' && $CTL phone click '[data-back]' && $CTL state '.bots[0] | {default_computer, computers}'`。看到:清單只有「驗證小幫手 的電腦 · 離線 · 預設」,選單只有它一台;Bot 設定有「做事的電腦」,沒有「可以用的電腦」(只有一台);state 記的是 Bot 自己的電腦。 +- **手機的做事的電腦**(covers `computers-default`、`computers-allowed`):聊天「⋯」›「對話詳細資訊」›「電腦」,點「預設在這台做事」到 Bot 設定,在「做事的電腦」選它。指令:`$CTL phone click '#b-chatmore' && $CTL phone click '#sheet-in .opt' --text 對話詳細資訊 && $CTL phone click '[data-tab="computer"]' && $CTL phone wait-text '離線 · 預設' --in '#details' && $CTL phone wait-text '在 Bot 設定裡改' --in '#details' && $CTL phone click '[data-d="botsetcomp"]' && $CTL phone click '[data-e="comp"]' && $CTL phone click '#sheet-in .opt' --text '驗證小幫手 的電腦' && $CTL phone wait-text '之後預設在「驗證小幫手 的電腦」做事' && $CTL phone wait-gone '.gt' --text 可以用的電腦 && $CTL phone click '[data-back]' && $CTL phone click '[data-back]' && $CTL state '.bots[0] | {default_computer, computers}'`。看到:清單只有「驗證小幫手 的電腦 · 離線 · 預設」,「預設在這台做事」下面寫「在 Bot 設定裡改」,點了到 Bot 設定;選單只有它一台;Bot 設定有「做事的電腦」,沒有「可以用的電腦」(只有一台);state 記的是 Bot 自己的電腦。 - **指名不存在的電腦**(covers `computers-default`):Bot 在「工作站」跑指令,再請它把做事的電腦改成工作站、你按允許。指令:`$CTL phone send '[[call shell {"command":"pwd","computer":"工作站"}]]' && $CTL phone wait-text '「工作站」現在連不到' --in '#msgs' && $CTL phone send '換電腦 [[call update_bot {"default_computer":"工作站"}]]' && $CTL phone wait-text '預設電腦 → 工作站' --in '#ask' && $CTL phone click '#ask button[data-a="once"]' && $CTL phone wait-text '沒有「工作站」這台電腦' --in '#msgs' && $CTL api GET /api/bots/1 --jq '[.messages[].tools[]? | .status]'`。看到:「「工作站」現在連不到…絕對不要自己換到清單上的別台做同一件事」,沒有在別台跑;卡片「修改 Bot 自己:預設電腦 → 工作站」,允許後「沒有「工作站」這台電腦。可以用:驗證小幫手 的電腦」;這兩步都是 failed。 - **傳到別的裝置**(covers `computers-send`):Bot 想傳到手機;你自己從帳戶選單打開「傳送到其他裝置」。指令:`$CTL phone send '[[call send_to_device {"path":"x.txt","to":"手機"}]]' && $CTL phone wait-text '這一輪沒有 send_to_device 這個工具' --in '#msgs' && $CTL phone click '[data-back]' && $CTL phone click '#b-me' && $CTL phone click '#sheet-in .opt' --text 傳送到其他裝置 && $CTL phone wait '#drop-say' && $CTL phone shot computers-drops && $CTL api GET /api/drop/targets`。看到:沒登入帳號,Bot 沒有 `send_to_device`;「傳送到其他裝置」打得開,能選的只有大腦「驗證用 AnyBot」(API 的 targets 是 this 和這支手機)。 - **在這台電腦上執行、SSH、加一台**(covers `computers-kinds`、`computers-local`、`computers-pair`):指令:要開視窗——`$CTL stop && ABV_ALLOW_WINDOW=1 $CTL desktop-shot computers ANYBOT_SHOT_REAL=1 ANYBOT_SHOT_VIEW=computers`;其餘走不到——每次詢問的卡片、永不允許要「這台電腦」(`--serve` 沒有),SSH 要一台真的 SSH 主機,帳號裡的電腦、配對碼要帳號伺服器。看到:設定 › 電腦「你的電腦」的名字、「在這台電腦上執行」選單和「其他電腦」;行為靠自動測試(關卡順序)。實機時:設成每次詢問,請 Bot 在這台跑 `pwd` 要跳允許卡片;改成永不允許要被擋下,並請它改用自己的電腦。 diff --git a/mobile/index.html b/mobile/index.html index 896ced1..39a5495 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -2767,7 +2767,8 @@ function tabBody(b, d) { const own = comps.find((c) => c.kind === "own"); let h = ""; if (own) h += `
${esc(own.name)} ${esc(S.boxOn ? S.box || "可以用" : "沒有 Docker")}
${S.boxOn ? `` : "沒有畫面"}
`; - h += group("做事的電腦", item({icon: "monitor", k: "預設在這台做事", r: b.computer || "", tap: 1, data: 'data-d="pickcomp"'})); + // Shown here, set in one place: Bot 設定 (the row goes there). + h += group("做事的電腦", item({icon: "monitor", k: "預設在這台做事", v: isOwner() ? "在 Bot 設定裡改" : "", r: b.computer || "", tap: isOwner() ? 1 : 0, data: isOwner() ? 'data-d="botsetcomp"' : ""})); h += group("電腦", comps.map((c) => { const k = {own: "cloud", this: "monitor", device: "laptop", ssh: "server"}[c.kind] || "monitor"; return item({icon: k, k: c.name, v: (c.online ? "在線上" : "離線") + (c.person ? " · 你正在用的" : "") + (c.name === b.computer ? " · 預設" : ""), tap: c.kind === "this" && S.mac ? 1 : 0, data: c.kind === "this" && S.mac ? 'data-d="mac"' : ""}); }).join("")); return h; } @@ -2792,7 +2793,7 @@ function wireDetails(b, d) { else if (k === "openbox") openBox(false); else if (k === "takeover") openBox(true); else if (k === "wake") act("box", {op: "wake"}, "正在喚醒…"); - else if (k === "pickcomp") pickComputer(b, d); + else if (k === "botsetcomp") go("botset", {bot: b.id}); else if (k === "mac") go("screen"); }); on("[data-forget]", async (x) => { if (await app("forget", {what: x.dataset.forget}, b.id)) renderDetails(b.id, S.tab); }); diff --git a/src/app.rs b/src/app.rs index 834f4f2..c1aa203 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2342,19 +2342,14 @@ impl App { (t.iter().map(|x| (x.name.clone(), mirror_ui::computer_kind(x, &r).to_string())).collect(), current) } - /// Choose the computer a bot works on (a screen sends it to the brain with its other edits). - pub(super) fn set_computer(&mut self, bot_id: u64, name: &str) { - if let Some(b) = self.state.bot_mut(bot_id) { - let keep = Self::computer_to_keep(b, name); - if b.default_computer != keep { - b.default_computer = keep; - self.mark(); - } - } - // Shown at once on a screen (the brain's answer follows). - if let Some(c) = self.mir.computers.get_mut(&bot_id) { - c["current"] = serde_json::json!(name); - } + /// Bot 設定 opened at one of its folding cards (`section`: its fold id, e.g. "computer"), open + /// and scrolled into view: where a setting shown elsewhere is changed. + pub(super) fn edit_bot_at(&mut self, ctx: &egui::Context, bot: &Bot, section: &'static str) { + ctx.data_mut(|d| { + d.insert_temp(egui::Id::unique(("fold", (section, bot.id))), true); + d.insert_temp(egui::Id::unique(("edit-jump", section, bot.id)), true); + }); + self.edit_bot = Some((bot.clone(), false)); } /// 查看電腦 and the instructions: each computer by its name, what it is, in plain words. @@ -6045,6 +6040,10 @@ impl App { }); }); setting_card(ui, p, |ui| { + // Opened from where this is only shown (the panel's 做事的電腦): come into view. + if ui.data_mut(|d| d.remove_temp::(egui::Id::unique(("edit-jump", "computer", b.id)))).unwrap_or(false) { + ui.scroll_to_cursor(Some(Align::TOP)); + } let summary = if b.tools_enabled { t("可以查看、修改檔案和執行指令") } else { t("關閉") }; if !fold_title(ui, p, ("computer", b.id), "電腦操作", &summary, "") { return; @@ -6053,7 +6052,7 @@ impl App { if self.direct_on() && !b.tools_enabled { note(ui, "「直接操作」開著:這個 Bot 現在照樣可以用電腦;關掉直接操作才照這裡。", p); } - if b.tools_enabled { + if b.tools_enabled || self.direct_on() { ui.add_space(6.0); form_row(ui, "做事的電腦", p, |ui| { let (choices, current) = self.computer_choices(&b); diff --git a/src/app/panel_ui.rs b/src/app/panel_ui.rs index 92dfc7b..7d019a1 100644 --- a/src/app/panel_ui.rs +++ b/src/app/panel_ui.rs @@ -183,9 +183,10 @@ impl App { let thumb = if available && !absent { self.box_thumbnail(ctx) } else { None }; let own_name = crate::model::own_computer_name(&bot.name); let brain_name = self.state.remote.brain_name.clone(); - // 做事的電腦: which computer this bot works on (its own unless the person picks another). + // 做事的電腦: which computer this bot works on (its own unless the person picks another) — + // shown here, set in one place: Bot 設定 › 電腦操作 (the name opens it there). let (choices, current) = if bot.members.is_empty() { self.computer_choices(bot) } else { (vec![], String::new()) }; - let mut pick: Option = None; + let mut change = false; panel_card(ui, p, |ui| { let run = crate::cloudbox::run_state(); let running = if brain { self.mir.box_state["running"].as_bool().unwrap_or(false) } else { run.is_running() }; @@ -233,26 +234,13 @@ impl App { let tip = if running { t("看「{name}」的螢幕,也可以取得控制權自己操作") } else { t("叫醒「{name}」並看它的螢幕") }.replace("{name}", &own_name); view = r.on_hover_cursor(egui::CursorIcon::PointingHand).on_hover_text(tip).clicked(); if !choices.is_empty() { - let shown = super::sidebar_ui::shorten_width(ui, ¤t, (ui.available_width() - 120.0).max(60.0), 13.0); - panel_select(ui, p, "做事的電腦", ("computer", bot.id), &shown, |ui| { - for (name, kind) in &choices { - let what = t(match kind.as_str() { - "own" => "它自己的電腦", - "person" => "你正在用的這台", - "this" => "這台電腦", - "server" => "大腦所在的伺服器", - "device" => "帳號裡的電腦", - _ => "SSH 電腦", - }); - if ui.selectable_label(*name == current, format!("{name} · {what}")).clicked() { - pick = Some(name.clone()); - } - } - }); + let tools = bot.tools_enabled || self.direct_on(); + let tip = if tools { t("在 Bot 設定 › 電腦操作 裡改") } else { t("這個 Bot 的電腦操作關著:用電腦前會先問你。在 Bot 設定 › 電腦操作 裡改") }; + change = panel_link_row(ui, p, "做事的電腦", ¤t).on_hover_text(tip).clicked(); } }); - if let Some(n) = pick { - self.set_computer(bot.id, &n); + if change { + self.edit_bot_at(ctx, bot, "computer"); } // 全部螢幕: every bot's own screen at once (when any is open). let open = if available { self.screen_tiles().len() } else { 0 }; @@ -560,6 +548,22 @@ fn panel_select(ui: &mut egui::Ui, p: Palette, label: &str, id: impl std::hash:: panel_select_with(ui, p, label, id, shown, egui::PopupCloseBehavior::CloseOnClick, menu); } +/// A row that shows a value set elsewhere: the label, and on the right the value with a › (the +/// whole row opens where it is set). +fn panel_link_row(ui: &mut egui::Ui, p: Palette, label: &str, value: &str) -> egui::Response { + let (rect, r) = ui.allocate_exact_size(vec2(ui.available_width(), ROW_H), egui::Sense::click()); + if r.hovered() { + ui.painter().rect_filled(rect, R_M, p.hover); + } + let label = ui.painter().text(rect.left_center() + vec2(10.0, 0.0), egui::Align2::LEFT_CENTER, t(label), egui::FontId::proportional(FONT_SM), p.text); + // The value takes what is left between the label and the ›. + let shown = super::sidebar_ui::shorten_width(ui, value, (rect.right() - 24.0 - 4.0 - label.right() - 8.0).max(40.0), FONT_SM); + let chev = egui::Rect::from_center_size(rect.right_center() - vec2(12.0, 0.0), vec2(11.0, 11.0)); + crate::icons::paint(ui.painter(), chev, crate::icons::Icon::ChevronRight, p.text3); + ui.painter().text(chev.left_center() - vec2(4.0, 0.0), egui::Align2::RIGHT_CENTER, shown, egui::FontId::proportional(FONT_SM), p.text2); + r.on_hover_cursor(egui::CursorIcon::PointingHand) +} + /// The same, choosing how its menu closes (one with a field in it stays open while typing). fn panel_select_with(ui: &mut egui::Ui, p: Palette, label: &str, id: impl std::hash::Hash + std::fmt::Debug, shown: &str, close: egui::PopupCloseBehavior, menu: impl FnOnce(&mut egui::Ui)) { ui.horizontal(|ui| {