設定: 一般 and 整合 as drawn — white cards of rows, word-only pages, 整合 in three pages with the form behind a tile
- cards are white with a hairline edge; group titles small and grey; the page list is words only, the chosen page in ink - 聊天的顏色 is two dots (the bots' colours, black); switches are ink with a white knob - 整合 is three pages (訊息管道, 連接器, 技能) instead of one long scroll - 訊息管道: 已連接 lists each channel on a line (its mark, name · kind, who answers, how it stands, the switch, ⋯ to remove); 新增管道 is a grid of kinds, and a press opens that kind's form below (取消 closes it) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3QxSfoydRPM9mjj6d
This commit is contained in:
parent
f0b417f7cc
commit
675aad9d2a
79
src/app.rs
79
src/app.rs
|
|
@ -3684,9 +3684,9 @@ impl App {
|
||||||
ui.painter().rect_filled(rect, 10, if on { p.primary } else { p.hover });
|
ui.painter().rect_filled(rect, 10, if on { p.primary } else { p.hover });
|
||||||
}
|
}
|
||||||
let col = if on { p.on_primary } else { p.text };
|
let col = if on { p.on_primary } else { p.text };
|
||||||
crate::icons::paint(ui.painter(), egui::Rect::from_center_size(rect.left_center() + vec2(18.0, 0.0), vec2(16.0, 16.0)), icon, col);
|
let _ = icon;
|
||||||
let font = if on { egui::FontId::new(FONT_BASE, crate::bold()) } else { egui::FontId::proportional(FONT_BASE) };
|
let font = if on { egui::FontId::new(FONT_BASE, crate::bold()) } else { egui::FontId::proportional(FONT_BASE) };
|
||||||
ui.painter().text(rect.left_center() + vec2(36.0, 0.0), egui::Align2::LEFT_CENTER, t(name), font, col);
|
ui.painter().text(rect.left_center() + vec2(12.0, 0.0), egui::Align2::LEFT_CENTER, t(name), font, col);
|
||||||
// 更新: a newer build is waiting (the yellow that means 「需要你」).
|
// 更新: a newer build is waiting (the yellow that means 「需要你」).
|
||||||
if tab == SettingsTab::Updates && self.newer_build.is_some() && rect.width() > 110.0 {
|
if tab == SettingsTab::Updates && self.newer_build.is_some() && rect.width() > 110.0 {
|
||||||
ui.painter().circle_filled(rect.right_center() - vec2(14.0, 0.0), 5.0, p.attention);
|
ui.painter().circle_filled(rect.right_center() - vec2(14.0, 0.0), 5.0, p.attention);
|
||||||
|
|
@ -3713,10 +3713,30 @@ impl App {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
card_row(ui, p, "聊天的顏色", "", "跟著 Bot:你的訊息、送出鈕和選中的 Bot 用那隻 Bot 的顏色。只用黑色:都是黑的。", |ui| {
|
card_row(ui, p, "聊天的顏色", "", "跟著 Bot:你的訊息、送出鈕和選中的 Bot 用那隻 Bot 的顏色。只用黑色:都是黑的。", |ui| {
|
||||||
if let Some(a) = segmented(ui, p, self.state.accent, &[(Accent::BotColor, "跟著 Bot"), (Accent::Black, "只用黑色")]) {
|
// Two dots (from the right): black, and the bots' own colours.
|
||||||
|
for a in [Accent::Black, Accent::BotColor] {
|
||||||
|
let (rect, r) = ui.allocate_exact_size(vec2(30.0, 30.0), egui::Sense::click());
|
||||||
|
let c = rect.center();
|
||||||
|
if a == Accent::Black {
|
||||||
|
ui.painter().circle_filled(c, 11.0, p.primary);
|
||||||
|
} else {
|
||||||
|
// (A pie of four bot colours.)
|
||||||
|
for (k, name) in ["green", "purple", "blue", "brown"].iter().enumerate() {
|
||||||
|
let (a0, a1) = (k as f32 * std::f32::consts::FRAC_PI_2, (k + 1) as f32 * std::f32::consts::FRAC_PI_2);
|
||||||
|
let mut pts = vec![c];
|
||||||
|
pts.extend((0..=8).map(|j| { let a = a0 + (a1 - a0) * j as f32 / 8.0; c + vec2(a.cos(), a.sin()) * 11.0 }));
|
||||||
|
ui.painter().add(egui::Shape::convex_polygon(pts, avatar::color(name), Stroke::NONE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if self.state.accent == a {
|
||||||
|
ui.painter().circle_stroke(c, 14.0, Stroke::new(2.0, p.text));
|
||||||
|
}
|
||||||
|
if r.on_hover_text(t(if a == Accent::Black { "只用黑色" } else { "跟著 Bot" })).on_hover_cursor(egui::CursorIcon::PointingHand).clicked() && self.state.accent != a {
|
||||||
self.state.accent = a;
|
self.state.accent = a;
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ui.label(RichText::new(t(if self.state.accent == Accent::Black { "只用黑色" } else { "跟著 Bot" })).size(FONT_SM).color(p.text2));
|
||||||
});
|
});
|
||||||
card_row(ui, p, "字型", "", "思源黑體有粗體;粉圓體和系統字型只有一種粗細。", |ui| {
|
card_row(ui, p, "字型", "", "思源黑體有粗體;粉圓體和系統字型只有一種粗細。", |ui| {
|
||||||
let cur = crate::font_choice();
|
let cur = crate::font_choice();
|
||||||
|
|
@ -3903,10 +3923,14 @@ impl App {
|
||||||
self.remote_page(ui, ctx);
|
self.remote_page(ui, ctx);
|
||||||
}
|
}
|
||||||
SettingsTab::Channels => {
|
SettingsTab::Channels => {
|
||||||
section(ui, "訊息管道", p);
|
// Three pages instead of one long scroll.
|
||||||
self.channels_page(ui, ctx);
|
sub_tabs(ui, p, &mut self.ch.sub, &["訊息管道", "連接器", "技能"]);
|
||||||
section(ui, "連接器", p);
|
ui.add_space(12.0);
|
||||||
self.connectors_page(ui, ctx);
|
match self.ch.sub {
|
||||||
|
0 => self.channels_page(ui, ctx),
|
||||||
|
1 => self.connectors_page(ui, ctx, 1),
|
||||||
|
_ => self.connectors_page(ui, ctx, 2),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SettingsTab::Review => {
|
SettingsTab::Review => {
|
||||||
Frame::new().fill(p.accent.gamma_multiply(0.07)).stroke(Stroke::new(1.0, p.accent.gamma_multiply(0.45))).corner_radius(12).inner_margin(Margin::symmetric(16, 14)).show(ui, |ui| {
|
Frame::new().fill(p.accent.gamma_multiply(0.07)).stroke(Stroke::new(1.0, p.accent.gamma_multiply(0.45))).corner_radius(12).inner_margin(Margin::symmetric(16, 14)).show(ui, |ui| {
|
||||||
|
|
@ -5076,8 +5100,11 @@ fn pill_icon(ui: &mut egui::Ui, icon: crate::icons::Icon, p: Palette) -> egui::R
|
||||||
/// A group heading inside a settings page (like the original's section titles).
|
/// A group heading inside a settings page (like the original's section titles).
|
||||||
fn section(ui: &mut egui::Ui, title: &str, p: Palette) {
|
fn section(ui: &mut egui::Ui, title: &str, p: Palette) {
|
||||||
ui.add_space(16.0);
|
ui.add_space(16.0);
|
||||||
ui.label(RichText::new(t(title)).size(FONT_LG).family(crate::bold()).color(p.text));
|
ui.horizontal(|ui| {
|
||||||
ui.add_space(4.0);
|
ui.add_space(4.0);
|
||||||
|
ui.label(RichText::new(t(title)).size(FONT_XS).family(crate::bold()).color(p.text2));
|
||||||
|
});
|
||||||
|
ui.add_space(2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A small「?」after a setting's name. Its explanation shows as soon as the pointer is on it (no
|
/// A small「?」after a setting's name. Its explanation shows as soon as the pointer is on it (no
|
||||||
|
|
@ -5117,14 +5144,35 @@ fn help_mark(ui: &mut egui::Ui, text: &str, p: Palette) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// One setting: its name (with「?」for the explanation) on the left, its control on the right.
|
/// One setting: its name (with「?」for the explanation) on the left, its control on the right.
|
||||||
/// The quiet fill of a settings card.
|
/// The pages inside a settings page (設定 › 整合: 訊息管道, 連接器, 技能): words on a hairline, the
|
||||||
fn card_fill(p: Palette) -> Color32 {
|
/// chosen one bold with an ink line under it.
|
||||||
if p.pane.r() < 128 { Color32::from_rgb(0x1e, 0x1e, 0x1e) } else { Color32::from_rgb(0xf5, 0xf5, 0xf3) }
|
fn sub_tabs(ui: &mut egui::Ui, p: Palette, cur: &mut u8, names: &[&str]) {
|
||||||
|
let (bar, _) = ui.allocate_exact_size(vec2(ui.available_width(), 40.0), egui::Sense::hover());
|
||||||
|
ui.painter().hline(bar.x_range(), bar.bottom() - 0.5, Stroke::new(1.0, p.border));
|
||||||
|
let mut x = bar.left();
|
||||||
|
for (i, name) in names.iter().enumerate() {
|
||||||
|
let on = *cur as usize == i;
|
||||||
|
let font = if on { egui::FontId::new(FONT_BASE, crate::bold()) } else { egui::FontId::proportional(FONT_BASE) };
|
||||||
|
let galley = ui.painter().layout_no_wrap(t(name), font, if on { p.text } else { p.text2 });
|
||||||
|
let rect = egui::Rect::from_min_size(egui::pos2(x, bar.top()), vec2(galley.size().x + 24.0, bar.height()));
|
||||||
|
let r = ui.interact(rect, egui::Id::unique(("sub-tab", i)), egui::Sense::click());
|
||||||
|
if r.hovered() && !on {
|
||||||
|
ui.painter().rect_filled(rect.shrink2(vec2(0.0, 4.0)), 8, p.hover);
|
||||||
|
}
|
||||||
|
ui.painter().galley(egui::pos2(rect.left() + 12.0, rect.center().y - galley.size().y / 2.0), galley, p.text);
|
||||||
|
if on {
|
||||||
|
ui.painter().hline(rect.x_range(), bar.bottom() - 1.0, Stroke::new(2.0, p.text));
|
||||||
|
}
|
||||||
|
if r.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() {
|
||||||
|
*cur = i as u8;
|
||||||
|
}
|
||||||
|
x = rect.right() + 4.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A group of settings: one quiet card, its rows (`card_row`) divided by hairlines.
|
/// A group of settings: one quiet card, its rows (`card_row`) divided by hairlines.
|
||||||
fn rows_card(ui: &mut egui::Ui, p: Palette, rows: impl FnOnce(&mut egui::Ui)) {
|
fn rows_card(ui: &mut egui::Ui, p: Palette, rows: impl FnOnce(&mut egui::Ui)) {
|
||||||
Frame::new().fill(card_fill(p)).corner_radius(16).inner_margin(Margin::symmetric(16, 2)).show(ui, |ui| {
|
Frame::new().fill(p.elevated).stroke(Stroke::new(1.0, p.border)).corner_radius(14).inner_margin(Margin::symmetric(16, 1)).show(ui, |ui| {
|
||||||
ui.set_width(ui.available_width());
|
ui.set_width(ui.available_width());
|
||||||
ui.spacing_mut().item_spacing.y = 0.0;
|
ui.spacing_mut().item_spacing.y = 0.0;
|
||||||
rows(ui);
|
rows(ui);
|
||||||
|
|
@ -5185,7 +5233,7 @@ fn segmented<T: PartialEq + Copy>(ui: &mut egui::Ui, p: Palette, cur: T, options
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setting_row(ui: &mut egui::Ui, p: Palette, label: &str, desc: &str, control: impl FnOnce(&mut egui::Ui)) {
|
fn setting_row(ui: &mut egui::Ui, p: Palette, label: &str, desc: &str, control: impl FnOnce(&mut egui::Ui)) {
|
||||||
Frame::new().fill(card_fill(p)).corner_radius(14).inner_margin(Margin::symmetric(16, 12)).show(ui, |ui| {
|
Frame::new().fill(p.elevated).stroke(Stroke::new(1.0, p.border)).corner_radius(14).inner_margin(Margin::symmetric(16, 12)).show(ui, |ui| {
|
||||||
ui.set_width(ui.available_width());
|
ui.set_width(ui.available_width());
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let w = (ui.available_width() * 0.5).max(180.0);
|
let w = (ui.available_width() * 0.5).max(180.0);
|
||||||
|
|
@ -5219,8 +5267,9 @@ fn hint(ui: &mut egui::Ui, text: impl Into<String>, p: Palette) {
|
||||||
/// A rounded group of related settings, like a macOS settings card.
|
/// A rounded group of related settings, like a macOS settings card.
|
||||||
fn setting_card<R>(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui) -> R) -> R {
|
fn setting_card<R>(ui: &mut egui::Ui, p: Palette, body: impl FnOnce(&mut egui::Ui) -> R) -> R {
|
||||||
let r = Frame::new()
|
let r = Frame::new()
|
||||||
.fill(card_fill(p))
|
.fill(p.elevated)
|
||||||
.corner_radius(16)
|
.stroke(Stroke::new(1.0, p.border))
|
||||||
|
.corner_radius(14)
|
||||||
.inner_margin(Margin::symmetric(16, 14))
|
.inner_margin(Margin::symmetric(16, 14))
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.set_width(ui.available_width());
|
ui.set_width(ui.available_width());
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,10 @@ pub struct ChannelUi {
|
||||||
reg_q: String,
|
reg_q: String,
|
||||||
reg_busy: Arc<AtomicBool>,
|
reg_busy: Arc<AtomicBool>,
|
||||||
reg_found: Arc<Mutex<Option<RegistryAnswer>>>,
|
reg_found: Arc<Mutex<Option<RegistryAnswer>>>,
|
||||||
|
/// 設定 › 整合's page: 0 訊息管道, 1 連接器, 2 技能.
|
||||||
|
pub sub: u8,
|
||||||
|
/// The form for a new channel is open (a press on one of 新增管道's tiles).
|
||||||
|
adding: bool,
|
||||||
/// 連接器市集 was asked for (scroll it into view once).
|
/// 連接器市集 was asked for (scroll it into view once).
|
||||||
pub focus_market: bool,
|
pub focus_market: bool,
|
||||||
skill_src: String,
|
skill_src: String,
|
||||||
|
|
@ -54,7 +58,7 @@ impl Default for ChannelUi {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
let (trig_tx, trig_rx) = channel();
|
let (trig_tx, trig_rx) = channel();
|
||||||
ChannelUi { tx, rx, replies: HashMap::new(), waiting: VecDeque::new(), new_kind: Kind::Telegram, new_name: String::new(), new_token: String::new(), new_target: String::new(), new_bot: 0, note: Default::default(), started: false, trig_tx, trig_rx, trig_sig: String::new(), new_client: String::new(), new_tenant: String::new(), ms_login: Default::default(), mcp_sig: String::new(), mcp_errors: Default::default(), mcp_busy: Default::default(), new_mcp: Default::default(), focus_market: false, skill_src: String::new(), skill_open: None, skill_busy: Default::default(), skill_reload: Default::default(), skill_note: Default::default(), skill_note_list: false, new_mcp_hint: String::new(), focus_form: false, reg_q: String::new(), reg_busy: Default::default(), reg_found: Default::default() }
|
ChannelUi { tx, rx, replies: HashMap::new(), waiting: VecDeque::new(), new_kind: Kind::Telegram, new_name: String::new(), new_token: String::new(), new_target: String::new(), new_bot: 0, note: Default::default(), started: false, trig_tx, trig_rx, trig_sig: String::new(), new_client: String::new(), new_tenant: String::new(), ms_login: Default::default(), mcp_sig: String::new(), mcp_errors: Default::default(), mcp_busy: Default::default(), new_mcp: Default::default(), sub: 0, adding: false, focus_market: false, skill_src: String::new(), skill_open: None, skill_busy: Default::default(), skill_reload: Default::default(), skill_note: Default::default(), skill_note_list: false, new_mcp_hint: String::new(), focus_form: false, reg_q: String::new(), reg_busy: Default::default(), reg_found: Default::default() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,59 +183,115 @@ impl App {
|
||||||
|
|
||||||
pub(super) fn channels_page(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
|
pub(super) fn channels_page(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
|
||||||
let p = self.pal;
|
let p = self.pal;
|
||||||
setting_card(ui, p, |ui| {
|
// 已連接: what there is, each on a line — what it is, who answers, how it stands, on or off.
|
||||||
setting_title(ui, "訊息管道", "讓 Bot 在 Slack、Discord、Telegram、Microsoft Teams、Mac 的「訊息」或「郵件」回覆別人。收到訊息時 Bot 會像收到你的訊息一樣開始工作,做完後把回答傳回去(Slack 回在討論串,Discord 和 Telegram 引用原訊息)。AnyBot 開著時才會收訊息。", p);
|
ui.horizontal(|ui| {
|
||||||
hint(ui, "Microsoft Teams 用你自己的 Microsoft 帳號登入(裝置碼),不需要公開網址;Bot 會以你的身分在聊天或頻道裡回覆。", p);
|
ui.spacing_mut().item_spacing.x = 4.0;
|
||||||
|
ui.label(RichText::new(t("已連接")).size(FONT_XS).family(crate::bold()).color(p.text2));
|
||||||
|
help_mark(ui, "讓 Bot 在 Slack、Discord、Telegram、Microsoft Teams、Mac 的「訊息」或「郵件」回覆別人。收到訊息時 Bot 會像收到你的訊息一樣開始工作,做完後把回答傳回去(Slack 回在討論串,Discord 和 Telegram 引用原訊息)。AnyBot 開著時才會收訊息。", p);
|
||||||
});
|
});
|
||||||
|
ui.add_space(4.0);
|
||||||
let mut remove = None;
|
let mut remove = None;
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
let statuses = channels::statuses().lock().unwrap().clone();
|
let statuses = channels::statuses().lock().unwrap().clone();
|
||||||
let bots: Vec<(u64, String)> = self.state.bots.iter().map(|b| (b.id, b.name.clone())).collect();
|
let bots: Vec<(u64, String)> = self.state.bots.iter().map(|b| (b.id, b.name.clone())).collect();
|
||||||
for (i, c) in self.state.channels.iter_mut().enumerate() {
|
rows_card(ui, p, |ui| {
|
||||||
setting_card(ui, p, |ui| {
|
if self.state.channels.is_empty() {
|
||||||
ui.horizontal(|ui| {
|
ui.add_space(16.0);
|
||||||
ui.label(RichText::new(c.kind.label()).size(FONT_XS).color(p.text2));
|
ui.label(RichText::new(t("還沒有連接任何管道。從下面挑一個開始。")).size(FONT_BASE).color(p.text2));
|
||||||
ui.label(RichText::new(&c.name).strong().family(crate::bold()).size(FONT_BASE));
|
ui.add_space(16.0);
|
||||||
let st = statuses.get(&c.id);
|
|
||||||
let (col, text) = match st {
|
|
||||||
_ if !c.enabled => (p.text3, "已暫停".to_string()),
|
|
||||||
Some(s) if s.ok => (Color32::from_rgb(0x14, 0xc3, 0x70), format!("{}{}", s.note, if s.received > 0 { format!("(收到 {} 則)", s.received) } else { String::new() })),
|
|
||||||
Some(s) => (p.danger, s.note.clone()),
|
|
||||||
None => (p.text3, "連線中…".into()),
|
|
||||||
};
|
|
||||||
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), egui::Sense::hover());
|
|
||||||
ui.painter().circle_filled(r.center(), 4.0, col);
|
|
||||||
ui.add(egui::Label::new(RichText::new(text).size(11.5).color(p.text3)).truncate());
|
|
||||||
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
|
||||||
if ui.add(egui::Button::new(RichText::new(t("移除")).size(12.0).color(p.danger)).frame(false)).clicked() {
|
|
||||||
remove = Some(i);
|
|
||||||
}
|
}
|
||||||
if ui.checkbox(&mut c.enabled, t("開啟")).changed() {
|
for (i, c) in self.state.channels.iter_mut().enumerate() {
|
||||||
|
let top = ui.cursor().top();
|
||||||
|
if i > 0 {
|
||||||
|
ui.painter().hline(ui.max_rect().x_range(), top, Stroke::new(1.0, p.border));
|
||||||
|
}
|
||||||
|
let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), 64.0), egui::Sense::hover());
|
||||||
|
kind_tile(ui, egui::Rect::from_min_size(egui::pos2(rect.left(), rect.center().y - 18.0), vec2(36.0, 36.0)), c.kind, p);
|
||||||
|
// From the right: ⋯, the switch, how it stands.
|
||||||
|
let mut right = ui.new_child(egui::UiBuilder::new().max_rect(rect).layout(Layout::right_to_left(Align::Center)));
|
||||||
|
right.spacing_mut().item_spacing.x = 10.0;
|
||||||
|
let more = crate::icons::button(&mut right, crate::icons::Icon::More, 30.0, p.text2, p.hover).on_hover_text(t("更多"));
|
||||||
|
egui::Popup::menu(&more).show(|ui| {
|
||||||
|
ui.set_min_width(menu_ui::MENU_W);
|
||||||
|
if menu_ui::danger(ui, p, crate::icons::Icon::Trash, "移除這個管道").clicked() {
|
||||||
|
remove = Some(i);
|
||||||
|
ui.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if right.add(computers_ui::toggle(&mut c.enabled)).changed() {
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
});
|
let (col, text) = match statuses.get(&c.id) {
|
||||||
});
|
_ if !c.enabled => (p.text3, t("已暫停")),
|
||||||
let bot = bots.iter().find(|b| b.0 == c.bot_id).map(|b| b.1.clone()).unwrap_or_else(|| "(Bot 已刪除)".into());
|
Some(s) if s.ok => (Color32::from_rgb(0x0b, 0x7f, 0x48), if s.received > 0 { format!("{}(收到 {} 則)", s.note, s.received) } else { s.note.clone() }),
|
||||||
hint(ui, format!("由「{bot}」回覆 · {}", if c.target.is_empty() { "任何聊天".to_string() } else { c.target.clone() }), p);
|
Some(s) => (p.danger, s.note.clone()),
|
||||||
});
|
None => (p.text3, t("連線中…")),
|
||||||
|
};
|
||||||
|
let room = (right.available_width() - 36.0 - 150.0).clamp(60.0, 200.0);
|
||||||
|
right.label(RichText::new(sidebar_ui::shorten_width(&right, &text, room, 12.0)).size(12.0).color(if col == p.text3 { p.text2 } else { col }));
|
||||||
|
let (dot, _) = right.allocate_exact_size(vec2(8.0, 8.0), egui::Sense::hover());
|
||||||
|
right.painter().circle_filled(dot.center(), 4.0, col);
|
||||||
|
// The words, in the room that is left.
|
||||||
|
let words = egui::Rect::from_min_max(egui::pos2(rect.left() + 48.0, rect.top()), egui::pos2((right.min_rect().left() - 10.0).max(rect.left() + 120.0), rect.bottom()));
|
||||||
|
let mut left = ui.new_child(egui::UiBuilder::new().max_rect(words).layout(Layout::top_down(Align::Min)));
|
||||||
|
left.spacing_mut().item_spacing.y = 1.0;
|
||||||
|
left.add_space(12.0);
|
||||||
|
left.add(egui::Label::new(RichText::new(format!("{} · {}", c.name, c.kind.label())).size(FONT_LG).color(p.text)).truncate());
|
||||||
|
let bot = bots.iter().find(|b| b.0 == c.bot_id).map(|b| b.1.clone()).unwrap_or_else(|| t("(Bot 已刪除)"));
|
||||||
|
let whom = if c.target.is_empty() { t("{bot} 回覆").replace("{bot}", &bot) } else { format!("{} · {}", t("{bot} 回覆").replace("{bot}", &bot), c.target) };
|
||||||
|
left.add(egui::Label::new(RichText::new(whom).size(12.5).color(p.text2)).truncate());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
if let Some(i) = remove {
|
if let Some(i) = remove {
|
||||||
self.state.channels.remove(i);
|
self.state.channels.remove(i);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
// ── 新增 ──
|
// 新增管道: the kinds as tiles; a press opens that kind's form below.
|
||||||
setting_card(ui, p, |ui| {
|
ui.add_space(14.0);
|
||||||
setting_title(ui, "新增管道", "", p);
|
ui.label(RichText::new(t("新增管道")).size(FONT_XS).family(crate::bold()).color(p.text2));
|
||||||
// Wraps onto a second line in a narrow window instead of widening the dialog.
|
ui.add_space(4.0);
|
||||||
ui.horizontal_wrapped(|ui| {
|
let kinds = [Kind::Telegram, Kind::Slack, Kind::Discord, Kind::Teams, Kind::IMessage, Kind::Email, Kind::Sms, Kind::X];
|
||||||
for k in [Kind::Telegram, Kind::Slack, Kind::Discord, Kind::Teams, Kind::IMessage, Kind::Email, Kind::Sms, Kind::X] {
|
let cols = if ui.available_width() < 470.0 { 2 } else { 4 };
|
||||||
if ui.selectable_label(self.ch.new_kind == k, k.label()).clicked() && self.ch.new_kind != k {
|
let (gap, w) = (10.0, (ui.available_width() - 10.0 * (cols as f32 - 1.0)) / cols as f32);
|
||||||
self.ch.new_kind = k;
|
for row in kinds.chunks(cols) {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.spacing_mut().item_spacing.x = gap;
|
||||||
|
for k in row {
|
||||||
|
let (rect, r) = ui.allocate_exact_size(vec2(w, 56.0), egui::Sense::click());
|
||||||
|
let on = self.ch.adding && self.ch.new_kind == *k;
|
||||||
|
ui.painter().rect_filled(rect, 14, if r.hovered() { p.hover } else { p.elevated });
|
||||||
|
ui.painter().rect_stroke(rect, 14, if on { Stroke::new(2.0, p.text) } else { Stroke::new(1.0, p.border) }, egui::StrokeKind::Inside);
|
||||||
|
kind_tile(ui, egui::Rect::from_min_size(egui::pos2(rect.left() + 12.0, rect.center().y - 16.0), vec2(32.0, 32.0)), *k, p);
|
||||||
|
let name = sidebar_ui::shorten_width(ui, k.label(), w - 62.0, FONT_BASE);
|
||||||
|
ui.painter().text(egui::pos2(rect.left() + 54.0, rect.center().y), egui::Align2::LEFT_CENTER, name, egui::FontId::proportional(FONT_BASE), p.text);
|
||||||
|
if r.on_hover_cursor(egui::CursorIcon::PointingHand).clicked() {
|
||||||
|
if self.ch.new_kind != *k {
|
||||||
self.ch.new_token.clear();
|
self.ch.new_token.clear();
|
||||||
self.ch.new_target.clear();
|
self.ch.new_target.clear();
|
||||||
}
|
}
|
||||||
|
self.ch.adding = !on;
|
||||||
|
self.ch.new_kind = *k;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ui.add_space(gap - 6.0);
|
||||||
|
}
|
||||||
|
if !self.ch.adding {
|
||||||
|
hint(ui, "點一個,才打開它的表單(名稱、回覆的 Bot、Token)。", p);
|
||||||
|
}
|
||||||
|
let mut added = false;
|
||||||
|
if self.ch.adding {
|
||||||
|
ui.add_space(6.0);
|
||||||
|
setting_card(ui, p, |ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label(RichText::new(format!("{} {}", t("新增"), self.ch.new_kind.label())).size(FONT_LG).family(crate::bold()).color(p.text));
|
||||||
|
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
|
||||||
|
if small_button(ui, "取消", p).clicked() {
|
||||||
|
added = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ui.add_space(4.0);
|
||||||
let k = self.ch.new_kind;
|
let k = self.ch.new_kind;
|
||||||
if self.ch.new_bot == 0 || !bots.iter().any(|b| b.0 == self.ch.new_bot) {
|
if self.ch.new_bot == 0 || !bots.iter().any(|b| b.0 == self.ch.new_bot) {
|
||||||
self.ch.new_bot = self.state.selected;
|
self.ch.new_bot = self.state.selected;
|
||||||
|
|
@ -325,6 +385,7 @@ impl App {
|
||||||
self.ch.new_token.clear();
|
self.ch.new_token.clear();
|
||||||
self.ch.new_target.clear();
|
self.ch.new_target.clear();
|
||||||
changed = true;
|
changed = true;
|
||||||
|
added = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let note = self.ch.note.lock().unwrap().clone();
|
let note = self.ch.note.lock().unwrap().clone();
|
||||||
|
|
@ -332,6 +393,10 @@ impl App {
|
||||||
ui.label(RichText::new(note).size(FONT_XS).color(p.text2));
|
ui.label(RichText::new(note).size(FONT_XS).color(p.text2));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
if added {
|
||||||
|
self.ch.adding = false;
|
||||||
|
}
|
||||||
if changed {
|
if changed {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
self.channels_restart(ctx);
|
self.channels_restart(ctx);
|
||||||
|
|
@ -359,9 +424,11 @@ impl App {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn connectors_page(&mut self, ui: &mut egui::Ui, ctx: &egui::Context) {
|
/// 連接器 (`part` 1: the servers, their tools, the markets, the form) and 技能 (`part` 2).
|
||||||
|
pub(super) fn connectors_page(&mut self, ui: &mut egui::Ui, ctx: &egui::Context, part: u8) {
|
||||||
let p = self.pal;
|
let p = self.pal;
|
||||||
let before = serde_json::to_string(&self.state.mcp_servers).unwrap_or_default();
|
let before = serde_json::to_string(&self.state.mcp_servers).unwrap_or_default();
|
||||||
|
if part == 1 {
|
||||||
setting_card(ui, p, |ui| {
|
setting_card(ui, p, |ui| {
|
||||||
setting_title(ui, "連接器(MCP)", "接上 Model Context Protocol 伺服器,Bot 就能用它的工具(例如 GitHub、Notion、資料庫、你公司的內部系統)。每個連接器第一次被使用時會先問你。", p);
|
setting_title(ui, "連接器(MCP)", "接上 Model Context Protocol 伺服器,Bot 就能用它的工具(例如 GitHub、Notion、資料庫、你公司的內部系統)。每個連接器第一次被使用時會先問你。", p);
|
||||||
hint(ui, "本機伺服器填指令(例如 npx -y @modelcontextprotocol/server-filesystem ~/Documents);遠端伺服器填網址(Streamable HTTP),需要時加上 Authorization 標頭。", p);
|
hint(ui, "本機伺服器填指令(例如 npx -y @modelcontextprotocol/server-filesystem ~/Documents);遠端伺服器填網址(Streamable HTTP),需要時加上 Authorization 標頭。", p);
|
||||||
|
|
@ -413,6 +480,7 @@ impl App {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// A finished install: this computer's skill folder joins the list. (Not on a screen: its
|
// A finished install: this computer's skill folder joins the list. (Not on a screen: its
|
||||||
// list is the brain's, and the brain installs there itself.)
|
// list is the brain's, and the brain installs there itself.)
|
||||||
if self.ch.skill_reload.swap(false, Ordering::SeqCst) && !self.mir.on {
|
if self.ch.skill_reload.swap(false, Ordering::SeqCst) && !self.mir.on {
|
||||||
|
|
@ -421,6 +489,7 @@ impl App {
|
||||||
}
|
}
|
||||||
let skill_busy = self.ch.skill_busy.load(Ordering::SeqCst);
|
let skill_busy = self.ch.skill_busy.load(Ordering::SeqCst);
|
||||||
|
|
||||||
|
if part == 2 {
|
||||||
setting_card(ui, p, |ui| {
|
setting_card(ui, p, |ui| {
|
||||||
setting_title(ui, "技能", "所有 Bot 共用的專業指南與標準作業流程(相容 Agent Skills SKILL.md 規格,支援隨附 scripts/ 與 references/)。開啟的技能會列在 Bot 的目錄中,需要時自動載入。", p);
|
setting_title(ui, "技能", "所有 Bot 共用的專業指南與標準作業流程(相容 Agent Skills SKILL.md 規格,支援隨附 scripts/ 與 references/)。開啟的技能會列在 Bot 的目錄中,需要時自動載入。", p);
|
||||||
if self.state.skills.is_empty() {
|
if self.state.skills.is_empty() {
|
||||||
|
|
@ -579,6 +648,8 @@ impl App {
|
||||||
skill_status(ui, &self.ch, skill_busy, p);
|
skill_status(ui, &self.ch, skill_busy, p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
if part == 1 {
|
||||||
// 外掛市集: common connectors, one click away (ones needing a key fill the form below).
|
// 外掛市集: common connectors, one click away (ones needing a key fill the form below).
|
||||||
setting_card(ui, p, |ui| {
|
setting_card(ui, p, |ui| {
|
||||||
if std::mem::take(&mut self.ch.focus_market) {
|
if std::mem::take(&mut self.ch.focus_market) {
|
||||||
|
|
@ -657,6 +728,7 @@ impl App {
|
||||||
self.ch.new_mcp_hint.clear();
|
self.ch.new_mcp_hint.clear();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
let _ = ctx;
|
let _ = ctx;
|
||||||
if serde_json::to_string(&self.state.mcp_servers).unwrap_or_default() != before {
|
if serde_json::to_string(&self.state.mcp_servers).unwrap_or_default() != before {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
|
|
@ -787,6 +859,25 @@ fn skill_status(ui: &mut egui::Ui, ch: &ChannelUi, busy: bool, p: Palette) {
|
||||||
/// What a 公用市集 search found (rows as `mcp::registry_entries` gives them), or why it failed.
|
/// What a 公用市集 search found (rows as `mcp::registry_entries` gives them), or why it failed.
|
||||||
type RegistryAnswer = Result<Vec<serde_json::Value>, String>;
|
type RegistryAnswer = Result<Vec<serde_json::Value>, String>;
|
||||||
|
|
||||||
|
/// A channel kind's mark: its first letter on a quiet tint of its own (no logos).
|
||||||
|
fn kind_tile(ui: &egui::Ui, rect: egui::Rect, k: Kind, p: Palette) {
|
||||||
|
let (letter, rgb): (&str, [u8; 3]) = match k {
|
||||||
|
Kind::Telegram => ("T", [0x0f, 0x4c, 0x8a]),
|
||||||
|
Kind::Slack => ("S", [0x5b, 0x2a, 0x86]),
|
||||||
|
Kind::Discord => ("D", [0x3a, 0x3f, 0x9e]),
|
||||||
|
Kind::Teams => ("M", [0x43, 0x38, 0xa8]),
|
||||||
|
Kind::IMessage => ("訊", [0x0b, 0x6b, 0x3d]),
|
||||||
|
Kind::Email => ("郵", [0x9a, 0x34, 0x12]),
|
||||||
|
Kind::Sms => ("簡", [0xa1, 0x1d, 0x2b]),
|
||||||
|
Kind::X => ("X", [0x1c, 0x1c, 0x1c]),
|
||||||
|
};
|
||||||
|
let ink = Color32::from_rgb(rgb[0], rgb[1], rgb[2]);
|
||||||
|
let dark = p.pane.r() < 128;
|
||||||
|
ui.painter().rect_filled(rect, 10, crate::theme::mist(ink, Palette { pane: if dark { Color32::from_rgb(0x30, 0x30, 0x30) } else { Color32::WHITE }, ..p }).gamma_multiply(1.0));
|
||||||
|
let col = if dark { Color32::from_rgb(0xf0, 0xf0, 0xf0) } else { ink };
|
||||||
|
ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, letter, egui::FontId::new(15.0, crate::bold()), col);
|
||||||
|
}
|
||||||
|
|
||||||
/// One line of a list: its buttons on the right (`buttons` adds them rightmost first), and the
|
/// One line of a list: its buttons on the right (`buttons` adds them rightmost first), and the
|
||||||
/// words on the left in the room that is left — a long description ends in … before the
|
/// words on the left in the room that is left — a long description ends in … before the
|
||||||
/// buttons instead of running under them.
|
/// buttons instead of running under them.
|
||||||
|
|
|
||||||
|
|
@ -1257,12 +1257,15 @@ pub(super) fn toggle(on: &mut bool) -> impl egui::Widget + '_ {
|
||||||
r.mark_changed();
|
r.mark_changed();
|
||||||
}
|
}
|
||||||
let t = ui.ctx().animate_bool_responsive(r.id, *on);
|
let t = ui.ctx().animate_bool_responsive(r.id, *on);
|
||||||
let off_col = ui.visuals().widgets.inactive.bg_fill;
|
// On is ink with a white knob; off is the quiet grey.
|
||||||
let on_col = ui.visuals().selection.bg_fill;
|
let dark = ui.visuals().dark_mode;
|
||||||
|
let off_col = if dark { Color32::from_gray(0x4a) } else { Color32::from_gray(0xd4) };
|
||||||
|
let on_col = if dark { Color32::from_gray(0xf5) } else { Color32::from_gray(0x1c) };
|
||||||
let fill = if ui.is_enabled() { egui::lerp(egui::Rgba::from(off_col)..=egui::Rgba::from(on_col), t).into() } else { off_col.gamma_multiply(0.6) };
|
let fill = if ui.is_enabled() { egui::lerp(egui::Rgba::from(off_col)..=egui::Rgba::from(on_col), t).into() } else { off_col.gamma_multiply(0.6) };
|
||||||
ui.painter().rect_filled(rect, 10, fill);
|
ui.painter().rect_filled(rect, 10, fill);
|
||||||
let x = egui::lerp((rect.left() + 10.0)..=(rect.right() - 10.0), t);
|
let x = egui::lerp((rect.left() + 10.0)..=(rect.right() - 10.0), t);
|
||||||
ui.painter().circle_filled(egui::pos2(x, rect.center().y), 8.0, Color32::WHITE);
|
let knob = if dark && *on { Color32::from_gray(0x1c) } else { Color32::WHITE };
|
||||||
|
ui.painter().circle_filled(egui::pos2(x, rect.center().y), 8.0, knob);
|
||||||
r.on_hover_cursor(egui::CursorIcon::PointingHand)
|
r.on_hover_cursor(egui::CursorIcon::PointingHand)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,7 @@ impl App {
|
||||||
self.show_settings = true;
|
self.show_settings = true;
|
||||||
self.settings_tab = SettingsTab::Channels;
|
self.settings_tab = SettingsTab::Channels;
|
||||||
self.ch.focus_market = true;
|
self.ch.focus_market = true;
|
||||||
|
self.ch.sub = 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// A newer build is in place: one row across the sidebar, never wider — with the
|
// A newer build is in place: one row across the sidebar, never wider — with the
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue