package com.github.nullptroma.wallenc.app.sync

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.github.nullptroma.wallenc.app.di.StorageSyncBootEntryPoint
import dagger.hilt.android.EntryPointAccessors
import timber.log.Timber

class StorageSyncBootReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent?) {
        if (intent?.action != Intent.ACTION_BOOT_COMPLETED) {
            return
        }
        val scheduler = EntryPointAccessors.fromApplication(
            context.applicationContext,
            StorageSyncBootEntryPoint::class.java,
        ).storageSyncScheduler()
        scheduler.ensureScheduled()
        Timber.d("Rescheduled periodic storage sync after boot")
    }
}
