fix(sync): restore foreground refresh behavior

This commit is contained in:
tapframe 2026-07-22 21:28:00 +05:30
parent 2f19d06fd3
commit 7210e7cc68
3 changed files with 17 additions and 4 deletions

View file

@ -1221,7 +1221,7 @@ private fun MainAppContent(
val activeProfileId = profileState.activeProfile?.profileIndex ?: return@LaunchedEffect
SyncManager.pullAllForProfile(activeProfileId)
AppForegroundMonitor.events().collect {
SyncManager.requestForegroundPull(activeProfileId)
SyncManager.requestForegroundPull(activeProfileId, force = true)
}
}
var resumePromptItem by remember { mutableStateOf<ContinueWatchingItem?>(null) }

View file

@ -170,6 +170,9 @@ object SimklProgressRepository {
}
}
internal fun simklProgressRefreshIntent(sourceChanged: Boolean): TrackingRefreshIntent =
if (sourceChanged) TrackingRefreshIntent.INVALIDATED else TrackingRefreshIntent.AUTOMATIC
object SimklTrackingProgressProvider : TrackingProgressProvider {
override val providerId: TrackingProviderId = TrackingProviderId.SIMKL
override val changes: Flow<Unit> = SimklProgressRepository.uiState.map { Unit }
@ -179,9 +182,7 @@ object SimklTrackingProgressProvider : TrackingProgressProvider {
override fun onProfileChanged() = SimklProgressRepository.ensureLoaded()
override suspend fun refresh(force: Boolean, sourceChanged: Boolean) =
SimklProgressRepository.refresh(
if (sourceChanged) TrackingRefreshIntent.INVALIDATED else TrackingRefreshIntent.AUTOMATIC,
)
SimklProgressRepository.refresh(simklProgressRefreshIntent(sourceChanged))
override fun snapshot(): TrackingProgressSnapshot {
val state = SimklProgressRepository.uiState.value

View file

@ -10,6 +10,18 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue
class SimklRefreshPolicyTest {
@Test
fun `progress refresh keeps provider policy unless the source changes`() {
assertEquals(
TrackingRefreshIntent.AUTOMATIC,
simklProgressRefreshIntent(sourceChanged = false),
)
assertEquals(
TrackingRefreshIntent.INVALIDATED,
simklProgressRefreshIntent(sourceChanged = true),
)
}
@Test
fun `automatic refresh is throttled for fifteen minutes`() {
val lastCheckedAt = 1_000L