notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit a176f544c617c966424d4a75f7d4ee270435a034
parent 13e626836587c3e4820df5f8095e03aa4734e783
Author: kernelkind <kernelkind@gmail.com>
Date:   Sat, 22 Nov 2025 21:10:51 -0700

feat(media-job): pre & post actions

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck/src/jobs/media.rs | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mcrates/notedeck/src/jobs/mod.rs | 5++++-
2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/crates/notedeck/src/jobs/media.rs b/crates/notedeck/src/jobs/media.rs @@ -3,9 +3,9 @@ use std::sync::mpsc::Sender; use egui::TextureHandle; use crate::jobs::JobCache; -use crate::{Animation, Error}; +use crate::{Animation, Error, TextureState, TexturesCache}; -use crate::jobs::types::JobPackage; +use crate::jobs::types::{JobComplete, JobId, JobPackage}; pub type MediaJobs = JobCache<MediaJobKind, MediaJobResult>; pub type MediaJobSender = Sender<JobPackage<MediaJobKind, MediaJobResult>>; @@ -22,3 +22,57 @@ pub enum MediaJobResult { Blurhash(Result<TextureHandle, Error>), Animation(Result<Animation, Error>), } + +pub fn deliver_completed_media_job( + completed: JobComplete<MediaJobKind, MediaJobResult>, + tex_cache: &mut TexturesCache, +) { + let id = completed.job_id.id; + let id_c = id.clone(); + match completed.response { + MediaJobResult::StaticImg(job_complete) => { + let r = match job_complete { + Ok(t) => TextureState::Loaded(t), + Err(e) => TextureState::Error(e), + }; + tex_cache.static_image.cache.insert(id, r); + } + MediaJobResult::Animation(animation) => { + let r = match animation { + Ok(a) => TextureState::Loaded(a), + Err(e) => TextureState::Error(e), + }; + + tex_cache.animated.cache.insert(id, r); + } + MediaJobResult::Blurhash(texture_handle) => { + let r = match texture_handle { + Ok(t) => TextureState::Loaded(t), + Err(e) => TextureState::Error(e), + }; + tex_cache.blurred.cache.insert(id, r.into()); + } + } + tracing::trace!("Delivered job for {id_c}"); +} + +pub fn run_media_job_pre_action(job_id: &JobId<MediaJobKind>, tex_cache: &mut TexturesCache) { + let id = job_id.id.clone(); + match job_id.job_kind { + MediaJobKind::Blurhash => { + tex_cache + .blurred + .cache + .insert(id, TextureState::Pending.into()); + } + MediaJobKind::StaticImg => { + tex_cache + .static_image + .cache + .insert(id, TextureState::Pending); + } + MediaJobKind::AnimatedImg => { + tex_cache.animated.cache.insert(id, TextureState::Pending); + } + } +} diff --git a/crates/notedeck/src/jobs/mod.rs b/crates/notedeck/src/jobs/mod.rs @@ -12,4 +12,7 @@ pub use cache_old::{ BlurhashParams, Job, JobError, JobIdOld, JobParams, JobParamsOwned, JobState, JobsCacheOld, }; pub use job_pool::JobPool; -pub use media::{MediaJobKind, MediaJobResult, MediaJobSender, MediaJobs}; +pub use media::{ + deliver_completed_media_job, run_media_job_pre_action, MediaJobKind, MediaJobResult, + MediaJobSender, +};