mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 15:11:58 +01:00
cancel in-flight downloads when offline mode turns on
This commit is contained in:
@@ -76,6 +76,11 @@ class DownloadRepository(
|
||||
scope.launch {
|
||||
sourceRepository.activeSourceId().distinctUntilChanged().collect { reconcile() }
|
||||
}
|
||||
scope.launch {
|
||||
sourceRepository.offline.collect { offline ->
|
||||
if (offline) cancelActive()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun close() {
|
||||
|
||||
@@ -345,6 +345,23 @@ class DownloadRepositoryTest {
|
||||
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
|
||||
fun theDownloadStartsBeforeItsArtworkIsFetched() =
|
||||
runTest {
|
||||
|
||||
Reference in New Issue
Block a user