feat(update): show release notes + version-card layout in update notice

The update notice dialog now mirrors what GitHub publishes: side-by-side
Installed → Latest version cards (the new one accent-tinted to draw the
eye) and a scrollable release-notes panel under them. Light markdown
rendering covers `##` headings, bullet lists, and inline bold/code
markers — enough for the GitHub release body format we ship.

- update_check::check_for_update() returns UpdateInfo { version, body };
  body is parsed from the releases API JSON with a tiny custom
  string-field extractor (\n / \" / \u handling) so we keep the
  serde_json-free dependency footprint.
- Window grows from 480x240 to 560x460 and becomes resizable to make
  room for the notes scroller.
- Layout tightens: header bottom padding drops 14 → 6, notes heading
  10, and the notes block is wrapped in a Fill-height container so it
  claims every leftover pixel — no more dead space between heading and
  footer.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Hakan 2026-05-22 12:55:37 +03:00
commit 2357b39a1d
5 changed files with 255 additions and 53 deletions

View file

@ -1,5 +1,5 @@
use crate::app::Message;
use iced::widget::{button, column, container, row, text, Space};
use iced::widget::{button, column, container, row, scrollable, text, Space};
use iced::{Background, Border, Color, Element, Fill, Theme};
const BG: Color = Color {
@ -39,18 +39,104 @@ const WHITE: Color = Color {
a: 1.0,
};
fn info_row<'a>(label: &'static str, value: String) -> Element<'a, Message> {
row![
text(label).size(11).color(DIM).width(100),
text(value).size(11).color(WHITE),
]
.spacing(8)
.align_y(iced::Center)
.padding([3, 0])
/// Renders one of the two "Installed" / "Latest" cards. The `highlight`
/// flag tints the border + label with the accent colour, making the new
/// version the visual anchor of the row.
fn version_card<'a>(label: &'static str, value: String, highlight: bool) -> Element<'a, Message> {
let label_color = if highlight { ACCENT } else { DIM };
let value_color = WHITE;
let border_color = if highlight { ACCENT } else { BORDER };
let bg = if highlight {
Color { r: 0.10, g: 0.16, b: 0.22, a: 1.0 } // accent-tinted dark
} else {
PANEL
};
container(
column![
text(label).size(10).color(label_color),
text(value).size(20).color(value_color),
]
.spacing(4)
.align_x(iced::Center),
)
.width(Fill)
.padding(iced::Padding {
top: 14.0,
right: 12.0,
bottom: 14.0,
left: 12.0,
})
.align_x(iced::Center)
.style(move |_: &Theme| container::Style {
background: Some(Background::Color(bg)),
border: Border {
color: border_color,
width: 1.0,
radius: 6.0.into(),
},
..Default::default()
})
.into()
}
pub fn view_window<'a>(latest: &'a str) -> Element<'a, Message> {
/// Light-weight renderer for a single line of GitHub-style release-notes
/// markdown. Recognises:
/// * `## Heading` → bold accent line
/// * `### Heading` → smaller bold line
/// * `- bullet` → indented bullet text
/// * `**bold**` runs and `` `code` `` runs (rendered tonally, not styled
/// differently — iced's text widget has no inline run styling).
/// Anything else is plain body text. Strips the markdown markers so the
/// dialog reads cleanly even if the user has a Patreon-formatted note.
fn render_notes_line<'a>(raw: &str) -> Element<'a, Message> {
let trimmed = raw.trim_end();
if trimmed.is_empty() {
return Space::new()
.height(iced::Length::Fixed(6.0))
.into();
}
if let Some(rest) = trimmed.strip_prefix("## ") {
return text(strip_inline_md(rest))
.size(13)
.color(ACCENT)
.into();
}
if let Some(rest) = trimmed.strip_prefix("### ") {
return text(strip_inline_md(rest))
.size(12)
.color(WHITE)
.into();
}
if let Some(rest) = trimmed.strip_prefix("- ").or_else(|| trimmed.strip_prefix("* ")) {
return row![
text("•").size(11).color(DIM).width(14),
text(strip_inline_md(rest)).size(11).color(WHITE),
]
.spacing(4)
.into();
}
text(strip_inline_md(trimmed)).size(11).color(WHITE).into()
}
/// Drop `**…**` and `` `…` `` markers without preserving emphasis (iced 0.14
/// Text widgets style the whole string uniformly). Keeps the inner text.
fn strip_inline_md(s: &str) -> String {
let mut out = String::with_capacity(s.len());
let mut chars = s.chars().peekable();
while let Some(c) = chars.next() {
if c == '*' && chars.peek() == Some(&'*') {
chars.next();
continue;
}
if c == '`' {
continue;
}
out.push(c);
}
out
}
pub fn view_window<'a>(latest: &'a str, body: &'a str) -> Element<'a, Message> {
let header = container(
column![
text("New Release Available").size(20).color(ACCENT),
@ -63,31 +149,31 @@ pub fn view_window<'a>(latest: &'a str) -> Element<'a, Message> {
)
.width(Fill)
.padding(iced::Padding {
top: 16.0,
top: 14.0,
right: 0.0,
bottom: 14.0,
bottom: 6.0,
left: 0.0,
})
.align_x(iced::Center);
let info_block = container(
column![
info_row("Installed", format!("v{}", env!("CARGO_PKG_VERSION"))),
info_row("Latest", format!("v{}", latest)),
]
.spacing(2)
.padding([12, 16]),
)
.width(Fill)
.style(|_: &Theme| container::Style {
background: Some(Background::Color(PANEL)),
border: Border {
color: BORDER,
width: 1.0,
radius: 4.0.into(),
},
..Default::default()
});
// Two side-by-side version cards (Installed → Latest) with the latest
// one accent-tinted to draw the eye. Replaces the previous label/value
// row layout. The arrow between them is purely decorative.
let installed = version_card(
"Installed",
format!("v{}", env!("CARGO_PKG_VERSION")),
false,
);
let latest_card = version_card("Latest", format!("v{}", latest), true);
let arrow = container(text("→").size(22).color(DIM))
.width(iced::Length::Fixed(32.0))
.height(Fill)
.align_x(iced::Center)
.align_y(iced::Center);
let info_block = row![installed, arrow, latest_card]
.spacing(0)
.align_y(iced::Center)
.width(Fill);
let later_btn = button(text("Later").size(11))
.on_press(Message::UpdateNoticeClose)
@ -147,9 +233,56 @@ pub fn view_window<'a>(latest: &'a str) -> Element<'a, Message> {
left: 0.0,
});
// Release notes panel. Rendered as a light-markdown column inside a
// bordered scrollable so long bodies stay contained and don't
// explode the window. Empty body → "No release notes provided."
let notes_heading = container(text("What's new").size(11).color(DIM))
.padding(iced::Padding {
top: 10.0,
right: 0.0,
bottom: 4.0,
left: 0.0,
});
let notes_body: Element<'a, Message> = if body.trim().is_empty() {
text("No release notes provided.")
.size(11)
.color(DIM)
.into()
} else {
let mut col = column![].spacing(4);
for line in body.lines() {
col = col.push(render_notes_line(line));
}
scrollable(container(col).padding([10, 14])).height(Fill).into()
};
let notes_block = container(notes_body)
.width(Fill)
.height(Fill)
.style(|_: &Theme| container::Style {
background: Some(Background::Color(PANEL)),
border: Border {
color: BORDER,
width: 1.0,
radius: 4.0.into(),
},
..Default::default()
});
// Wrap notes_block in a Fill-height container outside the column so it
// greedily claims every pixel left over after the fixed-height rows
// (header, version cards, heading, footer). Without this iced lets the
// notes panel shrink to its content height, leaving a gap above the
// footer.
let notes_fill = container(notes_block)
.width(Fill)
.height(Fill);
container(
column![header, info_block, footer]
column![header, info_block, notes_heading, notes_fill, footer]
.spacing(0)
.height(Fill)
.padding(iced::Padding {
top: 0.0,
right: 20.0,