mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-27 19:38:23 +01:00
38 lines
1.3 KiB
Kotlin
38 lines
1.3 KiB
Kotlin
package tachiyomi.presentation.widget
|
|
|
|
import android.content.Context
|
|
import androidx.glance.appwidget.updateAll
|
|
import androidx.lifecycle.LifecycleCoroutineScope
|
|
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
|
import kotlinx.coroutines.flow.combine
|
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
import kotlinx.coroutines.flow.launchIn
|
|
import kotlinx.coroutines.flow.onEach
|
|
import logcat.LogPriority
|
|
import tachiyomi.core.common.util.system.logcat
|
|
import tachiyomi.domain.updates.interactor.GetUpdates
|
|
|
|
class WidgetManager(
|
|
private val getUpdates: GetUpdates,
|
|
private val securityPreferences: SecurityPreferences,
|
|
) {
|
|
|
|
fun Context.init(scope: LifecycleCoroutineScope) {
|
|
combine(
|
|
getUpdates.subscribe(read = false, after = BaseUpdatesGridGlanceWidget.DateLimit.toEpochMilli()),
|
|
securityPreferences.useAuthenticator().changes(),
|
|
transform = { a, _ -> a },
|
|
)
|
|
.distinctUntilChanged()
|
|
.onEach {
|
|
try {
|
|
UpdatesGridGlanceWidget().updateAll(this)
|
|
UpdatesGridCoverScreenGlanceWidget().updateAll(this)
|
|
} catch (e: Exception) {
|
|
logcat(LogPriority.ERROR, e) { "Failed to update widget" }
|
|
}
|
|
}
|
|
.launchIn(scope)
|
|
}
|
|
}
|