hex/src/rune_ui/sidebar_update.rs

113 lines
3.3 KiB
Rust

//! The sidebar's update: Restart to update, Download update, or a channel
//! switch, and under Restart to update what the staged dev build changed.
use super::sidebar::FOOTER_LINE;
use super::*;
const SHOWN: usize = 3;
/// An available update, as a secondary button with a dot.
pub(super) fn control(ui: &Ui, p: Paint) -> Option<El> {
let offer = crate::updater::offer(&ui.view.as_ref()?.update_status)?;
let action = offer.action;
// An available update is a state, not the screen's main action.
Some(
row()
.key("sidebar-update-control")
.gap(8.0)
.pl(6.0)
.center_y()
.child(controls::status_dot(p.accent()))
.child(controls::button(
p,
"sidebar-update",
&offer.label,
controls::ButtonKind::Secondary,
move |ui: &mut Ui, _| ui.send(Request::Desktop(action.clone())),
)),
)
}
/// Under Download update on Windows, why this Hex can't update itself and
/// what to do (#1352).
pub(super) fn blocked(ui: &Ui, p: Paint) -> Option<El> {
let view = ui.view.as_ref()?;
let why = view
.update_blocked
.filter(|_| view.update_status == DesktopUpdateStatus::Available)?;
Some(
text(tr(why))
.key("sidebar-update-blocked")
.font(p.k.ty.small)
.color(p.faint())
.wrap()
.mt(6.0)
.px(6.0),
)
}
/// What the staged dev build changed, while Restart to update shows.
pub(super) fn notes(ui: &Ui, p: Paint) -> Option<El> {
ui.view
.as_ref()
.filter(|view| view.update_status == DesktopUpdateStatus::ReadyToRestart)
.and_then(|view| view.update_notes.as_ref())
.and_then(|notes| list(p, notes))
}
/// The first few changes and the release notes for this staged build.
fn list(p: Paint, notes: &crate::desktop::host::UpdateNotes) -> Option<El> {
if notes.items.is_empty() {
return None;
}
let c = &p.k.c;
let url = notes.url.clone();
let link = row()
.key("whats-new")
.h(FOOTER_LINE)
.px(6.0)
.center_y()
.self_start()
.radius(p.k.radius.sm)
.role("link")
.label(tr("Release notes"))
.hover(c.hover)
.press(c.pressed)
.focusable(true)
.focus_ring(2.0, -2.0, c.border_focus)
.on_press(move |ui: &mut Ui| {
if ui.live()
&& let Err(error) = crate::desktop::opencode_catalog::open_url(&url)
{
ui.error = Some(format!("{error:#}"));
}
})
.child(
text(tr("Release notes"))
.key("label")
.font(p.k.ty.small)
.color(c.text_muted)
.truncate(),
);
let items = notes
.items
.iter()
.take(SHOWN)
.enumerate()
.map(|(index, item)| {
text(format!("· {item}"))
.key(format!("item{index}"))
.font(p.k.ty.small)
.color(p.faint())
.truncate()
.px(6.0)
});
Some(
col()
.key("sidebar-update-notes")
.mt(6.0)
.gap(2.0)
.child(link)
.children(items),
)
}