Files
SpotiFLAC-Mobile/rust_backend/crates/extensions/src/download/progress.rs
T
zarzet aa99726439 feat(backend): migrate production backend to Rust
Replace the Go backend with the Rust workspace and route Android/iOS through
UniFFI bindings. Include the migrated extension runtime, network, providers,
media metadata, downloads and library operations, with version 5.0.0+147.

Remove Go sources, adapters, native build selection and CI dependencies.
Build Rust unconditionally and lock the iOS Rust pod using a relative path.
Retain legacy source and migration evidence in a local ignored archive.

Validation: Android Kotlin compile and 53 native tests; Swift Rust-branch
equivalence and syntax; CocoaPods install; workflow, shell, Ruby, plist and
diff checks. Reuse the preceding 100 Rust tests, fmt/Clippy and five-ABI
build checkpoint; no new APK or iOS application build for this cleanup.

Known follow-up: URL/URLSearchParams globals are missing from the Rust JS
runtime. A controlled extension replay confirms a URL-resolution regression;
this commit does not fix that runtime gap.
2026-09-14 22:58:27 +07:00

56 lines
1.4 KiB
Rust

use spotiflac_core::progress::{ItemTransferProgressReporter, ProgressRegistry};
use std::sync::Arc;
pub(crate) struct ItemProgressTarget {
registry: Arc<ProgressRegistry>,
id: String,
track: bool,
}
impl ItemProgressTarget {
pub fn new(registry: Arc<ProgressRegistry>, id: String, track: bool) -> Self {
Self {
registry,
id,
track,
}
}
pub fn start(&self) {
if !self.id.is_empty() {
let _ = self.registry.downloading(&self.id);
}
}
pub fn set(&self, progress: f64, bytes: u64, total: i64) {
if self.track && !self.id.is_empty() {
let _ = self
.registry
.set_progress(&self.id, progress, bytes as i64, total);
}
}
pub fn initial(&self, bytes: u64, total: i64) {
if total > 0 {
self.set(bytes as f64 / total as f64, bytes, total);
} else {
self.received(bytes);
}
}
pub fn received(&self, bytes: u64) {
if self.track && !self.id.is_empty() && bytes > 0 {
let _ = self.registry.set_received(&self.id, bytes as i64);
}
}
pub fn reporter(&self, bytes: u64, total: i64) -> ItemTransferProgressReporter {
ItemTransferProgressReporter::new(
Arc::clone(&self.registry),
if self.track { &self.id } else { "" },
bytes as i64,
total,
)
}
}