@@ -0,0 +1,85 @@
1+//! Widget builds, bottom right: a pill per build in flight, and the agent's reply when one
2+//! finishes. A build on trial is live in the app until Keep merges it or Discard drops it; a
3+//! failed or parked build's reply goes once it's clicked away. The app draws this widget over
4+//! the whole window, so it fills the window and places its own parts.
5+use super::api::*;
6+use rune::{Color, El, col, row, text, tok};
7+use std::{collections::BTreeSet, path::PathBuf};
8+
9+pub const WIDGET: Widget = Widget { title: "Build status", size: (0.0, 0.0), new: |cx| Box::new(Status::load(cx)) };
10+
11+pub struct Status {
12+ /// When this widget first ran (replies older than that aren't news), and replies clicked away.
13+ born: u64,
14+ seen: BTreeSet<u64>,
15+ file: PathBuf,
16+}
17+
18+impl Status {
19+ fn load(cx: &Cx) -> Self {
20+ let file = cx.dir.join("seen");
21+ let saved = std::fs::read_to_string(&file).unwrap_or_else(|_| (now() as u64).to_string());
22+ let mut ids = saved.split_whitespace().filter_map(|w| w.parse().ok());
23+ let s = Status { born: ids.next().unwrap_or(0), seen: ids.collect(), file };
24+ s.save();
25+ s
26+ }
27+
28+ fn save(&self) {
29+ let ids: String = self.seen.iter().map(|i| format!(" {i}")).collect();
30+ let _ = std::fs::write(&self.file, format!("{}{ids}\n", self.born));
31+ }
32+}
33+
34+impl View for Status {
35+ fn view(&self, cx: &Cx) -> El {
36+ let t = tok::theme(true);
37+ let mut out = col().w_full().h_full().padding(12.0).gap(8.0).items_end().justify_end();
38+ if !cx.data.connected { out = out.child(text("conveyord isn't running").color(t.text_secondary)); }
39+ for b in cx.data.tickets.iter().filter(|b| b.project == "widgets") {
40+ out = match b.state.as_str() {
41+ "ready" | "running" => out.child(pill(b, cx.now as u64)),
42+ "review" => out.child(toast(b, cx)),
43+ "failed" | "parked" if b.since > self.born && !self.seen.contains(&(b.id as u64)) => out.child(toast(b, cx)),
44+ _ => out,
45+ };
46+ }
47+ out
48+ }
49+}
50+
51+fn pill(b: &Ticket, now: u64) -> El {
52+ let t = tok::theme(true);
53+ let secs = now.saturating_sub(b.since);
54+ row().key(format!("pill-{}", b.id)).h(28.0).px(10.0).gap(8.0).center_y().radius(14.0).fill(t.card)
55+ .child(text(format!("#{} {}", b.id, b.state)).font(tok::type_::LABEL).color(tok::accent(0, true)))
56+ .child(text(b.title.clone()).font(tok::type_::LABEL).color(t.text))
57+ .child(text(format!("{}:{:02}", secs / 60, secs % 60)).font(tok::type_::LABEL).color(t.text_secondary))
58+}
59+
60+fn toast(b: &Ticket, cx: &Cx) -> El {
61+ let t = tok::theme(true);
62+ let (id, trial, color) = (b.id, b.state == "review", tok::accent(1, true));
63+ let said = b.thread.iter().rev().find(|e| matches!(e.kind.as_str(), "reply" | "block" | "error")).map_or("", |e| &e.text);
64+ let head = text(format!("#{id} {} · {}", if trial { "on trial" } else { &b.state }, b.title))
65+ .font(tok::type_::LABEL).color(color).w_full().truncate();
66+ let toast = col().key(format!("toast-{id}")).w(380.0).radius(10.0).fill(t.card).padding(12.0).gap(4.0).border(1.0, color)
67+ .child(head).child(text(said.to_owned()).color(t.text).w_full().wrap());
68+ if trial {
69+ return toast.child(row().w_full().gap(8.0).center_y()
70+ .child(text("Try it, or Ctrl+click it to follow up").font(tok::type_::LABEL).color(t.text_secondary).grow(1.0))
71+ .child(decide(id, false, t.hover, t.text))
72+ .child(decide(id, true, tok::accent(0, true), t.bg)));
73+ }
74+ toast.role("button").label("Dismiss").hover(t.hover)
75+ .on_press_tx(on(cx.id, move |s: &mut Status, _| { s.seen.insert(id as u64); s.save(); }))
76+ .child(text("Ctrl+click the widget to follow up · click to dismiss").font(tok::type_::LABEL).color(t.text_secondary))
77+}
78+
79+/// Keep merges a build on trial into the library; Discard sends it back to draft.
80+fn decide(id: u32, keep: bool, fill: Color, ink: Color) -> El {
81+ let (key, label) = if keep { ("keep", "Keep") } else { ("discard", "Discard") };
82+ row().key(format!("{key}-{id}")).h(28.0).px(12.0).center_y().radius(6.0).fill(fill).role("button").label(label)
83+ .on_press_tx(move |h: &mut HostState, _| keep_build(h, id, keep))
84+ .child(text(label).font(tok::type_::LABEL).color(ink))
85+}