mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-11 07:29:14 +01:00
cancel in-flight downloads when offline mode turns on
This commit is contained in:
@@ -76,6 +76,11 @@ class DownloadRepository(
|
|||||||
scope.launch {
|
scope.launch {
|
||||||
sourceRepository.activeSourceId().distinctUntilChanged().collect { reconcile() }
|
sourceRepository.activeSourceId().distinctUntilChanged().collect { reconcile() }
|
||||||
}
|
}
|
||||||
|
scope.launch {
|
||||||
|
sourceRepository.offline.collect { offline ->
|
||||||
|
if (offline) cancelActive()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun close() {
|
fun close() {
|
||||||
|
|||||||
@@ -345,6 +345,23 @@ class DownloadRepositoryTest {
|
|||||||
assertNotNull(artwork.uri(1, coverArtKey(1, PLAYLIST_ART, false)))
|
assertNotNull(artwork.uri(1, coverArtKey(1, PLAYLIST_ART, false)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun goingOfflineCancelsActiveDownloads() =
|
||||||
|
runTest {
|
||||||
|
seedLibrary()
|
||||||
|
repository.start()
|
||||||
|
val active: (SongDownload) -> Boolean = {
|
||||||
|
it.status == DownloadStatus.Queued || it.status == DownloadStatus.Running
|
||||||
|
}
|
||||||
|
runBlocking { repository.download(1, "s1") }
|
||||||
|
await { allRows().any(active) }
|
||||||
|
|
||||||
|
runBlocking { sources.setOfflineMode(true) }
|
||||||
|
|
||||||
|
await { allRows().none(active) }
|
||||||
|
assertTrue(engine.cancelled.isNotEmpty())
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun theDownloadStartsBeforeItsArtworkIsFetched() =
|
fun theDownloadStartsBeforeItsArtworkIsFetched() =
|
||||||
runTest {
|
runTest {
|
||||||
|
|||||||
Reference in New Issue
Block a user