DownloadKeepAlive.kt
composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/services/download/DownloadKeepAlive.kt
1package eu.friedcutlet.yokan.services.download23import eu.friedcutlet.yokan.database.YokanDatabase4import eu.friedcutlet.yokan.domain.ProfileId5import kotlinx.coroutines.CoroutineScope67/**8 * Keeps [downloads] running after the app leaves the screen, for as long as [scope] lives. On Android a9 * foreground service runs while [needsKeepAlive], and a network-constrained job resumes the queue if the10 * process is killed anyway; the other platforms do nothing.11 */12expect fun keepDownloadsAlive(downloads: DownloadService, database: YokanDatabase, scope: CoroutineScope, profileId: ProfileId = ProfileId.Default)1314/** Work is pending and not parked waiting for Wi-Fi; a parked queue continues through the resume job. */15internal fun needsKeepAlive(status: DownloadQueueStatus): Boolean = status.pending > 0 && !status.waitingForWifi16