migrate to using Images instead of MediaCache directly

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-02-18 19:42:17 -05:00
parent 75a352a86f
commit 33fdf647e3
27 changed files with 101 additions and 106 deletions

View File

@@ -1,7 +1,7 @@
use crate::persist::{AppSizeHandler, ZoomHandler};
use crate::{
Accounts, AppContext, Args, DataPath, DataPathType, Directory, FileKeyStorage, KeyStorageType,
MediaCache, NoteCache, RelayDebugView, ThemeHandler, UnknownIds,
Accounts, AppContext, Args, DataPath, DataPathType, Directory, FileKeyStorage, Images,
KeyStorageType, NoteCache, RelayDebugView, ThemeHandler, UnknownIds,
};
use egui::ThemePreference;
use enostr::RelayPool;
@@ -19,7 +19,7 @@ pub trait App {
/// Main notedeck app framework
pub struct Notedeck {
ndb: Ndb,
img_cache: MediaCache,
img_cache: Images,
unknown_ids: UnknownIds,
pool: RelayPool,
note_cache: NoteCache,
@@ -129,9 +129,7 @@ impl Notedeck {
let _ = std::fs::create_dir_all(&dbpath_str);
let img_cache_dir = path
.path(DataPathType::Cache)
.join(MediaCache::rel_dir(crate::imgcache::MediaCacheType::Image));
let img_cache_dir = path.path(DataPathType::Cache);
let _ = std::fs::create_dir_all(img_cache_dir.clone());
let map_size = if cfg!(target_os = "windows") {
@@ -186,7 +184,7 @@ impl Notedeck {
}
}
let img_cache = MediaCache::new(img_cache_dir);
let img_cache = Images::new(img_cache_dir);
let note_cache = NoteCache::default();
let unknown_ids = UnknownIds::default();
let zoom = ZoomHandler::new(&path);

View File

@@ -1,4 +1,4 @@
use crate::{Accounts, Args, DataPath, MediaCache, NoteCache, ThemeHandler, UnknownIds};
use crate::{Accounts, Args, DataPath, Images, NoteCache, ThemeHandler, UnknownIds};
use enostr::RelayPool;
use nostrdb::Ndb;
@@ -7,7 +7,7 @@ use nostrdb::Ndb;
pub struct AppContext<'a> {
pub ndb: &'a mut Ndb,
pub img_cache: &'a mut MediaCache,
pub img_cache: &'a mut Images,
pub unknown_ids: &'a mut UnknownIds,
pub pool: &'a mut RelayPool,
pub note_cache: &'a mut NoteCache,

View File

@@ -149,7 +149,6 @@ pub fn get_texture(textured_image: &TexturedImage) -> &TextureHandle {
}
}
#[allow(dead_code)]
pub struct Images {
pub static_imgs: MediaCache,
pub gifs: MediaCache,
@@ -158,7 +157,6 @@ pub struct Images {
}
impl Images {
#[allow(dead_code)]
/// path to directory to place [`MediaCache`]s
pub fn new(path: path::PathBuf) -> Self {
Self {
@@ -169,7 +167,6 @@ impl Images {
}
}
#[allow(dead_code)]
pub fn migrate_v0(&self) -> Result<()> {
self.static_imgs.migrate_v0()?;
self.gifs.migrate_v0()

View File

@@ -31,7 +31,9 @@ pub use context::AppContext;
pub use error::{Error, FilterError};
pub use filter::{FilterState, FilterStates, UnifiedSubscription};
pub use fonts::NamedFontFamily;
pub use imgcache::{get_texture, GifState, GifStateMap, MediaCache, MediaCacheType, TexturedImage};
pub use imgcache::{
get_texture, GifState, GifStateMap, Images, MediaCache, MediaCacheType, TexturedImage,
};
pub use muted::{MuteFun, Muted};
pub use note::{NoteRef, RootIdError, RootNoteId, RootNoteIdBuf};
pub use notecache::{CachedNote, NoteCache};

View File

@@ -93,7 +93,7 @@ fn read_from_disk(path: PathBuf) -> Promise<Option<UrlsToMime>> {
match result {
Ok(data) => sender.send(Some(data)),
Err(e) => {
tracing::error!("problem deserializing UrlCache: {e}");
tracing::error!("problem deserializing UrlMimes: {e}");
sender.send(None)
}
}
@@ -116,13 +116,13 @@ fn save_to_disk(path: PathBuf, cache: Arc<RwLock<UrlsToMime>>) {
Ok(())
} else {
Err(Error::Generic(
"Could not read UrlCache behind RwLock".to_owned(),
"Could not read UrlMimes behind RwLock".to_owned(),
))
}
})();
if let Err(e) = result {
tracing::error!("Failed to save UrlCache: {}", e);
tracing::error!("Failed to save UrlMimes: {}", e);
}
});
}
@@ -144,7 +144,7 @@ fn ehttp_get_mime_type(url: &str, sender: poll_promise::Sender<MimeResult>) {
}
Err(err) => {
sender.send(MimeResult::Err(HttpError::HttpFailure));
tracing::error!("failed ehttp for UrlCache: {err}");
tracing::error!("failed ehttp for UrlMimes: {err}");
}
},
);