diff --git a/crates/notedeck/src/imgcache.rs b/crates/notedeck/src/imgcache.rs index 0ba841d8..42ceaa85 100644 --- a/crates/notedeck/src/imgcache.rs +++ b/crates/notedeck/src/imgcache.rs @@ -1,3 +1,4 @@ +use crate::urls::{UrlCache, UrlMimes}; use crate::Result; use egui::TextureHandle; use poll_promise::Promise; @@ -6,6 +7,7 @@ use egui::ColorImage; use std::collections::HashMap; use std::fs::{create_dir_all, File}; +use std::time::{Duration, Instant, SystemTime}; use hex::ToHex; use sha2::Digest; @@ -25,6 +27,7 @@ pub struct MediaCache { url_imgs: MediaCacheMap, } +#[derive(Clone)] pub enum MediaCacheType { Image, Gif, @@ -145,3 +148,39 @@ pub fn get_texture(textured_image: &TexturedImage) -> &TextureHandle { TexturedImage::Static(texture_handle) => texture_handle, } } + +#[allow(dead_code)] +pub struct Images { + pub static_imgs: MediaCache, + pub gifs: MediaCache, + pub urls: UrlMimes, + pub gif_states: GifStateMap, +} + +impl Images { + #[allow(dead_code)] + /// path to directory to place [`MediaCache`]s + pub fn new(path: path::PathBuf) -> Self { + Self { + static_imgs: MediaCache::new(path.join(MediaCache::rel_dir(MediaCacheType::Image))), + gifs: MediaCache::new(path.join(MediaCache::rel_dir(MediaCacheType::Gif))), + urls: UrlMimes::new(UrlCache::new(path.join(UrlCache::rel_dir()))), + gif_states: Default::default(), + } + } + + #[allow(dead_code)] + pub fn migrate_v0(&self) -> Result<()> { + self.static_imgs.migrate_v0()?; + self.gifs.migrate_v0() + } +} + +pub type GifStateMap = HashMap; + +pub struct GifState { + pub last_frame_rendered: Instant, + pub last_frame_duration: Duration, + pub next_frame_time: Option, + pub last_frame_index: usize, +} diff --git a/crates/notedeck/src/lib.rs b/crates/notedeck/src/lib.rs index 78f68921..6efc86a0 100644 --- a/crates/notedeck/src/lib.rs +++ b/crates/notedeck/src/lib.rs @@ -31,7 +31,7 @@ pub use context::AppContext; pub use error::{Error, FilterError}; pub use filter::{FilterState, FilterStates, UnifiedSubscription}; pub use fonts::NamedFontFamily; -pub use imgcache::{get_texture, MediaCache, MediaCacheType, TexturedImage}; +pub use imgcache::{get_texture, GifState, GifStateMap, MediaCache, MediaCacheType, TexturedImage}; pub use muted::{MuteFun, Muted}; pub use note::{NoteRef, RootIdError, RootNoteId, RootNoteIdBuf}; pub use notecache::{CachedNote, NoteCache};