Phase 1-7: Full migration from src/app/ to Clean Architecture
BREAKING CHANGES:
- Removed src/app/ (old TEA-style implementation)
- Removed src/constant.rs (constants now local to modules)
- Removed deprecated canvas_to_image_coords functions
NEW STRUCTURE:
- src/ui/ - UI Layer (COSMIC interface)
- src/application/ - Application Layer (DocumentManager, Commands)
- src/domain/ - Domain Layer (Document types, Operations)
- src/infrastructure/ - Infrastructure Layer (Loaders, Cache, System)
FEATURES:
- DocumentManager as Single Source of Truth
- Command Pattern for all operations
- Model caching for render data (performance)
- Sync mechanism between DocumentManager and UI Model
- Wallpaper support (COSMIC, KDE, GNOME, feh)
- Thumbnail cache with disk persistence
IMPROVEMENTS:
- Warnings: 62 → 43 (-31%)
- Deprecated warnings: 2 → 0 (-100%)
- Code removed: src/app/ (~2000 lines), constant.rs, deprecated functions
- Better Locality of Reference (constants local to modules)
- Clean separation of concerns
- No circular dependencies
DOCUMENTATION:
- Updated AGENTS.md (100% migration status)
- Updated README.md (architecture section)
- Updated Workflow.md
- Added Migration-Plan.md with full completion summary
TESTS:
- All 41 tests passing
- Build successful (0 errors, 43 warnings)
- Release build verified
Migration Status: ✅ 100% Complete
81 lines
2.1 KiB
Rust
81 lines
2.1 KiB
Rust
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// src/application/services/cache_service.rs
|
|
//
|
|
// Cache service: manages document and thumbnail caching.
|
|
// Reserved for future caching layer implementation.
|
|
|
|
#![allow(dead_code)]
|
|
|
|
use std::path::Path;
|
|
|
|
use cosmic::widget::image::Handle as ImageHandle;
|
|
use image::DynamicImage;
|
|
|
|
use crate::infrastructure::cache::ThumbnailCache;
|
|
|
|
/// Cache service for managing document caches.
|
|
///
|
|
/// Provides high-level caching operations for the application layer.
|
|
pub struct CacheService;
|
|
|
|
impl CacheService {
|
|
/// Create a new cache service.
|
|
#[must_use]
|
|
pub fn new() -> Self {
|
|
Self
|
|
}
|
|
|
|
/// Load a thumbnail from cache.
|
|
///
|
|
/// Returns None if the thumbnail is not cached or the cache is invalid.
|
|
#[must_use]
|
|
pub fn get_thumbnail(&self, path: &Path, page: usize) -> Option<ImageHandle> {
|
|
ThumbnailCache::load(path, page)
|
|
}
|
|
|
|
/// Save a thumbnail to cache.
|
|
///
|
|
/// Returns true if the thumbnail was successfully cached.
|
|
pub fn put_thumbnail(&self, path: &Path, page: usize, image: &DynamicImage) -> bool {
|
|
ThumbnailCache::save(path, page, image).is_some()
|
|
}
|
|
|
|
/// Clear all cached thumbnails.
|
|
///
|
|
/// This operation is not yet implemented.
|
|
pub fn clear_cache(&self) -> Result<(), String> {
|
|
ThumbnailCache::clear_cache().map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Get the size of the cache directory.
|
|
///
|
|
/// Returns the total size in bytes, or None if it cannot be determined.
|
|
#[must_use]
|
|
pub fn cache_size(&self) -> Option<u64> {
|
|
// TODO: Implement cache size calculation
|
|
None
|
|
}
|
|
}
|
|
|
|
impl Default for CacheService {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_cache_service_creation() {
|
|
let service = CacheService::new();
|
|
assert!(std::ptr::eq(&service, &service)); // Dummy test
|
|
}
|
|
|
|
#[test]
|
|
fn test_cache_service_default() {
|
|
let service = CacheService::default();
|
|
assert!(std::ptr::eq(&service, &service)); // Dummy test
|
|
}
|
|
}
|