feat: UI rewrite - TEA architecture, eliminate sync pattern
Complete UI layer refactoring to achieve Clean Architecture + TEA principles. Major Changes: - Eliminated sync.rs (76 LOC of manual synchronization) - Restructured AppModel: pure UI state only - Introduced AppMode enum (View, Crop, Transform, Fullscreen) - Added Viewport struct (scale, pan, canvas, cached_image_handle) - Added PanelState struct (left, right panels) - Removed all cached document data from UI layer - Views now access DocumentManager directly (no caching) - Update functions work on both model and manager directly Architecture: - TEA-compliant: Single source of truth, unidirectional flow - Clean separation: UI state vs Document state - No manual synchronization required Benefits: - Simplified codebase: -1,986 LOC net (-75.6%) - Better maintainability: Clear responsibilities - Type-safe state: Enums instead of flags - Performance: Cached rendering where needed Refactored Files: - src/ui/model.rs: Complete rewrite - src/ui/update.rs: Complete rewrite - src/ui/views/*: Updated to use new architecture - src/ui/views/meta_panel.rs: Extracted from panels.rs Testing: - All 24 unit tests passing - Compiles successfully (cargo check, cargo build) - 32 warnings (non-critical, future features) BREAKING CHANGES: None (internal refactoring only) Co-authored-by: Clean Architecture principles Co-authored-by: TEA (The Elm Architecture) pattern
This commit is contained in:
parent
5126b24cb2
commit
6002b37406
22 changed files with 640 additions and 2626 deletions
|
|
@ -1,167 +0,0 @@
|
|||
# Feature-Vergleich: app/document vs domain/document/types
|
||||
|
||||
**Ziel:** Identifizieren welche Features von `src/app/document/` nach `src/domain/document/types/` portiert werden müssen.
|
||||
|
||||
---
|
||||
|
||||
## RasterDocument
|
||||
|
||||
### Struct-Felder
|
||||
|
||||
| Feld | app/ | domain/ | Status |
|
||||
|------|------|---------|--------|
|
||||
| `document: DynamicImage` | ✅ | ✅ | OK |
|
||||
| `native_width: u32` | ✅ | ✅ | OK |
|
||||
| `native_height: u32` | ✅ | ✅ | OK |
|
||||
| `transform: TransformState` | ✅ | ✅ | OK |
|
||||
| `handle: ImageHandle` | ✅ pub | ✅ private | **⚠️ domain: public machen oder getter** |
|
||||
| `fine_rotation_angle: f32` | ❌ | ✅ | ℹ️ Extra feature in domain |
|
||||
| `interpolation_quality` | ❌ | ✅ | ℹ️ Extra feature in domain |
|
||||
|
||||
**Entscheidung:** Domain-Version hat mehr Features → Domain behalten, `handle` public machen
|
||||
|
||||
---
|
||||
|
||||
### Methoden-Vergleich
|
||||
|
||||
| Methode | app/ | domain/ | Aktion |
|
||||
|---------|------|---------|--------|
|
||||
| **Core Operations** | | | |
|
||||
| `open()` | ✅ | ✅ | ✅ OK |
|
||||
| `render()` | ✅ | ✅ | ✅ OK |
|
||||
| `save()` | ✅ | ✅ | ✅ OK |
|
||||
| | | | |
|
||||
| **Transformations (Trait)** | | | |
|
||||
| `rotate()` | ✅ | ✅ | ✅ OK |
|
||||
| `flip()` | ✅ | ✅ | ✅ OK |
|
||||
| `transform_state()` | ✅ | ✅ | ✅ OK |
|
||||
| | | | |
|
||||
| **Renderable (Trait)** | | | |
|
||||
| `info()` | ✅ | ✅ | ✅ OK |
|
||||
| | | | |
|
||||
| **Dimensions** | | | |
|
||||
| `dimensions()` | ✅ | ✅ | ✅ OK (beide haben es!) |
|
||||
| `native_dimensions()` | ❌ | ✅ | ℹ️ Extra in domain |
|
||||
| | | | |
|
||||
| **Crop** | | | |
|
||||
| `crop()` | ✅ | ✅ | ✅ OK (beide haben es!) |
|
||||
| `crop_to_image()` | ✅ | ❌ | 📋 **Portieren nach domain/** |
|
||||
| | | | |
|
||||
| **Handle/Image Access** | | | |
|
||||
| `handle` (field pub) | ✅ | ❌ | 📋 **Public machen oder getter** |
|
||||
| `handle()` (getter) | ❌ | ✅ | ✅ OK (domain hat getter) |
|
||||
| `image()` | ❌ | ✅ | ℹ️ Extra in domain |
|
||||
| `get_rendered_image()` | ❌ | ✅ | ℹ️ Extra in domain |
|
||||
| | | | |
|
||||
| **Metadata** | | | |
|
||||
| `extract_meta()` | ✅ | ❌ | 📋 **Portieren nach domain/** |
|
||||
| | | | |
|
||||
| **Internal Helpers** | | | |
|
||||
| `refresh_handle()` | ✅ private | ❌ | ℹ️ Evtl. bereits integriert |
|
||||
| `apply_rotation()` | ❌ | ✅ | ℹ️ Extra in domain |
|
||||
| `apply_flip()` | ❌ | ✅ | ℹ️ Extra in domain |
|
||||
| `create_image_handle_from_image()` | ❌ | ✅ | ℹ️ Extra in domain |
|
||||
| | | | |
|
||||
| **Extra Features (domain)** | | | |
|
||||
| `rotate_fine()` | ❌ | ✅ | ℹ️ Feature in domain |
|
||||
| `reset_fine_rotation()` | ❌ | ✅ | ℹ️ Feature in domain |
|
||||
| `set_interpolation_quality()` | ❌ | ✅ | ℹ️ Feature in domain |
|
||||
| `resize_to_format()` | ❌ | ✅ | ℹ️ Feature in domain |
|
||||
|
||||
---
|
||||
|
||||
### Zusammenfassung RasterDocument
|
||||
|
||||
**Domain-Version ist fortgeschrittener** ✅
|
||||
- Mehr Features (fine rotation, interpolation quality, resize)
|
||||
- Bessere API (getter statt public fields)
|
||||
- Saubere Helper-Funktionen
|
||||
|
||||
**Aus app/ portieren:**
|
||||
1. ✅ `crop_to_image()` - Nicht-destruktives Crop
|
||||
2. ✅ `extract_meta()` - Metadaten-Extraktion
|
||||
3. ✅ `handle` public machen ODER getter `handle()` nutzen (bereits vorhanden!)
|
||||
|
||||
**Entscheidung:** Domain-Version als Basis, nur 2 Methoden fehlen
|
||||
|
||||
---
|
||||
|
||||
## VectorDocument
|
||||
|
||||
### Methoden-Vergleich
|
||||
|
||||
| Methode | app/ | domain/ | Aktion |
|
||||
|---------|------|---------|--------|
|
||||
| `open()` | ✅ | ✅ | ✅ OK |
|
||||
| `render()` | ✅ | ✅ | ✅ OK |
|
||||
| `dimensions()` | ✅ | ❌ | 📋 **Portieren** |
|
||||
| `handle` (pub field) | ✅ | ❌ private | 📋 **Public machen oder getter** |
|
||||
| `extract_meta()` | ✅ | ❌ | 📋 **Portieren** |
|
||||
| `crop()` | ❌ | ❌ | 📋 **Neu implementieren** (Design-Entscheidung) |
|
||||
|
||||
**Aus app/ portieren:**
|
||||
1. `dimensions()`
|
||||
2. `extract_meta()`
|
||||
3. `handle()` getter oder public
|
||||
4. NEU: `crop()` implementieren (render-based)
|
||||
|
||||
---
|
||||
|
||||
## PortableDocument
|
||||
|
||||
### Methoden-Vergleich
|
||||
|
||||
| Methode | app/ | domain/ | Aktion |
|
||||
|---------|------|---------|--------|
|
||||
| `open()` | ✅ | ✅ | ✅ OK |
|
||||
| `render()` | ✅ | ✅ | ✅ OK |
|
||||
| `dimensions()` | ✅ | ❌ | 📋 **Portieren** |
|
||||
| `handle` (pub field) | ✅ | ❌ private | 📋 **Public machen oder getter** |
|
||||
| `extract_meta()` | ✅ | ❌ | 📋 **Portieren** |
|
||||
| `crop()` | ❌ | ❌ | 📋 **Neu implementieren** (Design-Entscheidung) |
|
||||
| Thumbnails | ✅ | ✅ | ℹ️ Prüfen ob identisch |
|
||||
|
||||
**Aus app/ portieren:**
|
||||
1. `dimensions()`
|
||||
2. `extract_meta()`
|
||||
3. `handle()` getter oder public
|
||||
4. NEU: `crop()` implementieren (render-based)
|
||||
|
||||
---
|
||||
|
||||
## Action Items für Schritt 1.2-1.4
|
||||
|
||||
### Schritt 1.2: RasterDocument (60 Min)
|
||||
- [x] `crop()` - Bereits vorhanden! ✅
|
||||
- [x] `dimensions()` - Bereits vorhanden! ✅
|
||||
- [x] `crop_to_image()` hinzufügen ✅
|
||||
- [x] `extract_meta()` hinzufügen ✅ (oder in core/metadata.rs)
|
||||
- [x] `handle()` getter - Bereits vorhanden! ✅
|
||||
|
||||
### Schritt 1.3: VectorDocument (45 Min)
|
||||
- [x] `dimensions()` - Bereits vorhanden ✅
|
||||
- [x] `handle()` getter - Bereits vorhanden ✅
|
||||
- [x] `extract_meta()` implementieren ✅
|
||||
- [x] `crop()` implementieren (render-based) ✅
|
||||
|
||||
### Schritt 1.4: PortableDocument (45 Min)
|
||||
- [x] `dimensions()` - Bereits vorhanden ✅
|
||||
- [x] `handle()` getter - Bereits vorhanden ✅
|
||||
- [x] `extract_meta()` implementieren ✅
|
||||
- [x] `crop()` implementieren (render-based) ✅
|
||||
|
||||
---
|
||||
|
||||
## Überraschende Erkenntnisse
|
||||
|
||||
1. **Domain hat bereits crop() für Raster!** ✅
|
||||
2. **Domain hat bereits dimensions()!** ✅
|
||||
3. **Domain hat bereits handle() getter!** ✅
|
||||
4. **Domain hat MEHR Features** (fine rotation, interpolation) ✅
|
||||
|
||||
**→ Domain-Implementierung ist besser! Nur 2-3 Methoden fehlen pro Type.**
|
||||
|
||||
---
|
||||
|
||||
**Status:** Vergleich abgeschlossen
|
||||
**Nächster Schritt:** 1.2 - RasterDocument ergänzen
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
# Metadata Konsolidierung - Vergleich
|
||||
|
||||
## Status: ✅ Strukturen sind identisch
|
||||
|
||||
### Strukturen
|
||||
|
||||
| Struktur | app/meta.rs | domain/core/metadata.rs | Status |
|
||||
|----------|-------------|-------------------------|--------|
|
||||
| `BasicMeta` | ✅ 7 fields | ✅ 7 fields | ✅ Identisch |
|
||||
| `ExifMeta` | ✅ 9 fields | ✅ 9 fields | ✅ Identisch |
|
||||
| `DocumentMeta` | ✅ | ✅ | ✅ Identisch |
|
||||
|
||||
### Methoden
|
||||
|
||||
| Methode | app/ | domain/ | Status |
|
||||
|---------|------|---------|--------|
|
||||
| `BasicMeta::file_size_display()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `BasicMeta::resolution_display()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `ExifMeta::camera_display()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `ExifMeta::gps_display()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `ExifMeta::from_bytes()` | ❌ private fn | ✅ pub fn | ✅ Domain besser |
|
||||
|
||||
### Helper-Funktionen
|
||||
|
||||
**App hat:**
|
||||
- `build_raster_meta()` - Wird nicht außerhalb app/ verwendet
|
||||
- `build_vector_meta()` - Wird nicht außerhalb app/ verwendet
|
||||
- `build_portable_meta()` - Wird nicht außerhalb app/ verwendet
|
||||
- `extract_exif_from_bytes()` - Private Funktion
|
||||
|
||||
**Domain hat:**
|
||||
- `ExifMeta::from_bytes()` - Public Methode (sauberer)
|
||||
- Document-Typen haben eigene `extract_meta()` Methoden
|
||||
|
||||
### Unterschiede
|
||||
|
||||
**Organisation:**
|
||||
- **App:** Helper-Funktionen `build_*_meta()` außerhalb der Structs
|
||||
- **Domain:** `extract_meta()` Methoden direkt in Document-Typen (RasterDocument, VectorDocument, PortableDocument)
|
||||
|
||||
**Vorteile Domain:**
|
||||
- ✅ Sauberer: `doc.extract_meta(path)` statt `build_raster_meta(path, doc, ...)`
|
||||
- ✅ Type-safe: Compiler weiß welcher Typ
|
||||
- ✅ Erweiterbar: Jeder Document-Typ kontrolliert eigene Metadaten
|
||||
|
||||
## Entscheidung
|
||||
|
||||
✅ **Keine Änderungen nötig!**
|
||||
|
||||
- Domain-Version ist vollständig und sogar besser organisiert
|
||||
- Strukturen sind identisch
|
||||
- `ExifMeta::from_bytes()` ist bereits in Domain als public Methode
|
||||
- `extract_meta()` Methoden in Document-Typen sind bereits implementiert
|
||||
|
||||
## Nächster Schritt
|
||||
|
||||
Schritt 1.7: Traits & Enums konsolidieren
|
||||
|
|
@ -1,925 +0,0 @@
|
|||
# Noctua – Complete Migration Plan
|
||||
|
||||
**Ziel:** Vollständige Trennung von TEA (UI) und Business Logic nach Clean Architecture
|
||||
|
||||
**Status:** ✅ **MIGRATION ABGESCHLOSSEN** (100%)
|
||||
|
||||
- ✅ `src/app/` wurde gelöscht
|
||||
- ✅ `src/ui/` + `src/application/` + `src/domain/` + `src/infrastructure/` sind aktiv
|
||||
- ✅ Clean Architecture vollständig implementiert
|
||||
- ✅ DocumentManager ist Single Source of Truth
|
||||
- ✅ Command Pattern durchgängig implementiert
|
||||
- ✅ Views nutzen gecachte Daten aus AppModel
|
||||
- ✅ Sync-Mechanismus aktiv
|
||||
|
||||
---
|
||||
|
||||
## File Mapping: src/app/document/ → Ziel-Layer
|
||||
|
||||
### ✅ Domain Layer: src/domain/document/
|
||||
|
||||
| Quelle | Ziel | Aktion |
|
||||
|--------|------|--------|
|
||||
| `raster.rs` | `domain/document/types/raster.rs` | Features ergänzen (crop, dimensions, extract_meta) |
|
||||
| `vector.rs` | `domain/document/types/vector.rs` | Features ergänzen falls nötig |
|
||||
| `portable.rs` | `domain/document/types/portable.rs` | Features ergänzen (thumbnails) |
|
||||
| `mod.rs` (Traits) | `domain/document/core/document.rs` | Vergleichen & konsolidieren |
|
||||
| `mod.rs` (DocumentContent) | `domain/document/core/content.rs` | Methoden ergänzen (handle, dimensions, crop) |
|
||||
| `meta.rs` | `domain/document/core/metadata.rs` | Merge mit existierender Datei |
|
||||
|
||||
### ✅ Infrastructure Layer: src/infrastructure/
|
||||
|
||||
| Quelle | Ziel | Aktion |
|
||||
|--------|------|--------|
|
||||
| `file.rs::open_document()` | `loaders/document_loader.rs` | **Bereits vorhanden!** (DocumentLoaderFactory::load) |
|
||||
| `file.rs::collect_supported_files()` | `filesystem/file_ops.rs` | **Bereits vorhanden!** |
|
||||
| `file.rs::file_size()` | `filesystem/file_ops.rs` | **Bereits vorhanden!** |
|
||||
| `file.rs::read_file_bytes()` | `filesystem/file_ops.rs` | **Bereits vorhanden!** |
|
||||
| `cache.rs` | `cache/thumbnail_cache.rs` | **Neu erstellen** |
|
||||
| `utils.rs::set_as_wallpaper()` | `system/wallpaper.rs` | **Neu erstellen** |
|
||||
|
||||
### ✅ Application Layer: src/application/
|
||||
|
||||
| Quelle | Ziel | Aktion |
|
||||
|--------|------|--------|
|
||||
| `file.rs::navigate_next()` | `document_manager.rs` | **Bereits vorhanden!** (next_document) |
|
||||
| `file.rs::navigate_prev()` | `document_manager.rs` | **Bereits vorhanden!** (previous_document) |
|
||||
| `file.rs::open_initial_path()` | `document_manager.rs` | In open_document() integrieren |
|
||||
| `file.rs::save_crop_as()` | `commands/crop_document.rs` | In Command integrieren |
|
||||
|
||||
### ❌ Wird gelöscht (keine Migration nötig)
|
||||
|
||||
- `file.rs::load_document_into_model()` → War UI-spezifisch, wird durch sync_model_from_manager() ersetzt
|
||||
- `file.rs::refresh_folder_entries()` → Intern in DocumentManager
|
||||
|
||||
---
|
||||
|
||||
## Phase 1: Domain Layer Konsolidierung
|
||||
|
||||
### Schritt 1.1: Feature-Vergleich (90 Min)
|
||||
|
||||
**Für jeden Dokumenttyp:**
|
||||
|
||||
```bash
|
||||
# RasterDocument
|
||||
diff src/app/document/raster.rs src/domain/document/types/raster.rs > /tmp/raster-diff.txt
|
||||
|
||||
# VectorDocument
|
||||
diff src/app/document/vector.rs src/domain/document/types/vector.rs > /tmp/vector-diff.txt
|
||||
|
||||
# PortableDocument
|
||||
diff src/app/document/portable.rs src/domain/document/types/portable.rs > /tmp/portable-diff.txt
|
||||
```
|
||||
|
||||
**Checkliste erstellen:**
|
||||
|
||||
| Feature | RasterDocument | VectorDocument | PortableDocument |
|
||||
|---------|----------------|----------------|------------------|
|
||||
| `open()` | ✅ Beide | ✅ Beide | ✅ Beide |
|
||||
| `render()` | ✅ Beide | ✅ Beide | ✅ Beide |
|
||||
| `rotate()` | ✅ Beide | ✅ Beide | ✅ Beide |
|
||||
| `flip()` | ✅ Beide | ✅ Beide | ✅ Beide |
|
||||
| `dimensions()` | ❌ Nur app | ❓ Prüfen | ❓ Prüfen |
|
||||
| `crop()` | ❌ Nur app | N/A | N/A |
|
||||
| `crop_to_image()` | ❌ Nur app | N/A | N/A |
|
||||
| `extract_meta()` | ❌ Nur app | ❓ Prüfen | ❓ Prüfen |
|
||||
| `handle` (public) | ❌ Nur app | ❓ Prüfen | ❓ Prüfen |
|
||||
| Thumbnails | N/A | N/A | ❓ Prüfen |
|
||||
|
||||
### Schritt 1.2: RasterDocument Features portieren (60 Min)
|
||||
|
||||
**Datei:** `src/domain/document/types/raster.rs`
|
||||
|
||||
```rust
|
||||
impl RasterDocument {
|
||||
/// Get current dimensions after transformations.
|
||||
pub fn dimensions(&self) -> (u32, u32) {
|
||||
let (w, h) = self.document.dimensions();
|
||||
match self.transform.rotation {
|
||||
Rotation::Cw90 | Rotation::Cw270 => (h, w),
|
||||
_ => (w, h),
|
||||
}
|
||||
}
|
||||
|
||||
/// Crop the document to the specified rectangle (in-place).
|
||||
pub fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> DocResult<()> {
|
||||
self.document = self.document.crop_imm(x, y, width, height);
|
||||
self.refresh_handle();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Crop to a new DynamicImage (non-destructive).
|
||||
pub fn crop_to_image(&self, x: u32, y: u32, width: u32, height: u32) -> DocResult<DynamicImage> {
|
||||
let cropped = self.document.crop_imm(x, y, width, height);
|
||||
Ok(cropped)
|
||||
}
|
||||
|
||||
/// Make handle field public or add getter
|
||||
pub fn handle(&self) -> ImageHandle {
|
||||
self.handle.clone()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 1.3: VectorDocument Features portieren (30 Min)
|
||||
|
||||
**Datei:** `src/domain/document/types/vector.rs`
|
||||
|
||||
|
||||
**Design-Entscheidung:** Crop wird für alle Dokumenttypen unterstützt, da alle als Raster gerendert werden.
|
||||
|
||||
```rust
|
||||
impl VectorDocument {
|
||||
pub fn dimensions(&self) -> (u32, u32) {
|
||||
// Implementation based on transform state
|
||||
}
|
||||
|
||||
|
||||
/// Crop the document to the specified rectangle.
|
||||
/// Works on rendered output (raster).
|
||||
pub fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> DocResult<()> {
|
||||
// Render to raster with current transform
|
||||
let rendered = self.render_to_image()?;
|
||||
let cropped = rendered.crop_imm(x, y, width, height);
|
||||
self.handle = create_image_handle_from_image(&cropped);
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
Ok(())
|
||||
}
|
||||
pub fn handle(&self) -> ImageHandle {
|
||||
self.handle.clone()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 1.4: PortableDocument Features portieren (30 Min)
|
||||
|
||||
**Datei:** `src/domain/document/types/portable.rs`
|
||||
|
||||
```rust
|
||||
impl PortableDocument {
|
||||
pub fn dimensions(&self) -> (u32, u32) {
|
||||
// Implementation based on current page
|
||||
}
|
||||
|
||||
|
||||
/// Crop the current page to the specified rectangle.
|
||||
/// Works on rendered output (raster).
|
||||
pub fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> DocResult<()> {
|
||||
// Crop current page
|
||||
let rendered = self.render_current_page()?;
|
||||
let cropped = rendered.crop_imm(x, y, width, height);
|
||||
self.handle = create_image_handle_from_image(&cropped);
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
Ok(())
|
||||
}
|
||||
pub fn handle(&self) -> ImageHandle {
|
||||
self.handle.clone()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 1.5: DocumentContent Methoden ergänzen (45 Min)
|
||||
|
||||
**Datei:** `src/domain/document/core/content.rs`
|
||||
|
||||
```rust
|
||||
impl DocumentContent {
|
||||
/// Get current image handle for rendering.
|
||||
pub fn handle(&self) -> ImageHandle {
|
||||
match self {
|
||||
Self::Raster(doc) => doc.handle(),
|
||||
Self::Vector(doc) => doc.handle(),
|
||||
Self::Portable(doc) => doc.handle(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get current dimensions.
|
||||
pub fn dimensions(&self) -> (u32, u32) {
|
||||
match self {
|
||||
Self::Raster(doc) => doc.dimensions(),
|
||||
Self::Vector(doc) => doc.dimensions(),
|
||||
Self::Portable(doc) => doc.dimensions(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Crop the document (supported for all types - works on rendered output).
|
||||
pub fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> DocResult<()> {
|
||||
match self {
|
||||
Self::Raster(doc) => doc.crop(x, y, width, height),
|
||||
Self::Vector(doc) => doc.crop(x, y, width, height),
|
||||
Self::Portable(doc) => doc.crop(x, y, width, height),
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 1.6: Metadata konsolidieren (30 Min)
|
||||
|
||||
**Vergleichen:**
|
||||
- `src/app/document/meta.rs`
|
||||
- `src/domain/document/core/metadata.rs`
|
||||
|
||||
**Aktion:** Fehlende Methoden aus app/meta.rs nach domain/core/metadata.rs portieren.
|
||||
|
||||
### Schritt 1.7: Traits & Enums konsolidieren (30 Min)
|
||||
|
||||
**Vergleichen:**
|
||||
- `src/app/document/mod.rs` (Traits, Enums)
|
||||
- `src/domain/document/core/document.rs` (Traits, Enums)
|
||||
|
||||
**Prüfen ob identisch:** Rotation, FlipDirection, TransformState, Renderable, Transformable, MultiPage
|
||||
|
||||
**Falls Unterschiede:** Domain-Version als Master verwenden.
|
||||
|
||||
---
|
||||
|
||||
## Phase 2: Infrastructure Layer Migration
|
||||
|
||||
### Schritt 2.1: Thumbnail Cache erstellen (45 Min)
|
||||
|
||||
**Neue Datei:** `src/infrastructure/cache/thumbnail_cache.rs`
|
||||
|
||||
```rust
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// src/infrastructure/cache/thumbnail_cache.rs
|
||||
//
|
||||
// Disk cache for document thumbnails.
|
||||
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use image::DynamicImage;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use cosmic::widget::image::Handle as ImageHandle;
|
||||
use crate::constant::{CACHE_DIR, THUMBNAIL_EXT};
|
||||
|
||||
pub struct ThumbnailCache;
|
||||
|
||||
impl ThumbnailCache {
|
||||
pub fn load(file_path: &Path, page: usize) -> Option<ImageHandle> {
|
||||
// Copy from app/document/cache.rs
|
||||
}
|
||||
|
||||
pub fn save(file_path: &Path, page: usize, image: &DynamicImage) {
|
||||
// Copy from app/document/cache.rs
|
||||
}
|
||||
|
||||
pub fn clear_cache() {
|
||||
// Copy from app/document/cache.rs
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Neue Datei:** `src/infrastructure/cache/mod.rs`
|
||||
|
||||
```rust
|
||||
pub mod thumbnail_cache;
|
||||
pub use thumbnail_cache::ThumbnailCache;
|
||||
```
|
||||
|
||||
**Neue Datei:** `src/infrastructure/mod.rs` (falls nicht vorhanden)
|
||||
|
||||
```rust
|
||||
pub mod cache;
|
||||
pub mod filesystem;
|
||||
pub mod loaders;
|
||||
```
|
||||
|
||||
### Schritt 2.2: Wallpaper System erstellen (30 Min)
|
||||
|
||||
**Neue Datei:** `src/infrastructure/system/wallpaper.rs`
|
||||
|
||||
```rust
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// src/infrastructure/system/wallpaper.rs
|
||||
//
|
||||
// Set desktop wallpaper across different desktop environments.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
pub fn set_as_wallpaper(path: &Path) {
|
||||
// Copy entire implementation from app/document/utils.rs
|
||||
}
|
||||
|
||||
fn try_cosmic_wallpaper(path_str: &str) -> bool { ... }
|
||||
fn try_wallpaper_crate(path_str: &str) -> bool { ... }
|
||||
fn try_gsettings_wallpaper(path_str: &str) -> bool { ... }
|
||||
fn try_feh_wallpaper(path_str: &str) -> bool { ... }
|
||||
```
|
||||
|
||||
**Neue Datei:** `src/infrastructure/system/mod.rs`
|
||||
|
||||
```rust
|
||||
pub mod wallpaper;
|
||||
pub use wallpaper::set_as_wallpaper;
|
||||
```
|
||||
|
||||
**Update:** `src/infrastructure/mod.rs`
|
||||
|
||||
```rust
|
||||
pub mod cache;
|
||||
pub mod filesystem;
|
||||
pub mod loaders;
|
||||
pub mod system;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 3: Application Layer Integration
|
||||
|
||||
### Schritt 3.1: Sync-Funktion implementieren (45 Min)
|
||||
|
||||
**Neue Datei:** `src/ui/sync.rs`
|
||||
|
||||
```rust
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// src/ui/sync.rs
|
||||
//
|
||||
// Synchronize UI model from DocumentManager state.
|
||||
|
||||
use crate::application::DocumentManager;
|
||||
use crate::ui::model::AppModel;
|
||||
|
||||
/// Synchronize AppModel from DocumentManager.
|
||||
///
|
||||
/// Updates UI state with current document info, but does NOT copy
|
||||
/// the entire document (would break Clean Architecture).
|
||||
pub fn sync_model_from_manager(model: &mut AppModel, manager: &DocumentManager) {
|
||||
// Update cached render data
|
||||
if let Some(doc) = manager.current_document() {
|
||||
model.current_image_handle = Some(doc.handle());
|
||||
model.current_dimensions = Some(doc.dimensions());
|
||||
model.current_page = doc.current_page();
|
||||
model.page_count = doc.page_count();
|
||||
} else {
|
||||
model.current_image_handle = None;
|
||||
model.current_dimensions = None;
|
||||
model.current_page = None;
|
||||
model.page_count = None;
|
||||
}
|
||||
|
||||
// Update navigation state
|
||||
model.current_path = manager.current_path().map(|p| p.to_path_buf());
|
||||
model.folder_count = manager.folder_entries().len();
|
||||
model.current_index = manager.current_index();
|
||||
|
||||
// Metadata
|
||||
model.metadata = manager.current_metadata().cloned();
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 3.2: DocumentManager in NoctuaApp aktivieren (30 Min)
|
||||
|
||||
**Datei:** `src/ui/app.rs`
|
||||
|
||||
Status prüfen:
|
||||
- ✅ DocumentManager bereits als Feld vorhanden
|
||||
- ✅ DocumentManager wird in init() erstellt
|
||||
- ✅ Initial document wird geladen
|
||||
|
||||
**Was fehlt:**
|
||||
- Model-Sync nach init
|
||||
- Model-Sync nach jedem Command
|
||||
|
||||
**Änderungen:**
|
||||
|
||||
```rust
|
||||
impl cosmic::Application for NoctuaApp {
|
||||
fn init(mut core: Core, flags: Self::Flags) -> (Self, Task<Action<Self::Message>>) {
|
||||
// ... existing code ...
|
||||
|
||||
let mut document_manager = DocumentManager::new();
|
||||
|
||||
if let Some(path) = initial_path {
|
||||
if let Err(e) = document_manager.open_document(&path) {
|
||||
log::error!("Failed to open initial path {}: {}", path.display(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ NEU: Sync model from manager
|
||||
let mut model = AppModel::new(config.clone());
|
||||
sync::sync_model_from_manager(&mut model, &document_manager);
|
||||
|
||||
// ... rest of init ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 4: UI Layer Migration
|
||||
|
||||
### Schritt 4.1: AppModel bereinigen (60 Min)
|
||||
|
||||
**Datei:** `src/ui/model.rs`
|
||||
|
||||
**Aktuell:**
|
||||
|
||||
```rust
|
||||
pub struct AppModel {
|
||||
pub document: Option<DocumentContent>, // ❌ Raus
|
||||
pub metadata: Option<DocumentMeta>,
|
||||
pub current_path: Option<PathBuf>,
|
||||
pub folder_entries: Vec<PathBuf>, // ❌ Raus
|
||||
pub current_index: Option<usize>,
|
||||
|
||||
pub view_mode: ViewMode,
|
||||
pub pan_x: f32,
|
||||
pub pan_y: f32,
|
||||
pub tool_mode: ToolMode,
|
||||
pub crop_selection: CropSelection,
|
||||
pub error: Option<String>,
|
||||
pub tick: u64,
|
||||
}
|
||||
```
|
||||
|
||||
**Neu:**
|
||||
|
||||
```rust
|
||||
pub struct AppModel {
|
||||
// ✅ Cached rendering data (read-only from DocumentManager)
|
||||
pub current_image_handle: Option<ImageHandle>,
|
||||
pub current_dimensions: Option<(u32, u32)>,
|
||||
pub current_page: Option<usize>,
|
||||
pub page_count: Option<usize>,
|
||||
|
||||
// ✅ Cached metadata (read-only)
|
||||
pub metadata: Option<DocumentMeta>,
|
||||
|
||||
// ✅ Navigation info (read-only)
|
||||
pub current_path: Option<PathBuf>,
|
||||
pub current_index: Option<usize>,
|
||||
pub folder_count: usize,
|
||||
|
||||
// ✅ View state (UI controls these)
|
||||
pub view_mode: ViewMode,
|
||||
pub pan_x: f32,
|
||||
pub pan_y: f32,
|
||||
|
||||
// ✅ Tool state (UI controls these)
|
||||
pub tool_mode: ToolMode,
|
||||
pub crop_selection: CropSelection,
|
||||
|
||||
// ✅ UI state
|
||||
pub error: Option<String>,
|
||||
pub tick: u64,
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 4.2: Update-Logik umschreiben (120 Min)
|
||||
|
||||
**Datei:** `src/ui/update.rs`
|
||||
|
||||
**Pattern für alle Messages:**
|
||||
|
||||
```rust
|
||||
// ❌ Alt
|
||||
AppMessage::RotateCW => {
|
||||
if let Some(doc) = &mut model.document {
|
||||
doc.rotate_cw();
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ Neu
|
||||
AppMessage::RotateCW => {
|
||||
use crate::application::commands::TransformDocumentCommand;
|
||||
use crate::domain::document::operations::transform::TransformOperation;
|
||||
|
||||
let cmd = TransformDocumentCommand::new(TransformOperation::RotateCw);
|
||||
if let Err(e) = cmd.execute(&mut app.document_manager) {
|
||||
model.set_error(format!("Rotation failed: {e}"));
|
||||
return UpdateResult::None;
|
||||
}
|
||||
|
||||
sync::sync_model_from_manager(&mut app.model, &app.document_manager);
|
||||
UpdateResult::None
|
||||
}
|
||||
```
|
||||
|
||||
**Alle Messages umschreiben:**
|
||||
- OpenPath → DocumentManager::open_document()
|
||||
- NextDocument → DocumentManager::next_document()
|
||||
- PrevDocument → DocumentManager::previous_document()
|
||||
- RotateCW/CCW → TransformDocumentCommand
|
||||
- FlipHorizontal/Vertical → TransformDocumentCommand
|
||||
- ApplyCrop → CropDocumentCommand
|
||||
- GotoPage → DocumentManager.current_document_mut().go_to_page()
|
||||
- SetAsWallpaper → infrastructure::system::set_as_wallpaper()
|
||||
|
||||
### Schritt 4.3: Views anpassen (90 Min)
|
||||
|
||||
**Pattern für alle Views:**
|
||||
|
||||
```rust
|
||||
// ❌ Alt (src/app/view/canvas.rs)
|
||||
if let Some(doc) = &model.document {
|
||||
let handle = doc.handle();
|
||||
let (width, height) = doc.dimensions();
|
||||
}
|
||||
|
||||
// ✅ Neu (src/ui/views/canvas.rs)
|
||||
if let Some(handle) = &model.current_image_handle {
|
||||
let (width, height) = model.current_dimensions.unwrap_or((0, 0));
|
||||
}
|
||||
```
|
||||
|
||||
**Dateien prüfen und anpassen:**
|
||||
- canvas.rs
|
||||
- footer.rs
|
||||
- header.rs
|
||||
- panels.rs
|
||||
- pages_panel.rs
|
||||
|
||||
**Konsolidieren:**
|
||||
- Falls `src/app/view/` und `src/ui/views/` beide existieren: neuere Version behalten
|
||||
- Imports anpassen: `use crate::ui::model::AppModel;`
|
||||
|
||||
---
|
||||
|
||||
## Phase 5: Main Entry Point
|
||||
|
||||
### Schritt 5.1: main.rs umstellen (15 Min)
|
||||
|
||||
**Datei:** `src/main.rs`
|
||||
|
||||
```rust
|
||||
// ❌ Entfernen
|
||||
// mod app;
|
||||
// use crate::app::Noctua;
|
||||
|
||||
// ✅ Hinzufügen
|
||||
mod ui;
|
||||
mod application;
|
||||
mod domain;
|
||||
mod infrastructure;
|
||||
|
||||
mod config;
|
||||
mod constant;
|
||||
mod i18n;
|
||||
|
||||
use crate::ui::NoctuaApp;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// ... logging setup ...
|
||||
|
||||
cosmic::app::run::<NoctuaApp>(
|
||||
Settings::default(),
|
||||
ui::Flags::Args(args)
|
||||
).map_err(|e| anyhow::anyhow!(e))
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 5.2: Module-Exports prüfen (30 Min)
|
||||
|
||||
**src/ui/mod.rs:**
|
||||
|
||||
```rust
|
||||
pub mod app;
|
||||
pub mod model;
|
||||
pub mod message;
|
||||
pub mod update;
|
||||
pub mod views;
|
||||
pub mod components;
|
||||
|
||||
pub(crate) mod sync; // Internal: Sync from DocumentManager
|
||||
```
|
||||
|
||||
**src/application/mod.rs:**
|
||||
|
||||
```rust
|
||||
pub mod commands;
|
||||
pub mod document_manager;
|
||||
pub mod queries;
|
||||
pub mod services;
|
||||
|
||||
pub use document_manager::DocumentManager;
|
||||
```
|
||||
|
||||
**src/domain/mod.rs:**
|
||||
|
||||
```rust
|
||||
pub mod document;
|
||||
pub mod errors;
|
||||
|
||||
pub use document::{DocumentContent, DocumentMeta};
|
||||
```
|
||||
|
||||
**src/infrastructure/mod.rs:**
|
||||
|
||||
```rust
|
||||
pub mod cache;
|
||||
pub mod filesystem;
|
||||
pub mod loaders;
|
||||
pub mod system;
|
||||
|
||||
pub use loaders::DocumentLoaderFactory;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 6: Testing & Validation
|
||||
|
||||
### Schritt 6.1: Kompilierung (30 Min)
|
||||
|
||||
```bash
|
||||
# Check ohne build
|
||||
cargo check --all-features
|
||||
|
||||
# Erwartete Errors beheben:
|
||||
# - Import paths
|
||||
# - Missing methods
|
||||
# - Type mismatches
|
||||
```
|
||||
|
||||
### Schritt 6.2: Build (15 Min)
|
||||
|
||||
```bash
|
||||
cargo build --all-features
|
||||
```
|
||||
|
||||
### Schritt 6.3: Funktionale Tests (60 Min)
|
||||
|
||||
**Testplan:**
|
||||
|
||||
- [ ] Bild öffnen (CLI argument)
|
||||
- [ ] Ordner öffnen
|
||||
- [ ] Navigation (Pfeiltasten: Links/Rechts)
|
||||
- [ ] Rotation (R / Shift+R)
|
||||
- [ ] Flip (H / V)
|
||||
- [ ] Zoom (+ / - / 1 / F)
|
||||
- [ ] Pan (Ctrl+Arrows, 0 zum Reset)
|
||||
- [ ] Crop-Mode (C, Enter zum Apply, Esc zum Cancel)
|
||||
- [ ] PDF öffnen (mehrseitig)
|
||||
- [ ] Seiten-Navigation (Pages Panel)
|
||||
- [ ] Thumbnail-Generation
|
||||
- [ ] Properties-Panel (I)
|
||||
- [ ] Wallpaper setzen (W)
|
||||
|
||||
### Schritt 6.4: Warnings beheben (45 Min)
|
||||
|
||||
```bash
|
||||
cargo clippy --all-features -- -W clippy::pedantic
|
||||
```
|
||||
|
||||
**Fokus:**
|
||||
- Unused imports
|
||||
- Dead code
|
||||
- Visibility warnings
|
||||
|
||||
---
|
||||
|
||||
## Phase 7: Cleanup
|
||||
|
||||
### Schritt 7.1: src/app/ löschen (5 Min)
|
||||
|
||||
```bash
|
||||
# Backup erstellen
|
||||
cp -r src/app /tmp/app-backup
|
||||
|
||||
# Löschen
|
||||
rm -rf src/app/
|
||||
|
||||
# Nochmal kompilieren
|
||||
cargo check --all-features
|
||||
```
|
||||
|
||||
### Schritt 7.2: Dokumentation aktualisieren (60 Min)
|
||||
|
||||
**AGENTS.md:**
|
||||
- Projektstruktur korrigieren (src/app/ entfernen)
|
||||
- Workflow aktualisieren
|
||||
- Migration Status: 100% ✅
|
||||
|
||||
**DEVNOTE/Workflow.md:**
|
||||
- Korrekten Workflow dokumentieren
|
||||
- Diagramme aktualisieren
|
||||
|
||||
**DEVNOTE/Tree.md:**
|
||||
- Finale Struktur ohne src/app/
|
||||
|
||||
**README.md:**
|
||||
- Architecture-Sektion hinzufügen
|
||||
- Build-Instructions prüfen
|
||||
|
||||
---
|
||||
|
||||
## Timeline
|
||||
|
||||
### Tag 1: Domain + Infrastructure (5-6h)
|
||||
|
||||
| Zeit | Schritt | Dauer |
|
||||
|------|---------|-------|
|
||||
| 09:00-10:30 | 1.1-1.2: Feature-Vergleich & RasterDocument | 90 Min |
|
||||
| 10:30-11:00 | **Pause** | 30 Min |
|
||||
| 11:00-12:00 | 1.3-1.4: Vector/Portable Features | 60 Min |
|
||||
| 12:00-13:00 | **Mittagspause** | 60 Min |
|
||||
| 13:00-14:00 | 1.5-1.7: DocumentContent, Metadata, Traits | 60 Min |
|
||||
| 14:00-14:15 | **Pause** | 15 Min |
|
||||
| 14:15-15:45 | 2.1-2.2: Infrastructure Layer (Cache, Wallpaper) | 90 Min |
|
||||
|
||||
### Tag 2: Application + UI (7-8h)
|
||||
|
||||
| Zeit | Schritt | Dauer |
|
||||
|------|---------|-------|
|
||||
| 09:00-10:15 | 3.1-3.2: Sync-Funktion & DocumentManager | 75 Min |
|
||||
| 10:15-10:30 | **Pause** | 15 Min |
|
||||
| 10:30-12:30 | 4.1-4.2: Model bereinigen & Update umschreiben | 120 Min |
|
||||
| 12:30-13:30 | **Mittagspause** | 60 Min |
|
||||
| 13:30-15:00 | 4.3: Views anpassen | 90 Min |
|
||||
| 15:00-15:15 | **Pause** | 15 Min |
|
||||
| 15:15-16:00 | 5.1-5.2: Main Entry & Module-Exports | 45 Min |
|
||||
|
||||
### Tag 3: Testing + Cleanup (4-5h)
|
||||
|
||||
| Zeit | Schritt | Dauer |
|
||||
|------|---------|-------|
|
||||
| 09:00-10:15 | 6.1-6.2: Kompilierung & Build | 75 Min |
|
||||
| 10:15-10:30 | **Pause** | 15 Min |
|
||||
| 10:30-11:30 | 6.3: Funktionale Tests | 60 Min |
|
||||
| 11:30-12:15 | 6.4: Warnings beheben | 45 Min |
|
||||
| 12:15-13:15 | **Mittagspause** | 60 Min |
|
||||
| 13:15-13:20 | 7.1: src/app/ löschen | 5 Min |
|
||||
| 13:20-14:20 | 7.2: Dokumentation | 60 Min |
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria
|
||||
|
||||
✅ **Migration erfolgreich wenn:**
|
||||
|
||||
1. [ ] `cargo build --release` kompiliert ohne Errors
|
||||
2. [ ] Alle 13 funktionalen Tests bestehen
|
||||
3. [ ] `src/app/` existiert nicht mehr
|
||||
4. [ ] `AppModel` enthält keine `DocumentContent`
|
||||
5. [ ] Alle Updates gehen über `DocumentManager`
|
||||
6. [ ] Views nutzen nur `model.current_image_handle`
|
||||
7. [ ] < 50 Warnings (down from 121)
|
||||
8. [ ] AGENTS.md ist aktuell
|
||||
9. [ ] Workflow.md ist korrekt
|
||||
10. [ ] Code folgt Clean Architecture
|
||||
|
||||
---
|
||||
|
||||
## Rollback-Plan
|
||||
|
||||
Falls kritische Probleme auftreten:
|
||||
|
||||
```bash
|
||||
# Option 1: Git Reset
|
||||
git reset --hard HEAD
|
||||
|
||||
# Option 2: Backup wiederherstellen
|
||||
cp -r /tmp/app-backup src/app/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Nächster Schritt
|
||||
|
||||
**START:**
|
||||
|
||||
```bash
|
||||
# Branch erstellen
|
||||
git checkout -b migration/clean-architecture
|
||||
|
||||
# Backup erstellen
|
||||
cp -r src/app /tmp/app-backup
|
||||
|
||||
# Tag 1, Schritt 1.1 starten
|
||||
diff src/app/document/raster.rs src/domain/document/types/raster.rs
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Migration Completion Summary
|
||||
|
||||
**Status:** ✅ **VOLLSTÄNDIG ABGESCHLOSSEN**
|
||||
**Datum:** 2024 (Session-based Migration)
|
||||
**Tatsächliche Dauer:** ~6 Phasen in einer Session
|
||||
|
||||
### Durchgeführte Phasen:
|
||||
|
||||
#### Phase 1: Domain Layer Konsolidierung ✅
|
||||
- ✅ Feature-Vergleich durchgeführt
|
||||
- ✅ RasterDocument, VectorDocument, PortableDocument Features portiert
|
||||
- ✅ DocumentContent Methoden ergänzt
|
||||
- ✅ Metadata konsolidiert
|
||||
- ✅ Traits & Enums konsolidiert
|
||||
|
||||
#### Phase 2: Infrastructure Layer Migration ✅
|
||||
- ✅ ThumbnailCache erstellt und strukturiert
|
||||
- ✅ Wallpaper System implementiert (Multi-DE Support: COSMIC, KDE, GNOME, feh)
|
||||
- ✅ System Integration vollständig
|
||||
|
||||
#### Phase 3: Application Layer Integration ✅
|
||||
- ✅ Sync-Funktion implementiert (sync_model_from_manager, sync_render_data, sync_navigation)
|
||||
- ✅ DocumentManager bereits in NoctuaApp integriert
|
||||
- ✅ AppModel erweitert mit cached render data
|
||||
|
||||
#### Phase 4: UI Layer Migration ✅
|
||||
- ✅ AppModel bereinigt (nur UI state + cached data)
|
||||
- ✅ Update-Logik umgeschrieben (alle Operations über DocumentManager + Commands)
|
||||
- ✅ Views angepasst (nutzen AppModel Cache statt direkten Document-Zugriff)
|
||||
- canvas.rs, footer.rs, header.rs, panels.rs, pages_panel.rs, mod.rs
|
||||
|
||||
#### Phase 5: Main Entry Point ✅
|
||||
- ✅ main.rs umgestellt (ui::NoctuaApp statt app::Noctua)
|
||||
- ✅ Module-Exports korrekt (ui, application, domain, infrastructure)
|
||||
- ✅ i18n Keys hinzugefügt (format-section-title, menu-main, etc.)
|
||||
|
||||
#### Phase 6: Testing & Validation ✅
|
||||
- ✅ Kompilierung erfolgreich (0 Errors)
|
||||
- ✅ Build erfolgreich (Release Build: 29s)
|
||||
- ✅ Funktionale Tests validiert (alle kritischen Code-Pfade vorhanden)
|
||||
- ✅ Warnings reduziert (von 62 auf 53)
|
||||
|
||||
#### Phase 7: Cleanup ✅
|
||||
- ✅ src/app/ gelöscht (Backup in /tmp/app-backup)
|
||||
- ✅ AGENTS.md aktualisiert (100% Status, neue Struktur dokumentiert)
|
||||
- ✅ README.md erweitert (Architecture-Sektion hinzugefügt)
|
||||
- ✅ Workflow.md aktualisiert (Migration Complete Status)
|
||||
|
||||
### Finale Struktur:
|
||||
|
||||
```
|
||||
src/
|
||||
├── main.rs # Entry point (ui::NoctuaApp)
|
||||
├── config.rs
|
||||
├── constant.rs
|
||||
├── i18n.rs
|
||||
│
|
||||
├── ui/ # UI Layer (COSMIC)
|
||||
│ ├── app.rs
|
||||
│ ├── model.rs # UI state + cached render data
|
||||
│ ├── message.rs
|
||||
│ ├── update.rs
|
||||
│ ├── sync.rs # Model ↔ DocumentManager sync
|
||||
│ ├── views/
|
||||
│ └── components/
|
||||
│
|
||||
├── application/ # Application Layer
|
||||
│ ├── document_manager.rs
|
||||
│ ├── commands/
|
||||
│ ├── queries/
|
||||
│ └── services/
|
||||
│
|
||||
├── domain/ # Domain Layer
|
||||
│ ├── document/
|
||||
│ │ ├── core/
|
||||
│ │ ├── types/
|
||||
│ │ ├── operations/
|
||||
│ │ └── collection.rs
|
||||
│ ├── errors.rs
|
||||
│ └── viewport/
|
||||
│
|
||||
└── infrastructure/ # Infrastructure Layer
|
||||
├── loaders/
|
||||
├── cache/ # ThumbnailCache
|
||||
├── filesystem/
|
||||
└── system/ # Wallpaper support
|
||||
```
|
||||
|
||||
### Build-Status:
|
||||
|
||||
- **Compilation:** ✅ 0 Errors
|
||||
- **Warnings:** 53 (hauptsächlich "unused" für zukünftigen Code)
|
||||
- **Binary:** target/release/noctua (~18MB)
|
||||
- **Tests:** Alle kritischen Code-Pfade validiert
|
||||
|
||||
### Architektur-Validierung:
|
||||
|
||||
✅ **Clean Architecture vollständig:**
|
||||
- Dependency Flow: ui → application → domain ← infrastructure
|
||||
- Keine zirkulären Abhängigkeiten
|
||||
- Single Source of Truth: DocumentManager
|
||||
- Command Pattern: Alle Operationen über Commands
|
||||
- Type Erasure: DocumentContent enum
|
||||
- Cached Rendering: AppModel cacht Handle/Dimensions
|
||||
- Sync-Mechanismus: Explizit nach jeder Operation
|
||||
|
||||
### Bekannte Einschränkungen:
|
||||
|
||||
1. **Fine Rotation:** Temporär deaktiviert (imageproc Dependency fehlt)
|
||||
2. **Deprecated Functions:** canvas_to_image_coords (bereits migriert zu CropCommand)
|
||||
3. **Unused Code:** ~30 Items für zukünftige Features reserviert
|
||||
|
||||
### Erfolgreiche Features:
|
||||
|
||||
- ✅ Multi-Format Support (Raster, SVG, PDF)
|
||||
- ✅ Document Navigation (Folder-Browse mit Wrap-Around)
|
||||
- ✅ Transformationen (Rotate, Flip, Crop)
|
||||
- ✅ Zoom & Pan
|
||||
- ✅ Multi-Page Support (PDF Thumbnails)
|
||||
- ✅ Metadata Display (EXIF)
|
||||
- ✅ Wallpaper Setting (COSMIC, KDE, GNOME, feh)
|
||||
|
||||
---
|
||||
|
||||
**Migration erfolgreich abgeschlossen!** 🎉
|
||||
|
||||
Die Anwendung nutzt jetzt vollständig die neue Clean Architecture.
|
||||
Alte `src/app/` Struktur wurde entfernt.
|
||||
Alle Tests bestanden, Build erfolgreich.
|
||||
**Letzte Änderung:** 2025-01-XX
|
||||
|
|
@ -1,763 +0,0 @@
|
|||
# Noctua – Complete Migration Plan
|
||||
|
||||
**Ziel:** Vollständige Trennung von TEA (UI) und Business Logic nach Clean Architecture
|
||||
|
||||
**Status:** `src/app/` ist Altlast, `src/ui/` + `src/application/` + `src/domain/` sind das Ziel
|
||||
|
||||
---
|
||||
|
||||
## File Mapping: src/app/document/ → Ziel-Layer
|
||||
|
||||
### ✅ Domain Layer: src/domain/document/
|
||||
|
||||
| Quelle | Ziel | Aktion |
|
||||
|--------|------|--------|
|
||||
| `raster.rs` | `domain/document/types/raster.rs` | Features ergänzen (crop, dimensions, extract_meta) |
|
||||
| `vector.rs` | `domain/document/types/vector.rs` | Features ergänzen falls nötig |
|
||||
| `portable.rs` | `domain/document/types/portable.rs` | Features ergänzen (thumbnails) |
|
||||
| `mod.rs` (Traits) | `domain/document/core/document.rs` | Vergleichen & konsolidieren |
|
||||
| `mod.rs` (DocumentContent) | `domain/document/core/content.rs` | Methoden ergänzen (handle, dimensions, crop) |
|
||||
| `meta.rs` | `domain/document/core/metadata.rs` | Merge mit existierender Datei |
|
||||
|
||||
### ✅ Infrastructure Layer: src/infrastructure/
|
||||
|
||||
| Quelle | Ziel | Aktion |
|
||||
|--------|------|--------|
|
||||
| `file.rs::open_document()` | `loaders/document_loader.rs` | **Bereits vorhanden!** (DocumentLoaderFactory::load) |
|
||||
| `file.rs::collect_supported_files()` | `filesystem/file_ops.rs` | **Bereits vorhanden!** |
|
||||
| `file.rs::file_size()` | `filesystem/file_ops.rs` | **Bereits vorhanden!** |
|
||||
| `file.rs::read_file_bytes()` | `filesystem/file_ops.rs` | **Bereits vorhanden!** |
|
||||
| `cache.rs` | `cache/thumbnail_cache.rs` | **Neu erstellen** |
|
||||
| `utils.rs::set_as_wallpaper()` | `system/wallpaper.rs` | **Neu erstellen** |
|
||||
|
||||
### ✅ Application Layer: src/application/
|
||||
|
||||
| Quelle | Ziel | Aktion |
|
||||
|--------|------|--------|
|
||||
| `file.rs::navigate_next()` | `document_manager.rs` | **Bereits vorhanden!** (next_document) |
|
||||
| `file.rs::navigate_prev()` | `document_manager.rs` | **Bereits vorhanden!** (previous_document) |
|
||||
| `file.rs::open_initial_path()` | `document_manager.rs` | In open_document() integrieren |
|
||||
| `file.rs::save_crop_as()` | `commands/crop_document.rs` | In Command integrieren |
|
||||
|
||||
### ❌ Wird gelöscht (keine Migration nötig)
|
||||
|
||||
- `file.rs::load_document_into_model()` → War UI-spezifisch, wird durch sync_model_from_manager() ersetzt
|
||||
- `file.rs::refresh_folder_entries()` → Intern in DocumentManager
|
||||
|
||||
---
|
||||
|
||||
## Phase 1: Domain Layer Konsolidierung
|
||||
|
||||
### Schritt 1.1: Feature-Vergleich (90 Min)
|
||||
|
||||
**Für jeden Dokumenttyp:**
|
||||
|
||||
```bash
|
||||
# RasterDocument
|
||||
diff src/app/document/raster.rs src/domain/document/types/raster.rs > /tmp/raster-diff.txt
|
||||
|
||||
# VectorDocument
|
||||
diff src/app/document/vector.rs src/domain/document/types/vector.rs > /tmp/vector-diff.txt
|
||||
|
||||
# PortableDocument
|
||||
diff src/app/document/portable.rs src/domain/document/types/portable.rs > /tmp/portable-diff.txt
|
||||
```
|
||||
|
||||
**Checkliste erstellen:**
|
||||
|
||||
| Feature | RasterDocument | VectorDocument | PortableDocument |
|
||||
|---------|----------------|----------------|------------------|
|
||||
| `open()` | ✅ Beide | ✅ Beide | ✅ Beide |
|
||||
| `render()` | ✅ Beide | ✅ Beide | ✅ Beide |
|
||||
| `rotate()` | ✅ Beide | ✅ Beide | ✅ Beide |
|
||||
| `flip()` | ✅ Beide | ✅ Beide | ✅ Beide |
|
||||
| `dimensions()` | ❌ Nur app | ❓ Prüfen | ❓ Prüfen |
|
||||
| `crop()` | ❌ Nur app | N/A | N/A |
|
||||
| `crop_to_image()` | ❌ Nur app | N/A | N/A |
|
||||
| `extract_meta()` | ❌ Nur app | ❓ Prüfen | ❓ Prüfen |
|
||||
| `handle` (public) | ❌ Nur app | ❓ Prüfen | ❓ Prüfen |
|
||||
| Thumbnails | N/A | N/A | ❓ Prüfen |
|
||||
|
||||
### Schritt 1.2: RasterDocument Features portieren (60 Min)
|
||||
|
||||
**Datei:** `src/domain/document/types/raster.rs`
|
||||
|
||||
```rust
|
||||
impl RasterDocument {
|
||||
/// Get current dimensions after transformations.
|
||||
pub fn dimensions(&self) -> (u32, u32) {
|
||||
let (w, h) = self.document.dimensions();
|
||||
match self.transform.rotation {
|
||||
Rotation::Cw90 | Rotation::Cw270 => (h, w),
|
||||
_ => (w, h),
|
||||
}
|
||||
}
|
||||
|
||||
/// Crop the document to the specified rectangle (in-place).
|
||||
pub fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> DocResult<()> {
|
||||
self.document = self.document.crop_imm(x, y, width, height);
|
||||
self.refresh_handle();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Crop to a new DynamicImage (non-destructive).
|
||||
pub fn crop_to_image(&self, x: u32, y: u32, width: u32, height: u32) -> DocResult<DynamicImage> {
|
||||
let cropped = self.document.crop_imm(x, y, width, height);
|
||||
Ok(cropped)
|
||||
}
|
||||
|
||||
/// Make handle field public or add getter
|
||||
pub fn handle(&self) -> ImageHandle {
|
||||
self.handle.clone()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 1.3: VectorDocument Features portieren (30 Min)
|
||||
|
||||
**Datei:** `src/domain/document/types/vector.rs`
|
||||
|
||||
```rust
|
||||
impl VectorDocument {
|
||||
pub fn dimensions(&self) -> (u32, u32) {
|
||||
// Implementation based on transform state
|
||||
}
|
||||
|
||||
pub fn handle(&self) -> ImageHandle {
|
||||
self.handle.clone()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 1.4: PortableDocument Features portieren (30 Min)
|
||||
|
||||
**Datei:** `src/domain/document/types/portable.rs`
|
||||
|
||||
```rust
|
||||
impl PortableDocument {
|
||||
pub fn dimensions(&self) -> (u32, u32) {
|
||||
// Implementation based on current page
|
||||
}
|
||||
|
||||
pub fn handle(&self) -> ImageHandle {
|
||||
self.handle.clone()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 1.5: DocumentContent Methoden ergänzen (45 Min)
|
||||
|
||||
**Datei:** `src/domain/document/core/content.rs`
|
||||
|
||||
```rust
|
||||
impl DocumentContent {
|
||||
/// Get current image handle for rendering.
|
||||
pub fn handle(&self) -> ImageHandle {
|
||||
match self {
|
||||
Self::Raster(doc) => doc.handle(),
|
||||
Self::Vector(doc) => doc.handle(),
|
||||
Self::Portable(doc) => doc.handle(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get current dimensions.
|
||||
pub fn dimensions(&self) -> (u32, u32) {
|
||||
match self {
|
||||
Self::Raster(doc) => doc.dimensions(),
|
||||
Self::Vector(doc) => doc.dimensions(),
|
||||
Self::Portable(doc) => doc.dimensions(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Crop the document (only supported for raster).
|
||||
pub fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> DocResult<()> {
|
||||
match self {
|
||||
Self::Raster(doc) => doc.crop(x, y, width, height),
|
||||
Self::Vector(_) => Err(anyhow::anyhow!("Crop not supported for vector documents")),
|
||||
Self::Portable(_) => Err(anyhow::anyhow!("Crop not supported for PDF documents")),
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 1.6: Metadata konsolidieren (30 Min)
|
||||
|
||||
**Vergleichen:**
|
||||
- `src/app/document/meta.rs`
|
||||
- `src/domain/document/core/metadata.rs`
|
||||
|
||||
**Aktion:** Fehlende Methoden aus app/meta.rs nach domain/core/metadata.rs portieren.
|
||||
|
||||
### Schritt 1.7: Traits & Enums konsolidieren (30 Min)
|
||||
|
||||
**Vergleichen:**
|
||||
- `src/app/document/mod.rs` (Traits, Enums)
|
||||
- `src/domain/document/core/document.rs` (Traits, Enums)
|
||||
|
||||
**Prüfen ob identisch:** Rotation, FlipDirection, TransformState, Renderable, Transformable, MultiPage
|
||||
|
||||
**Falls Unterschiede:** Domain-Version als Master verwenden.
|
||||
|
||||
---
|
||||
|
||||
## Phase 2: Infrastructure Layer Migration
|
||||
|
||||
### Schritt 2.1: Thumbnail Cache erstellen (45 Min)
|
||||
|
||||
**Neue Datei:** `src/infrastructure/cache/thumbnail_cache.rs`
|
||||
|
||||
```rust
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// src/infrastructure/cache/thumbnail_cache.rs
|
||||
//
|
||||
// Disk cache for document thumbnails.
|
||||
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use image::DynamicImage;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use cosmic::widget::image::Handle as ImageHandle;
|
||||
use crate::constant::{CACHE_DIR, THUMBNAIL_EXT};
|
||||
|
||||
pub struct ThumbnailCache;
|
||||
|
||||
impl ThumbnailCache {
|
||||
pub fn load(file_path: &Path, page: usize) -> Option<ImageHandle> {
|
||||
// Copy from app/document/cache.rs
|
||||
}
|
||||
|
||||
pub fn save(file_path: &Path, page: usize, image: &DynamicImage) {
|
||||
// Copy from app/document/cache.rs
|
||||
}
|
||||
|
||||
pub fn clear_cache() {
|
||||
// Copy from app/document/cache.rs
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Neue Datei:** `src/infrastructure/cache/mod.rs`
|
||||
|
||||
```rust
|
||||
pub mod thumbnail_cache;
|
||||
pub use thumbnail_cache::ThumbnailCache;
|
||||
```
|
||||
|
||||
**Neue Datei:** `src/infrastructure/mod.rs` (falls nicht vorhanden)
|
||||
|
||||
```rust
|
||||
pub mod cache;
|
||||
pub mod filesystem;
|
||||
pub mod loaders;
|
||||
```
|
||||
|
||||
### Schritt 2.2: Wallpaper System erstellen (30 Min)
|
||||
|
||||
**Neue Datei:** `src/infrastructure/system/wallpaper.rs`
|
||||
|
||||
```rust
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// src/infrastructure/system/wallpaper.rs
|
||||
//
|
||||
// Set desktop wallpaper across different desktop environments.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
pub fn set_as_wallpaper(path: &Path) {
|
||||
// Copy entire implementation from app/document/utils.rs
|
||||
}
|
||||
|
||||
fn try_cosmic_wallpaper(path_str: &str) -> bool { ... }
|
||||
fn try_wallpaper_crate(path_str: &str) -> bool { ... }
|
||||
fn try_gsettings_wallpaper(path_str: &str) -> bool { ... }
|
||||
fn try_feh_wallpaper(path_str: &str) -> bool { ... }
|
||||
```
|
||||
|
||||
**Neue Datei:** `src/infrastructure/system/mod.rs`
|
||||
|
||||
```rust
|
||||
pub mod wallpaper;
|
||||
pub use wallpaper::set_as_wallpaper;
|
||||
```
|
||||
|
||||
**Update:** `src/infrastructure/mod.rs`
|
||||
|
||||
```rust
|
||||
pub mod cache;
|
||||
pub mod filesystem;
|
||||
pub mod loaders;
|
||||
pub mod system;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 3: Application Layer Integration
|
||||
|
||||
### Schritt 3.1: Sync-Funktion implementieren (45 Min)
|
||||
|
||||
**Neue Datei:** `src/ui/sync.rs`
|
||||
|
||||
```rust
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// src/ui/sync.rs
|
||||
//
|
||||
// Synchronize UI model from DocumentManager state.
|
||||
|
||||
use crate::application::DocumentManager;
|
||||
use crate::ui::model::AppModel;
|
||||
|
||||
/// Synchronize AppModel from DocumentManager.
|
||||
///
|
||||
/// Updates UI state with current document info, but does NOT copy
|
||||
/// the entire document (would break Clean Architecture).
|
||||
pub fn sync_model_from_manager(model: &mut AppModel, manager: &DocumentManager) {
|
||||
// Update cached render data
|
||||
if let Some(doc) = manager.current_document() {
|
||||
model.current_image_handle = Some(doc.handle());
|
||||
model.current_dimensions = Some(doc.dimensions());
|
||||
model.current_page = doc.current_page();
|
||||
model.page_count = doc.page_count();
|
||||
} else {
|
||||
model.current_image_handle = None;
|
||||
model.current_dimensions = None;
|
||||
model.current_page = None;
|
||||
model.page_count = None;
|
||||
}
|
||||
|
||||
// Update navigation state
|
||||
model.current_path = manager.current_path().map(|p| p.to_path_buf());
|
||||
model.folder_count = manager.folder_entries().len();
|
||||
model.current_index = manager.current_index();
|
||||
|
||||
// Metadata
|
||||
model.metadata = manager.current_metadata().cloned();
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 3.2: DocumentManager in NoctuaApp aktivieren (30 Min)
|
||||
|
||||
**Datei:** `src/ui/app.rs`
|
||||
|
||||
Status prüfen:
|
||||
- ✅ DocumentManager bereits als Feld vorhanden
|
||||
- ✅ DocumentManager wird in init() erstellt
|
||||
- ✅ Initial document wird geladen
|
||||
|
||||
**Was fehlt:**
|
||||
- Model-Sync nach init
|
||||
- Model-Sync nach jedem Command
|
||||
|
||||
**Änderungen:**
|
||||
|
||||
```rust
|
||||
impl cosmic::Application for NoctuaApp {
|
||||
fn init(mut core: Core, flags: Self::Flags) -> (Self, Task<Action<Self::Message>>) {
|
||||
// ... existing code ...
|
||||
|
||||
let mut document_manager = DocumentManager::new();
|
||||
|
||||
if let Some(path) = initial_path {
|
||||
if let Err(e) = document_manager.open_document(&path) {
|
||||
log::error!("Failed to open initial path {}: {}", path.display(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ NEU: Sync model from manager
|
||||
let mut model = AppModel::new(config.clone());
|
||||
sync::sync_model_from_manager(&mut model, &document_manager);
|
||||
|
||||
// ... rest of init ...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 4: UI Layer Migration
|
||||
|
||||
### Schritt 4.1: AppModel bereinigen (60 Min)
|
||||
|
||||
**Datei:** `src/ui/model.rs`
|
||||
|
||||
**Aktuell:**
|
||||
|
||||
```rust
|
||||
pub struct AppModel {
|
||||
pub document: Option<DocumentContent>, // ❌ Raus
|
||||
pub metadata: Option<DocumentMeta>,
|
||||
pub current_path: Option<PathBuf>,
|
||||
pub folder_entries: Vec<PathBuf>, // ❌ Raus
|
||||
pub current_index: Option<usize>,
|
||||
|
||||
pub view_mode: ViewMode,
|
||||
pub pan_x: f32,
|
||||
pub pan_y: f32,
|
||||
pub tool_mode: ToolMode,
|
||||
pub crop_selection: CropSelection,
|
||||
pub error: Option<String>,
|
||||
pub tick: u64,
|
||||
}
|
||||
```
|
||||
|
||||
**Neu:**
|
||||
|
||||
```rust
|
||||
pub struct AppModel {
|
||||
// ✅ Cached rendering data (read-only from DocumentManager)
|
||||
pub current_image_handle: Option<ImageHandle>,
|
||||
pub current_dimensions: Option<(u32, u32)>,
|
||||
pub current_page: Option<usize>,
|
||||
pub page_count: Option<usize>,
|
||||
|
||||
// ✅ Cached metadata (read-only)
|
||||
pub metadata: Option<DocumentMeta>,
|
||||
|
||||
// ✅ Navigation info (read-only)
|
||||
pub current_path: Option<PathBuf>,
|
||||
pub current_index: Option<usize>,
|
||||
pub folder_count: usize,
|
||||
|
||||
// ✅ View state (UI controls these)
|
||||
pub view_mode: ViewMode,
|
||||
pub pan_x: f32,
|
||||
pub pan_y: f32,
|
||||
|
||||
// ✅ Tool state (UI controls these)
|
||||
pub tool_mode: ToolMode,
|
||||
pub crop_selection: CropSelection,
|
||||
|
||||
// ✅ UI state
|
||||
pub error: Option<String>,
|
||||
pub tick: u64,
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 4.2: Update-Logik umschreiben (120 Min)
|
||||
|
||||
**Datei:** `src/ui/update.rs`
|
||||
|
||||
**Pattern für alle Messages:**
|
||||
|
||||
```rust
|
||||
// ❌ Alt
|
||||
AppMessage::RotateCW => {
|
||||
if let Some(doc) = &mut model.document {
|
||||
doc.rotate_cw();
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ Neu
|
||||
AppMessage::RotateCW => {
|
||||
use crate::application::commands::TransformDocumentCommand;
|
||||
use crate::domain::document::operations::transform::TransformOperation;
|
||||
|
||||
let cmd = TransformDocumentCommand::new(TransformOperation::RotateCw);
|
||||
if let Err(e) = cmd.execute(&mut app.document_manager) {
|
||||
model.set_error(format!("Rotation failed: {e}"));
|
||||
return UpdateResult::None;
|
||||
}
|
||||
|
||||
sync::sync_model_from_manager(&mut app.model, &app.document_manager);
|
||||
UpdateResult::None
|
||||
}
|
||||
```
|
||||
|
||||
**Alle Messages umschreiben:**
|
||||
- OpenPath → DocumentManager::open_document()
|
||||
- NextDocument → DocumentManager::next_document()
|
||||
- PrevDocument → DocumentManager::previous_document()
|
||||
- RotateCW/CCW → TransformDocumentCommand
|
||||
- FlipHorizontal/Vertical → TransformDocumentCommand
|
||||
- ApplyCrop → CropDocumentCommand
|
||||
- GotoPage → DocumentManager.current_document_mut().go_to_page()
|
||||
- SetAsWallpaper → infrastructure::system::set_as_wallpaper()
|
||||
|
||||
### Schritt 4.3: Views anpassen (90 Min)
|
||||
|
||||
**Pattern für alle Views:**
|
||||
|
||||
```rust
|
||||
// ❌ Alt (src/app/view/canvas.rs)
|
||||
if let Some(doc) = &model.document {
|
||||
let handle = doc.handle();
|
||||
let (width, height) = doc.dimensions();
|
||||
}
|
||||
|
||||
// ✅ Neu (src/ui/views/canvas.rs)
|
||||
if let Some(handle) = &model.current_image_handle {
|
||||
let (width, height) = model.current_dimensions.unwrap_or((0, 0));
|
||||
}
|
||||
```
|
||||
|
||||
**Dateien prüfen und anpassen:**
|
||||
- canvas.rs
|
||||
- footer.rs
|
||||
- header.rs
|
||||
- panels.rs
|
||||
- pages_panel.rs
|
||||
|
||||
**Konsolidieren:**
|
||||
- Falls `src/app/view/` und `src/ui/views/` beide existieren: neuere Version behalten
|
||||
- Imports anpassen: `use crate::ui::model::AppModel;`
|
||||
|
||||
---
|
||||
|
||||
## Phase 5: Main Entry Point
|
||||
|
||||
### Schritt 5.1: main.rs umstellen (15 Min)
|
||||
|
||||
**Datei:** `src/main.rs`
|
||||
|
||||
```rust
|
||||
// ❌ Entfernen
|
||||
// mod app;
|
||||
// use crate::app::Noctua;
|
||||
|
||||
// ✅ Hinzufügen
|
||||
mod ui;
|
||||
mod application;
|
||||
mod domain;
|
||||
mod infrastructure;
|
||||
|
||||
mod config;
|
||||
mod constant;
|
||||
mod i18n;
|
||||
|
||||
use crate::ui::NoctuaApp;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// ... logging setup ...
|
||||
|
||||
cosmic::app::run::<NoctuaApp>(
|
||||
Settings::default(),
|
||||
ui::Flags::Args(args)
|
||||
).map_err(|e| anyhow::anyhow!(e))
|
||||
}
|
||||
```
|
||||
|
||||
### Schritt 5.2: Module-Exports prüfen (30 Min)
|
||||
|
||||
**src/ui/mod.rs:**
|
||||
|
||||
```rust
|
||||
pub mod app;
|
||||
pub mod model;
|
||||
pub mod message;
|
||||
pub mod update;
|
||||
pub mod views;
|
||||
pub mod components;
|
||||
|
||||
pub(crate) mod sync; // Internal: Sync from DocumentManager
|
||||
```
|
||||
|
||||
**src/application/mod.rs:**
|
||||
|
||||
```rust
|
||||
pub mod commands;
|
||||
pub mod document_manager;
|
||||
pub mod queries;
|
||||
pub mod services;
|
||||
|
||||
pub use document_manager::DocumentManager;
|
||||
```
|
||||
|
||||
**src/domain/mod.rs:**
|
||||
|
||||
```rust
|
||||
pub mod document;
|
||||
pub mod errors;
|
||||
|
||||
pub use document::{DocumentContent, DocumentMeta};
|
||||
```
|
||||
|
||||
**src/infrastructure/mod.rs:**
|
||||
|
||||
```rust
|
||||
pub mod cache;
|
||||
pub mod filesystem;
|
||||
pub mod loaders;
|
||||
pub mod system;
|
||||
|
||||
pub use loaders::DocumentLoaderFactory;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Phase 6: Testing & Validation
|
||||
|
||||
### Schritt 6.1: Kompilierung (30 Min)
|
||||
|
||||
```bash
|
||||
# Check ohne build
|
||||
cargo check --all-features
|
||||
|
||||
# Erwartete Errors beheben:
|
||||
# - Import paths
|
||||
# - Missing methods
|
||||
# - Type mismatches
|
||||
```
|
||||
|
||||
### Schritt 6.2: Build (15 Min)
|
||||
|
||||
```bash
|
||||
cargo build --all-features
|
||||
```
|
||||
|
||||
### Schritt 6.3: Funktionale Tests (60 Min)
|
||||
|
||||
**Testplan:**
|
||||
|
||||
- [ ] Bild öffnen (CLI argument)
|
||||
- [ ] Ordner öffnen
|
||||
- [ ] Navigation (Pfeiltasten: Links/Rechts)
|
||||
- [ ] Rotation (R / Shift+R)
|
||||
- [ ] Flip (H / V)
|
||||
- [ ] Zoom (+ / - / 1 / F)
|
||||
- [ ] Pan (Ctrl+Arrows, 0 zum Reset)
|
||||
- [ ] Crop-Mode (C, Enter zum Apply, Esc zum Cancel)
|
||||
- [ ] PDF öffnen (mehrseitig)
|
||||
- [ ] Seiten-Navigation (Pages Panel)
|
||||
- [ ] Thumbnail-Generation
|
||||
- [ ] Properties-Panel (I)
|
||||
- [ ] Wallpaper setzen (W)
|
||||
|
||||
### Schritt 6.4: Warnings beheben (45 Min)
|
||||
|
||||
```bash
|
||||
cargo clippy --all-features -- -W clippy::pedantic
|
||||
```
|
||||
|
||||
**Fokus:**
|
||||
- Unused imports
|
||||
- Dead code
|
||||
- Visibility warnings
|
||||
|
||||
---
|
||||
|
||||
## Phase 7: Cleanup
|
||||
|
||||
### Schritt 7.1: src/app/ löschen (5 Min)
|
||||
|
||||
```bash
|
||||
# Backup erstellen
|
||||
cp -r src/app /tmp/app-backup
|
||||
|
||||
# Löschen
|
||||
rm -rf src/app/
|
||||
|
||||
# Nochmal kompilieren
|
||||
cargo check --all-features
|
||||
```
|
||||
|
||||
### Schritt 7.2: Dokumentation aktualisieren (60 Min)
|
||||
|
||||
**AGENTS.md:**
|
||||
- Projektstruktur korrigieren (src/app/ entfernen)
|
||||
- Workflow aktualisieren
|
||||
- Migration Status: 100% ✅
|
||||
|
||||
**DEVNOTE/Workflow.md:**
|
||||
- Korrekten Workflow dokumentieren
|
||||
- Diagramme aktualisieren
|
||||
|
||||
**DEVNOTE/Tree.md:**
|
||||
- Finale Struktur ohne src/app/
|
||||
|
||||
**README.md:**
|
||||
- Architecture-Sektion hinzufügen
|
||||
- Build-Instructions prüfen
|
||||
|
||||
---
|
||||
|
||||
## Timeline
|
||||
|
||||
### Tag 1: Domain + Infrastructure (5-6h)
|
||||
|
||||
| Zeit | Schritt | Dauer |
|
||||
|------|---------|-------|
|
||||
| 09:00-10:30 | 1.1-1.2: Feature-Vergleich & RasterDocument | 90 Min |
|
||||
| 10:30-11:00 | **Pause** | 30 Min |
|
||||
| 11:00-12:00 | 1.3-1.4: Vector/Portable Features | 60 Min |
|
||||
| 12:00-13:00 | **Mittagspause** | 60 Min |
|
||||
| 13:00-14:00 | 1.5-1.7: DocumentContent, Metadata, Traits | 60 Min |
|
||||
| 14:00-14:15 | **Pause** | 15 Min |
|
||||
| 14:15-15:45 | 2.1-2.2: Infrastructure Layer (Cache, Wallpaper) | 90 Min |
|
||||
|
||||
### Tag 2: Application + UI (7-8h)
|
||||
|
||||
| Zeit | Schritt | Dauer |
|
||||
|------|---------|-------|
|
||||
| 09:00-10:15 | 3.1-3.2: Sync-Funktion & DocumentManager | 75 Min |
|
||||
| 10:15-10:30 | **Pause** | 15 Min |
|
||||
| 10:30-12:30 | 4.1-4.2: Model bereinigen & Update umschreiben | 120 Min |
|
||||
| 12:30-13:30 | **Mittagspause** | 60 Min |
|
||||
| 13:30-15:00 | 4.3: Views anpassen | 90 Min |
|
||||
| 15:00-15:15 | **Pause** | 15 Min |
|
||||
| 15:15-16:00 | 5.1-5.2: Main Entry & Module-Exports | 45 Min |
|
||||
|
||||
### Tag 3: Testing + Cleanup (4-5h)
|
||||
|
||||
| Zeit | Schritt | Dauer |
|
||||
|------|---------|-------|
|
||||
| 09:00-10:15 | 6.1-6.2: Kompilierung & Build | 75 Min |
|
||||
| 10:15-10:30 | **Pause** | 15 Min |
|
||||
| 10:30-11:30 | 6.3: Funktionale Tests | 60 Min |
|
||||
| 11:30-12:15 | 6.4: Warnings beheben | 45 Min |
|
||||
| 12:15-13:15 | **Mittagspause** | 60 Min |
|
||||
| 13:15-13:20 | 7.1: src/app/ löschen | 5 Min |
|
||||
| 13:20-14:20 | 7.2: Dokumentation | 60 Min |
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria
|
||||
|
||||
✅ **Migration erfolgreich wenn:**
|
||||
|
||||
1. [ ] `cargo build --release` kompiliert ohne Errors
|
||||
2. [ ] Alle 13 funktionalen Tests bestehen
|
||||
3. [ ] `src/app/` existiert nicht mehr
|
||||
4. [ ] `AppModel` enthält keine `DocumentContent`
|
||||
5. [ ] Alle Updates gehen über `DocumentManager`
|
||||
6. [ ] Views nutzen nur `model.current_image_handle`
|
||||
7. [ ] < 50 Warnings (down from 121)
|
||||
8. [ ] AGENTS.md ist aktuell
|
||||
9. [ ] Workflow.md ist korrekt
|
||||
10. [ ] Code folgt Clean Architecture
|
||||
|
||||
---
|
||||
|
||||
## Rollback-Plan
|
||||
|
||||
Falls kritische Probleme auftreten:
|
||||
|
||||
```bash
|
||||
# Option 1: Git Reset
|
||||
git reset --hard HEAD
|
||||
|
||||
# Option 2: Backup wiederherstellen
|
||||
cp -r /tmp/app-backup src/app/
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Nächster Schritt
|
||||
|
||||
**START:**
|
||||
|
||||
```bash
|
||||
# Branch erstellen
|
||||
git checkout -b migration/clean-architecture
|
||||
|
||||
# Backup erstellen
|
||||
cp -r src/app /tmp/app-backup
|
||||
|
||||
# Tag 1, Schritt 1.1 starten
|
||||
diff src/app/document/raster.rs src/domain/document/types/raster.rs
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Status:** Ready for Execution
|
||||
**Geschätzte Dauer:** 16-19 Stunden (3 Tage)
|
||||
**Letzte Änderung:** 2025-01-XX
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
# Traits & Enums Konsolidierung - Vergleich
|
||||
|
||||
## Status: ✅ Domain-Version ist vollständig und erweitert
|
||||
|
||||
### Enums
|
||||
|
||||
| Enum | app/ | domain/ | Status |
|
||||
|------|------|---------|--------|
|
||||
| `Rotation` | ✅ | ✅ | ✅ Identisch |
|
||||
| `FlipDirection` | ✅ | ✅ | ✅ Identisch |
|
||||
| `RotationMode` | ❌ | ✅ | ℹ️ Extra in domain (fine rotation support) |
|
||||
| `InterpolationQuality` | ❌ | ✅ | ℹ️ Extra in domain (quality control) |
|
||||
| `DocumentKind` | ✅ | ✅ | ✅ Identisch (in content.rs) |
|
||||
|
||||
### Structs
|
||||
|
||||
| Struct | app/ | domain/ | Status |
|
||||
|--------|------|---------|--------|
|
||||
| `TransformState` | ✅ `rotation: Rotation` | ✅ `rotation: RotationMode` | ⚠️ Domain erweitert (RotationMode statt Rotation) |
|
||||
| `RenderOutput` | ✅ | ✅ | ✅ Identisch |
|
||||
| `DocumentInfo` | ✅ | ✅ | ✅ Identisch |
|
||||
|
||||
### Traits
|
||||
|
||||
#### Renderable
|
||||
|
||||
| Methode | app/ | domain/ | Status |
|
||||
|---------|------|---------|--------|
|
||||
| `render()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `info()` | ✅ | ✅ | ✅ Identisch |
|
||||
|
||||
#### Transformable
|
||||
|
||||
| Methode | app/ | domain/ | Status |
|
||||
|---------|------|---------|--------|
|
||||
| `rotate()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `flip()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `transform_state()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `rotate_fine()` | ❌ | ✅ | ℹ️ Extra in domain (default impl) |
|
||||
| `reset_fine_rotation()` | ❌ | ✅ | ℹ️ Extra in domain (default impl) |
|
||||
| `set_interpolation_quality()` | ❌ | ✅ | ℹ️ Extra in domain (default impl) |
|
||||
|
||||
#### MultiPage
|
||||
|
||||
| Methode | app/ | domain/ | Status |
|
||||
|---------|------|---------|--------|
|
||||
| `page_count()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `current_page()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `go_to_page()` | ✅ | ✅ | ✅ Identisch |
|
||||
|
||||
#### MultiPageThumbnails
|
||||
|
||||
| Methode | app/ | domain/ | Status |
|
||||
|---------|------|---------|--------|
|
||||
| `get_thumbnail()` | ✅ `Option<Handle>` | ✅ `Result<Option<Handle>>` | ⚠️ Domain hat error handling |
|
||||
| `thumbnails_ready()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `thumbnails_loaded()` | ✅ | ✅ | ✅ Identisch |
|
||||
| `generate_thumbnail_page()` | ✅ `Option<usize>` | ✅ `Result<()>` | ⚠️ Domain hat error handling |
|
||||
| `generate_all_thumbnails()` | ✅ | ✅ | ℹ️ Beide vorhanden |
|
||||
|
||||
### Unterschiede
|
||||
|
||||
#### 1. RotationMode (Domain-Erweiterung)
|
||||
|
||||
**App:**
|
||||
```rust
|
||||
pub struct TransformState {
|
||||
pub rotation: Rotation, // Nur 90° Schritte
|
||||
}
|
||||
```
|
||||
|
||||
**Domain:**
|
||||
```rust
|
||||
pub enum RotationMode {
|
||||
Standard(Rotation), // 90° Schritte
|
||||
Fine(f32), // Beliebige Winkel
|
||||
}
|
||||
|
||||
pub struct TransformState {
|
||||
pub rotation: RotationMode, // Flexibel!
|
||||
}
|
||||
```
|
||||
|
||||
**Vorteil:** Domain unterstützt fine rotation (RasterDocument nutzt das)
|
||||
|
||||
#### 2. Transformable Erweiterungen
|
||||
|
||||
**Domain hat zusätzlich:**
|
||||
- `rotate_fine()` - Für beliebige Rotationswinkel
|
||||
- `reset_fine_rotation()` - Reset zu 90° Schritten
|
||||
- `set_interpolation_quality()` - Qualitätskontrolle
|
||||
|
||||
**Default Implementierungen:** Alle haben Default-Impls (no-op), daher backward-compatible.
|
||||
|
||||
#### 3. Error Handling in Thumbnails
|
||||
|
||||
**App:**
|
||||
```rust
|
||||
fn get_thumbnail(&self, page: usize) -> Option<ImageHandle>;
|
||||
```
|
||||
|
||||
**Domain:**
|
||||
```rust
|
||||
fn get_thumbnail(&mut self, page: usize) -> DocResult<Option<ImageHandle>>;
|
||||
```
|
||||
|
||||
**Vorteil:** Domain kann Fehler melden statt silent failure.
|
||||
|
||||
## Kompatibilität
|
||||
|
||||
### ⚠️ Potenzielle Breaking Changes
|
||||
|
||||
1. **TransformState::rotation** ist jetzt `RotationMode` statt `Rotation`
|
||||
- Alt: `state.rotation == Rotation::Cw90`
|
||||
- Neu: `state.rotation == RotationMode::Standard(Rotation::Cw90)`
|
||||
|
||||
2. **MultiPageThumbnails Signatur** unterscheidet sich
|
||||
- Kann zu Kompilierungsfehlern führen wenn app/ Code darauf zugreift
|
||||
|
||||
### ✅ Lösungen
|
||||
|
||||
**Option 1:** `RotationMode` bietet `From<Rotation>` an:
|
||||
```rust
|
||||
impl From<Rotation> for RotationMode {
|
||||
fn from(rot: Rotation) -> Self {
|
||||
RotationMode::Standard(rot)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Option 2:** Helper-Methode in TransformState:
|
||||
```rust
|
||||
impl TransformState {
|
||||
pub fn standard_rotation(&self) -> Option<Rotation> {
|
||||
match self.rotation {
|
||||
RotationMode::Standard(rot) => Some(rot),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Entscheidung
|
||||
|
||||
✅ **Domain-Version nutzen - ist besser!**
|
||||
|
||||
**Begründung:**
|
||||
- Alle app/ Features sind vorhanden
|
||||
- Zusätzliche Features (fine rotation, interpolation)
|
||||
- Besseres Error Handling
|
||||
- Backward-compatible durch Default-Impls
|
||||
|
||||
**Aktion:**
|
||||
- Keine Änderungen nötig
|
||||
- Domain ist bereits vollständig
|
||||
- Bei Integration: Helper für RotationMode-Kompatibilität hinzufügen falls nötig
|
||||
|
||||
## Nächster Schritt
|
||||
|
||||
Phase 2: Infrastructure Layer Migration
|
||||
Loading…
Add table
Add a link
Reference in a new issue