feat(slint): offline artwork policy and local media-controls art

Shared artwork HTTP client gains the missing 10s total timeout (half-up
networks could pin the 16-permit semaphore). fetch_cached_http short-
circuits while offline: disk hits serve, misses return the placeholder
immediately with zero network and no negative caching. Now-playing meta
resolves MPRIS art to a cached file:// URL (or none) instead of an
unfetchable https URL while offline; system notifications skip their
blocking artwork download offline via an injected flag, keeping
qbz-media-controls frontend-agnostic.

Part of offline-mode slice 3; main.rs wiring rides the slice-3 wiring
commit.

cc
This commit is contained in:
vicrodh committed 2026-06-09 21:00:33 -06:00
1 parent b4caa5a309
commit dee85faadb
3 files changed
+63 -10

No files matched your search

+14 -5
View File
@@ -126,8 +126,11 @@ fn http_client() -> &'static reqwest::blocking::Client {
/// Resolve `url` to a local image file: a `file://`/`asset://` URL maps
/// straight through, an http(s) URL is downloaded and cached by md5(url).
/// `offline` = local paths + md5 cache hits only, never the HTTP download —
/// the verdict is injected by the caller so this crate stays frontend-agnostic
/// (no dependency on the app's offline-mode engine).
#[cfg(any(target_os = "linux", target_os = "macos"))]
fn cache_artwork(url: &str) -> Result<PathBuf, String> {
fn cache_artwork(url: &str, offline: bool) -> Result<PathBuf, String> {
use md5::{Digest, Md5};
use std::io::Write;
@@ -145,6 +148,10 @@ fn cache_artwork(url: &str) -> Result<PathBuf, String> {
return Ok(cache_path);
}
if offline {
return Err("offline: artwork not cached locally".to_string());
}
let response = http_client()
.get(url)
.header("User-Agent", "Mozilla/5.0")
@@ -215,8 +222,9 @@ fn prepare_icon_bytes(path: &std::path::Path) -> Result<Vec<u8>, String> {
/// Show a track-change notification. Fire-and-forget: every failure is logged,
/// none propagated. Must be called from within a tokio runtime (it uses
/// `spawn_blocking` for the HTTP/image work).
pub async fn show_track_notification(meta: NotificationMeta) {
/// `spawn_blocking` for the HTTP/image work). `offline` skips the artwork
/// HTTP download (local paths / disk-cache hits still render an icon).
pub async fn show_track_notification(meta: NotificationMeta, offline: bool) {
let body = build_body(&meta);
log::info!(
"[notify] track notification: {} by {}",
@@ -234,7 +242,7 @@ pub async fn show_track_notification(meta: NotificationMeta) {
if let Some(url) = meta.art_url.clone() {
let prepared = tokio::task::spawn_blocking(move || -> Result<Vec<u8>, String> {
let path = cache_artwork(&url)?;
let path = cache_artwork(&url, offline)?;
prepare_icon_bytes(&path)
})
.await;
@@ -265,7 +273,7 @@ pub async fn show_track_notification(meta: NotificationMeta) {
{
let _ = tokio::task::spawn_blocking(move || {
let _ = notify_rust::set_application("com.blitzfc.qbz");
let artwork_path = meta.art_url.as_deref().and_then(|url| match cache_artwork(url) {
let artwork_path = meta.art_url.as_deref().and_then(|url| match cache_artwork(url, offline) {
Ok(path) => Some(path),
Err(e) => {
log::debug!("[notify] could not cache artwork: {e}");
@@ -287,6 +295,7 @@ pub async fn show_track_notification(meta: NotificationMeta) {
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
let _ = body;
let _ = offline;
log::info!("[notify] desktop notifications not implemented on this platform");
}
}