package com.cottondb.android import android.app.Application import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ProcessLifecycleOwner class CottonApplication : Application(), DefaultLifecycleObserver, com.cottondb.android.platform.ScheduledNotificationRuntime, com.cottondb.android.platform.AlarmDeliveryFailureReporter { lateinit var runtime: AppRuntime private set override fun onCreate() { super.onCreate() if (getProcessName() != packageName) return runtime = AppRuntime(this) com.cottondb.android.platform.AndroidReminderRuntime.onError = { message, _ -> runtime.reportPlatformError(message) } ProcessLifecycleOwner.get().lifecycle.addObserver(this) runtime.open() } override suspend fun reconcileScheduledNotifications() = runtime.reconcileScheduledNotifications() override fun reportAlarmDeliveryFailure(message: String) = runtime.reportPlatformError(message) override fun onStart(owner: LifecycleOwner) = runtime.foreground() override fun onStop(owner: LifecycleOwner) = runtime.background() override fun onTerminate() { if (::runtime.isInitialized) runtime.close() super.onTerminate() } }