A comprehensive technical documentation guide for the Rust desktop downloader application.
This documentation is written in English and follows rustdoc writing principles for clear summaries, layered detail, and practical guidance.
- 1. Overview
- 2. High-Level Architecture
- 3. Runtime and Application Lifecycle
- 4. UI Architecture and Interaction Flow
- 5. Download Backends
- 6. Download Artifacts and File Layout
- 7. Progress, Speed, and ETA Model
- 8. Pause, Resume, and Cancel Semantics
- 9. Error Handling and Reliability
- 10. Localization
- 11. Icons, Fonts, and Visual Behavior
- 12. Module Reference
- 13. Build and Run
- 14. Testing Scenarios
- 15. Known Tradeoffs
CodexRustDownload is a native desktop downloader built with egui/eframe and tokio.
It supports:
- Product selection from a remote API.
- Resumable chunk-based downloads.
- Multiple backends (HTTP and Azure Blob SDK alternative path).
- Pause / Resume / Cancel lifecycle operations.
- Progress reporting with stabilized ETA.
- Download integrity verification via hash checks.
The application is optimized for practical installer distribution workflows where reliability, resumability, and a responsive UI are required.
The system is organized into 3 main layers:
-
UI Layer (
app.rs,app/actions.rs)- Renders controls, status, and dialogs.
- Handles user actions and UI state transitions.
- Polls async channels/handles and reacts to terminal statuses.
-
Download Orchestration Layer (
downloader.rs)- Exposes start APIs and backend selection.
- Manages progress channels and task spawning.
- Coordinates retry loops and lifecycle transitions.
-
Backend/Execution Layer (
downloader/*)- HTTP chunk worker, assembly, verify, retry helpers.
- Azure SDK architecture path (service-style decomposition).
- File artifact management (
.partN,.download_info).
Entry point: src/main.rs
- Initialize logging (stderr sink).
- Build a multithread Tokio runtime.
- Configure native viewport (title, size, icon).
- Apply custom font stack to egui context.
- Start
Codex365App.
The runtime is intentionally not entered on the UI thread to avoid event-loop contention between Tokio IO drivers and window message pumping on Windows.
This keeps the app responsive during intensive async activity.
Primary UI state is stored in Codex365App:
- API loading phase (
LoadingApi,Ready,ApiError). - Selected product and backend.
- Active
DownloadHandle(or terminal cached status). - Timing information (
download_start,download_elapsed). - Dialog flags and error messaging.
- App loads product catalog from API asynchronously.
- User selects product, method, and folder.
- User starts download.
- UI polls progress handle each frame.
- Terminal states (
Done,Failed,Cancelled) update UI and cleanup behavior.
Backend enum: DownloaderBackend
HttpAzureBlobSdk
Selection is done via UI ComboBox in the Status/Controls section.
Implemented by downloader.rs + downloader/chunk_worker.rs.
Key characteristics:
- Parallel range requests over HTTP.
- Per-chunk resumability based on existing
.partNsize. - Chunk worker cancellation and pause-aware loops.
- Retry wrapper with backoff for transient failures.
Implemented in downloader/azure_blob_sdk.rs with a Core-style decomposition:
AzureDownloadConfigurationAzureBlobStorageServiceAzureStateRepositoryAzureDownloadService
Key characteristics:
- Uses token credential chain (Azure Identity) and Blob SDK client.
- Parallel ranged chunk retrieval.
- State snapshot writes to
.download_info. - Reuses shared assembly and verification modules.
For a selected file <filename> in selected download directory:
<filename>.part0<filename>.part1- ...
<filename>.partN<filename>.download_info
Behavior:
.partNfiles are partial chunk data..download_infois state/progress artifact.- On successful assembly and completion, final target file is produced.
- On cancel, cleanup removes
.partN,.download_info, and legacy temp artifacts.
Progress type: DownloadProgress.
Fields include:
bytes_donetotal_bytesspeed_bpseta_secsstatus
ETA uses elapsed-time average speed:
avg_speed = bytes_done / elapsed_totaleta = remaining / avg_speed
This avoids heavy fluctuations seen with very short instantaneous windows.
- Sets paused flag in
DownloadHandle. - Workers flush buffers and wait on resume/cancel notification.
- Clears paused flag.
- Notifies waiting workers.
- Workers reconnect/re-enter chunk streaming loop.
- Cancels token and wakes paused workers.
- UI transitions to cancelled state and performs asynchronous cleanup.
- Guard window prevents immediate restart race after cancel.
Error type: AppError (src/error.rs).
Main categories:
- Network / IO failures
- Missing URI / invalid data
- Hash mismatch
- Cancelled flow
- Assemble failures
Reliability techniques:
- Retry loop with delay/backoff.
- Cancellation-aware select loops.
- Background cleanup to avoid blocking UI thread.
- Clear terminal status propagation to UI.
Localization source: src/localization.rs
- Supports English and Georgian.
- Uses
Stringsstruct with all UI text keys. - Language toggle swaps static string table at runtime.
Configured in main.rs:
- Segoe UI (primary Latin/English quality)
- Sylfaen (Georgian support)
- Embedded NotoSans fallback
- Build-time embedding via
build.rs(winres+app.ico). - Runtime viewport icon assignment in
main.rs.
Current UI uses card-style section frames and compact control layout for a more modern appearance.
Application bootstrap, runtime creation, font/icon setup, app startup.
Main UI state, frame update loop, view rendering, terminal status reactions.
Action handlers:
- start download
- restart download
- cancel confirm
- cancel artifact cleanup
Top-level downloader orchestration and backend dispatch.
HTTP chunk worker implementation with pause/cancel-aware loops.
Azure backend architecture and orchestration service.
Part concatenation into final file.
Hash verification with progress updates.
Progress send helper + repaint trigger.
Retry wait helper with cancellation awareness.
Domain models: downloads, status enums, progress snapshots.
Unified application error enum.
Language enum and localized string tables.
From project root (Codex365DownloaderV3):
cargo build
cargo runBuild with Azure backend feature enabled:
cargo run --features azure_blob_sdkWindows GNU setup details (recommended for this repository):
docs/windows-gnu-setup.md
Recommended manual scenarios:
- Start HTTP download → pause → resume → cancel.
- Start HTTP download → cancel → immediate restart.
- Start Azure SDK download path on blob URL.
- Verify
.partN+.download_infocreation in selected folder. - Confirm cleanup after cancel.
- Hash verification success/failure path.
- HTTP backend is the most mature path.
- Azure SDK backend is architecturally integrated but may not yet have exact parity for all nuanced retry/circuit-breaker behavior.
- Task manager icon display can still be influenced by Windows icon cache behavior outside application code.
This file is intended as the primary engineering documentation for contributors and maintainers.
For API-level docs, continue adding targeted /// and //! rustdoc comments directly to public modules, structs, and functions.