AndroidAppContext.kt
composeApp/src/androidMain/kotlin/eu/friedcutlet/yokan/AndroidAppContext.kt
1package eu.friedcutlet.yokan23import android.app.Activity4import android.app.Application5import android.content.Context6import eu.friedcutlet.yokan.app.YokanRuntime7import eu.friedcutlet.yokan.services.scheduling.ProfileWorkResult8import eu.friedcutlet.yokan.services.download.DownloadService9import eu.friedcutlet.yokan.services.download.DownloadTaskHost10import eu.friedcutlet.yokan.services.scheduling.BackgroundTaskHost11import eu.friedcutlet.yokan.services.scheduling.PeriodicTaskRunner12import eu.friedcutlet.yokan.services.scheduling.PeriodicTaskOutcome1314/**15 * Process-wide application [Context], set by [YokanApplication] before any16 * component (activity, WorkManager worker, receiver) runs.17 */18object AndroidAppContext {19 @Volatile var appContext: Context? = null20}2122/**23 * The currently resumed-or-created [MainActivity], for APIs that need an24 * activity window (system bars, permission prompts). Cleared in `onDestroy`.25 */26object AndroidForegroundActivity {27 @Volatile var activity: Activity? = null28}2930class YokanApplication : Application(), BackgroundTaskHost, DownloadTaskHost {31 override fun onCreate() {32 super.onCreate()33 AndroidAppContext.appContext = applicationContext34 }3536 override suspend fun runBackgroundTask(37 owner: String?,38 task: suspend PeriodicTaskRunner.() -> PeriodicTaskOutcome,39 ): ProfileWorkResult<PeriodicTaskOutcome> = YokanRuntime.runBackgroundTask(owner, allowLegacyDefault = true, task = task)4041 override suspend fun runBackgroundDownloads(42 owner: String?,43 task: suspend DownloadService.() -> Unit,44 ): ProfileWorkResult<Unit> = YokanRuntime.runBackgroundDownloads(owner, allowLegacyDefault = true, task = task)45}46