Fix image download recovery and banner layout

Retry failed avatars, icons and banners automatically with bounded backoff,
expire stalled image transfers, and preserve explicit avatar requests.
Bound concurrent HTTP downloads, allow larger banners, and decode BOM SVGs.

Separate artwork from channel titles and controls across desktop and mobile,
using bounded aspect-aware areas and realistic demo fixtures.

Validation: 176 library tests, explicit-fetch policy regression, independent
TS6 avatar download and transient503/banner reload scenarios, strict Clippy,
formatting, license notices, and eight reviewed headless captures.
This commit is contained in:
selikhov committed 2026-10-04 18:04:10 +03:00
1 parent 02693a0f7f
commit b2549f867e
21 files changed
+738 -139

No files matched your search

+7 -3
View File
@@ -385,7 +385,7 @@ fn demo_ui(app: &mut App) {
p.server.welcome_message =
"Welcome to [b]Nightfall Guild[/b]! Raids on Tuesdays and Fridays, all levels welcome."
.into();
// The host banner, a server icon, banners behind two channels and an icon
// The host banner, a server icon, banners above three channels and an icon
// on another; the pictures arrive below (`demo_pictures`).
p.server.banner_gfx_url = DEMO_HOST_BANNER.into();
p.server.banner_mode = BannerMode::KeepAspect;
@@ -400,6 +400,8 @@ fn demo_ui(app: &mut App) {
raid.banner_mode = BannerMode::KeepAspect;
let mut music = channel(5, 0, 3, "Music");
music.icon = DEMO_MUSIC_ICON;
music.banner_gfx_url = Some(DEMO_MUSIC_BANNER.into());
music.banner_mode = BannerMode::NoAdjust;
let mut locked = channel(7, 0, 6, "Officers");
locked.has_password = true;
for c in [
@@ -1001,6 +1003,7 @@ fn demo_social(app: &mut App) {
/// Addresses and icon ids of the sample server's pictures.
const DEMO_HOST_BANNER: &str = "https://nightfall.example/banner.png";
const DEMO_CHILL_BANNER: &str = "https://nightfall.example/chill.png";
const DEMO_MUSIC_BANNER: &str = "https://nightfall.example/music.png";
const DEMO_RAID_BANNER: &str = "https://nightfall.example/raid.png";
const DEMO_SERVER_ICON: u32 = 3_120_211_001;
const DEMO_ADMIN_ICON: u32 = 3_120_211_002;
@@ -1027,9 +1030,10 @@ fn demo_pictures(app: &mut App) {
}),
}];
for (url, picture) in [
(DEMO_HOST_BANNER, demo_picture(560, 144, 3)),
(DEMO_HOST_BANNER, demo_picture(256, 256, 3)),
(DEMO_CHILL_BANNER, demo_picture(900, 120, 11)),
(DEMO_RAID_BANNER, demo_picture(640, 160, 5)),
(DEMO_RAID_BANNER, demo_picture(240, 240, 5)),
(DEMO_MUSIC_BANNER, demo_picture(180, 36, 7)),
] {
let path = save(url.rsplit('/').next().unwrap_or(url), picture);
events.push(Event::PictureReady { session, url: url.into(), path });
+8 -1
View File
@@ -136,6 +136,7 @@ pub fn forget(path: &std::path::Path) {
/// raster dimensions before Slint allocates pixels on the UI thread. SVGs
/// keep Slint's native vector loader and are rasterized at the displayed size.
fn decode(bytes: &[u8]) -> Option<(Image, usize)> {
let bytes = bytes.strip_prefix(b"\xef\xbb\xbf").unwrap_or(bytes);
let reader = image::ImageReader::new(Cursor::new(bytes)).with_guessed_format().ok()?;
let cost = if reader.format().is_some() {
let (width, height) = reader.into_dimensions().ok()?;
@@ -157,7 +158,7 @@ fn decode(bytes: &[u8]) -> Option<(Image, usize)> {
}
// Intrinsic SVG dimensions describe coordinates, not an allocated
// pixel buffer. Use the same vector cost as the emoji cache.
svg_cost(bytes.len())
return Image::load_from_svg_data(start).ok().map(|image| (image, svg_cost(bytes.len())));
};
Image::load_from_data(bytes, None).ok().map(|image| (image, cost))
}
@@ -236,6 +237,12 @@ mod tests {
assert_eq!(picture("test:junk", b"not a picture").size().width, 0);
}
#[test]
fn svg_with_bom_and_whitespace_decodes() {
let svg = b"\xef\xbb\xbf \n<svg xmlns='http://www.w3.org/2000/svg' width='32' height='16'><rect width='32' height='16'/></svg>";
assert_eq!(picture("test:svg-bom", svg).size().width, 32);
}
#[test]
fn large_svg_coordinates_do_not_overflow_the_cache_cost() {
let svg = br#"<svg xmlns="http://www.w3.org/2000/svg" width="3000000000" height="3000000000"><rect width="1" height="1"/></svg>"#;