Fix LongPressMenu crashing if dismissed while loading

This commit is contained in:
Stypox 2026-02-07 13:13:30 +01:00
parent 59841e966e
commit 5094caf92b
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
2 changed files with 7 additions and 5 deletions

View File

@ -158,7 +158,9 @@ data class LongPressAction(
private fun buildPlayerShuffledActionList(queue: suspend (Context) -> PlayQueue): List<LongPressAction> {
val shuffledQueue: suspend (Context) -> PlayQueue = { context ->
val q = queue(context)
q.fetchAllAndShuffle()
withContext(Dispatchers.IO) {
q.fetchAllAndShuffle()
}
q
}
return listOf(

View File

@ -80,16 +80,14 @@ import androidx.compose.ui.window.DialogProperties
import androidx.lifecycle.viewmodel.compose.viewModel
import coil3.compose.AsyncImage
import java.time.OffsetDateTime
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.schabi.newpipe.R
import org.schabi.newpipe.error.ErrorInfo
import org.schabi.newpipe.error.ErrorUtil
import org.schabi.newpipe.error.UserAction.LONG_PRESS_MENU_ACTION
import org.schabi.newpipe.extractor.stream.StreamType
import org.schabi.newpipe.player.helper.PlayerHolder
import org.schabi.newpipe.ui.components.common.ScaffoldWithToolbar
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.EnqueueNext
import org.schabi.newpipe.ui.components.menu.LongPressAction.Type.ShowChannelDetails
import org.schabi.newpipe.ui.discardAllTouchesIf
@ -122,7 +120,7 @@ fun getLongPressMenuView(
LongPressMenu(
longPressable = longPressable,
longPressActions = longPressActions,
onDismissRequest = { (this.parent as ViewGroup).removeView(this) }
onDismissRequest = { (this.parent as? ViewGroup)?.removeView(this) }
)
}
}
@ -173,6 +171,8 @@ fun LongPressMenu(
coroutineScope.launch {
try {
action.action(ctx)
} catch (_: CancellationException) {
// the user canceled the action, e.g. by dismissing the dialog while loading
} catch (t: Throwable) {
ErrorUtil.showSnackbar(
ctx,