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