xonecas.ioDon't click! Sean Caetano Martin Sign in
cast / src / setup / view.rs 96 lines3.1 kB Raw
1use crate::app::App;
2use crate::app::chrome::shell;
3use crate::settings::view::{credentials, default_agent};
4use crate::setup::Row;
5use crate::ui::theme::{self, pal};
6use crate::ui::widgets::{Kind, bar, btn, lbl, mono, ph, tab};
7use crate::vm::bake::STAGES;
8use rune::{El, col, row, text};
9use rune_kit::Kit;
10
11pub fn view(s: &App, k: &Kit) -> El {
12    let p = pal();
13    let st = &s.setup;
14    let stages = col()
15        .gap(8.0)
16        .children(STAGES.iter().enumerate().map(|(i, label)| {
17            let pct = st.pct[i];
18            let active = st.row(i) == Row::Active;
19            let (glyph, color, right) = match st.row(i) {
20                Row::Done => ("✓", p.ok, "done".to_string()),
21                Row::Active => ("◐", p.accent, format!("{pct}%")),
22                Row::Failed => ("✕", p.danger, "failed".to_string()),
23                Row::Wait => ("○", p.muted, "wait".to_string()),
24            };
25            let head = row()
26                .gap(8.0)
27                .center_y()
28                .child(mono(glyph, color))
29                .child(text(*label).font(theme::BODY).color(p.fg).grow(1.0))
30                .child(mono(right, color));
31            let mut c = col().gap(4.0).child(head);
32            if active {
33                c = c
34                    .child(bar(pct as f32 / 100.0, p.accent))
35                    .child(mono(st.detail.clone(), p.muted).truncate());
36            }
37            c
38        }));
39    let mut body = col()
40        .padding(16.0)
41        .gap(12.0)
42        .child(stages)
43        .child(lbl("Agent credentials").mt(8.0))
44        .child(credentials(s, k))
45        .child(default_agent(s));
46    if let Some(e) = &st.error {
47        body = body.child(mono(format!("Bake failed: {e}"), p.danger).wrap());
48    }
49    let bake_label = if st.done { "Rebake" } else { "Bake VM" };
50    let actions = row()
51        .gap(8.0)
52        .justify_end()
53        .child(btn(
54            bake_label,
55            Kind::Normal,
56            (!st.running).then_some(|s: &mut App| s.bake()),
57        ))
58        .child(btn(
59            "Continue",
60            Kind::Primary,
61            (st.done && !st.running).then_some(|s: &mut App| s.finish_setup()),
62        ));
63    body = body.child(actions);
64    let step = format!(
65        "step {}/{}",
66        (st.stage() + 1).min(STAGES.len()),
67        STAGES.len()
68    );
69    let card = col()
70        .key("setup-card")
71        .w(680.0)
72        .fill(p.surface)
73        .radius(4.0)
74        .clip_rounded(4.0)
75        .child(ph(
76            lbl("First run · bake agent VM"),
77            lbl(&step).color(p.accent),
78        ))
79        .child(body);
80    let status = if st.running {
81        mono("● Baking debian cloud image", p.accent)
82    } else if st.done {
83        mono("● VM ready", p.ok)
84    } else {
85        mono("○ VM not baked", p.muted)
86    };
87    let main = col()
88        .grow(1.0)
89        .min_h(0.0)
90        .center()
91        .scroll(rune::ScrollSpec {
92            stick_bottom: false,
93        })
94        .child(col().w_full().items_center().py(24.0).child(card));
95    shell(vec![tab("Setup", true)], None, main, status)
96}