Fix crash after last screensaver image in list (#1055)

## Description
Fix a screensaver crash after the last item

Also adds some extra error checking

### Related issues
Fixes #1053

### Testing
Emulator

## Screenshots
N/A

## AI or LLM usage
None
This commit is contained in:
Ray 2026-03-06 18:16:35 -05:00 committed by GitHub
parent 8a4be3dd32
commit 256bb3f988
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 28 deletions

View file

@ -250,7 +250,7 @@ suspend fun upgradeApp(
}
}
if (previous.isEqualOrBefore(Version.fromString("0.5.0-6-g0"))) {
if (previous.isEqualOrBefore(Version.fromString("0.5.3-0-g0"))) {
appPreferences.updateData {
it.updateScreensaverPreferences {
startDelay = ScreensaverPreference.DEFAULT_START_DELAY

View file

@ -161,7 +161,13 @@ class ScreensaverService
if (pager.isEmpty()) {
emit(null)
} else {
val duration =
userPreferencesService
.getCurrent()
.appPreferences
.interfacePreferences.screensaverPreference.duration.milliseconds
while (true) {
try {
val item = pager.getBlocking(index)
Timber.v("Next index=%s, item=%s", index, item?.id)
if (item != null) {
@ -181,7 +187,6 @@ class ScreensaverService
}
val logoUrl = imageUrlService.getItemImageUrl(item, ImageType.LOGO)
if (backdropUrl != null) {
try {
context.imageLoader
.enqueue(
ImageRequest
@ -191,18 +196,17 @@ class ScreensaverService
).job
.await()
emit(CurrentItem(item, backdropUrl, logoUrl, title ?: ""))
} catch (_: CancellationException) {
break
}
val duration =
userPreferencesService
.getCurrent()
.appPreferences
.interfacePreferences.screensaverPreference.duration.milliseconds
delay(duration)
}
}
} catch (_: CancellationException) {
break
} catch (ex: Exception) {
Timber.e(ex, "Error fetching next item")
delay(duration)
}
index++
if (index > pager.lastIndex) index = 0
}
}
}.flowOn(Dispatchers.Default).cancellable()