fix(dl): add progress events for tracks from new downloader

This commit is contained in:
2025-10-04 20:58:34 -04:00
parent 96a01bdced
commit 7b84bc32df
2 changed files with 61 additions and 8 deletions

View File

@@ -31,6 +31,7 @@ export async function downloadTrack(
retryCount: number = 0,
decryptionTrackId?: string
): Promise<string> {
const { listen } = await import('@tauri-apps/api/event');
// Generate paths
const paths = generateTrackPath(track, musicFolder, format, false);
@@ -60,16 +61,28 @@ export async function downloadTrack(
// Use the provided decryption track ID (for fallback tracks) or the original track ID
const trackIdForDecryption = decryptionTrackId ? decryptionTrackId.toString() : track.id.toString();
// Download and decrypt in Rust backend (streaming, no memory accumulation)
console.log('Downloading and decrypting track in Rust backend...');
await invoke('download_and_decrypt_track', {
url: downloadURL,
trackId: trackIdForDecryption,
outputPath: paths.tempPath,
isEncrypted: isCrypted
// Set up progress listener
const unlisten = await listen<DownloadProgress>('download-progress', (event) => {
if (onProgress) {
onProgress(event.payload);
}
});
console.log('Download and decryption complete!');
try {
// Download and decrypt in Rust backend (streaming, no memory accumulation)
console.log('Downloading and decrypting track in Rust backend...');
await invoke('download_and_decrypt_track', {
url: downloadURL,
trackId: trackIdForDecryption,
outputPath: paths.tempPath,
isEncrypted: isCrypted
});
console.log('Download and decryption complete!');
} finally {
// Clean up event listener
unlisten();
}
// Get user settings
const appSettings = get(settings);