Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.

Commit 1103477

Browse files
authored
Fix season actions (#2031)
1 parent 5eaa322 commit 1103477

File tree

42 files changed

+213
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+213
-180
lines changed

android-app/app/src/main/kotlin/app/tivi/home/MainActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import app.tivi.inject.create
3131
import app.tivi.navigation.DeepLinker
3232
import app.tivi.screens.DiscoverScreen
3333
import app.tivi.settings.TiviPreferences
34+
import app.tivi.util.launchOrThrow
3435
import com.eygraber.uri.toUri
3536
import com.slack.circuit.backstack.rememberSaveableBackStack
3637
import com.slack.circuit.foundation.rememberCircuitNavigator
37-
import kotlinx.coroutines.launch
3838

3939
class MainActivity : TiviActivity() {
4040

@@ -51,7 +51,7 @@ class MainActivity : TiviActivity() {
5151

5252
deepLinker = applicationComponent.deepLinker
5353

54-
lifecycle.coroutineScope.launch {
54+
lifecycle.coroutineScope.launchOrThrow {
5555
repeatOnLifecycle(Lifecycle.State.STARTED) {
5656
applicationComponent.preferences.theme.flow
5757
.collect(::enableEdgeToEdgeForTheme)

api/tmdb/src/commonMain/kotlin/app/tivi/tmdb/TmdbInitializer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package app.tivi.tmdb
55

66
import app.tivi.appinitializers.AppInitializer
77
import app.tivi.inject.ApplicationCoroutineScope
8-
import kotlinx.coroutines.launch
8+
import app.tivi.util.launchOrThrow
99
import me.tatarka.inject.annotations.Inject
1010

1111
@Inject
@@ -14,7 +14,7 @@ class TmdbInitializer(
1414
private val scope: ApplicationCoroutineScope,
1515
) : AppInitializer {
1616
override fun initialize() {
17-
scope.launch {
17+
scope.launchOrThrow {
1818
tmdbManager.value.refreshConfiguration()
1919
}
2020
}

common/imageloading/src/commonMain/kotlin/app/tivi/common/imageloading/ImageLoaderCleanupInitializer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import app.tivi.app.ApplicationInfo
77
import app.tivi.appinitializers.AppInitializer
88
import app.tivi.inject.ApplicationCoroutineScope
99
import app.tivi.util.AppCoroutineDispatchers
10-
import kotlinx.coroutines.launch
10+
import app.tivi.util.launchOrThrow
1111
import me.tatarka.inject.annotations.Inject
1212
import okio.FileSystem
1313
import okio.Path.Companion.toPath
@@ -21,7 +21,7 @@ class ImageLoaderCleanupInitializer(
2121
) : AppInitializer {
2222

2323
override fun initialize() {
24-
scope.launch(dispatchers.io) {
24+
scope.launchOrThrow(dispatchers.io) {
2525
// We delete ImageLoader's disk cache folder to claim back space for the user
2626
val cachePath = applicationInfo.cachePath().toPath()
2727
val fs = fileSystem.value

common/ui/circuit/src/commonMain/kotlin/app/tivi/overlays/BottomSheetOverlay.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.compose.ui.Modifier
1515
import androidx.compose.ui.graphics.Color
1616
import androidx.compose.ui.graphics.isSpecified
1717
import androidx.compose.ui.unit.Dp
18+
import app.tivi.util.launchOrThrow
1819
import com.slack.circuit.foundation.CircuitContent
1920
import com.slack.circuit.foundation.NavEvent
2021
import com.slack.circuit.foundation.internal.BackHandler
@@ -24,7 +25,6 @@ import com.slack.circuit.overlay.OverlayHost
2425
import com.slack.circuit.overlay.OverlayNavigator
2526
import com.slack.circuit.runtime.Navigator
2627
import com.slack.circuit.runtime.screen.Screen
27-
import kotlinx.coroutines.launch
2828

2929
@OptIn(ExperimentalMaterial3Api::class)
3030
class BottomSheetOverlay<Model : Any, Result : Any>(
@@ -43,7 +43,7 @@ class BottomSheetOverlay<Model : Any, Result : Any>(
4343
val coroutineScope = rememberCoroutineScope()
4444
BackHandler(enabled = sheetState.isVisible) {
4545
coroutineScope
46-
.launch { sheetState.hide() }
46+
.launchOrThrow { sheetState.hide() }
4747
.invokeOnCompletion {
4848
if (!sheetState.isVisible) {
4949
navigator.finish(onDismiss())
@@ -57,7 +57,7 @@ class BottomSheetOverlay<Model : Any, Result : Any>(
5757
// Delay setting the result until we've finished dismissing
5858
content(model) { result ->
5959
// This is the OverlayNavigator.finish() callback
60-
coroutineScope.launch {
60+
coroutineScope.launchOrThrow {
6161
try {
6262
sheetState.hide()
6363
} finally {

common/ui/circuit/src/commonMain/kotlin/app/tivi/overlays/DialogOverlay.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import androidx.compose.material3.Surface
88
import androidx.compose.runtime.Composable
99
import androidx.compose.runtime.rememberCoroutineScope
1010
import androidx.compose.ui.window.Dialog
11+
import app.tivi.util.launchOrThrow
1112
import com.slack.circuit.foundation.CircuitContent
1213
import com.slack.circuit.foundation.NavEvent
1314
import com.slack.circuit.overlay.Overlay
1415
import com.slack.circuit.overlay.OverlayHost
1516
import com.slack.circuit.overlay.OverlayNavigator
1617
import com.slack.circuit.runtime.screen.Screen
17-
import kotlinx.coroutines.launch
1818

1919
class DialogOverlay<Model : Any, Result : Any>(
2020
private val model: Model,
@@ -35,7 +35,7 @@ class DialogOverlay<Model : Any, Result : Any>(
3535
// Delay setting the result until we've finished dismissing
3636
content(model) { result ->
3737
// This is the OverlayNavigator.finish() callback
38-
coroutineScope.launch {
38+
coroutineScope.launchOrThrow {
3939
navigator.finish(result)
4040
}
4141
}

common/ui/compose/src/commonMain/kotlin/app/tivi/common/compose/EntryGrid.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ import app.tivi.data.models.Entry
7575
import app.tivi.data.models.TiviShow
7676
import app.tivi.data.models.TrendingShowEntry
7777
import app.tivi.util.fmt
78+
import app.tivi.util.launchOrThrow
7879
import kotlin.math.roundToInt
79-
import kotlinx.coroutines.launch
8080
import org.jetbrains.compose.resources.stringResource
8181

8282
@OptIn(
@@ -126,7 +126,7 @@ fun <E : Entry> EntryGrid(
126126
onRefreshActionClick = lazyPagingItems::refresh,
127127
modifier = Modifier
128128
.noIndicationClickable {
129-
coroutineScope.launch {
129+
coroutineScope.launchOrThrow {
130130
lazyGridState.animateScrollToItem(0)
131131
}
132132
}

core/analytics/src/commonMain/kotlin/app/tivi/core/analytics/AnalyticsInitializer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package app.tivi.core.analytics
66
import app.tivi.appinitializers.AppInitializer
77
import app.tivi.inject.ApplicationCoroutineScope
88
import app.tivi.settings.TiviPreferences
9-
import kotlinx.coroutines.launch
9+
import app.tivi.util.launchOrThrow
1010
import me.tatarka.inject.annotations.Inject
1111

1212
@Inject
@@ -16,7 +16,7 @@ class AnalyticsInitializer(
1616
private val scope: ApplicationCoroutineScope,
1717
) : AppInitializer {
1818
override fun initialize() {
19-
scope.launch {
19+
scope.launchOrThrow {
2020
preferences.value.reportAnalytics.flow
2121
.collect { enabled -> analytics.value.setEnabled(enabled) }
2222
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2024, Christopher Banes and the Tivi project contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package app.tivi.util
5+
6+
import kotlin.coroutines.CoroutineContext
7+
import kotlin.coroutines.EmptyCoroutineContext
8+
import kotlinx.coroutines.CoroutineScope
9+
import kotlinx.coroutines.CoroutineStart
10+
import kotlinx.coroutines.Job
11+
import kotlinx.coroutines.launch
12+
13+
fun CoroutineScope.launchOrThrow(
14+
context: CoroutineContext = EmptyCoroutineContext,
15+
start: CoroutineStart = CoroutineStart.DEFAULT,
16+
block: suspend CoroutineScope.() -> Unit,
17+
): Job = launch(context, start, block).also {
18+
check(!it.isCancelled) {
19+
"launch failed. Job is already cancelled"
20+
}
21+
}

core/logging/src/commonMain/kotlin/app/tivi/util/CrashReportingInitializer.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package app.tivi.util
66
import app.tivi.appinitializers.AppInitializer
77
import app.tivi.inject.ApplicationCoroutineScope
88
import app.tivi.settings.TiviPreferences
9-
import kotlinx.coroutines.launch
109
import me.tatarka.inject.annotations.Inject
1110

1211
@Inject
@@ -16,7 +15,7 @@ class CrashReportingInitializer(
1615
private val scope: ApplicationCoroutineScope,
1716
) : AppInitializer {
1817
override fun initialize() {
19-
scope.launch {
18+
scope.launchOrThrow {
2019
preferences.value.reportAppCrashes.flow
2120
.collect { action.value(it) }
2221
}

core/notifications/core/src/androidMain/kotlin/app/tivi/core/notifications/PostNotificationBroadcastReceiver.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import android.net.Uri
1212
import android.util.Log
1313
import androidx.core.app.NotificationCompat
1414
import androidx.core.app.NotificationManagerCompat
15+
import app.tivi.util.launchOrThrow
1516
import kotlinx.coroutines.DelicateCoroutinesApi
1617
import kotlinx.coroutines.GlobalScope
17-
import kotlinx.coroutines.launch
1818

1919
class PostNotificationBroadcastReceiver : BroadcastReceiver() {
2020

@@ -33,11 +33,11 @@ class PostNotificationBroadcastReceiver : BroadcastReceiver() {
3333
val store = context.pendingNotificationsStore
3434
val result = goAsync()
3535

36-
GlobalScope.launch {
36+
GlobalScope.launchOrThrow {
3737
val pending = store.findWithId(id) ?: run {
3838
Log.d(TAG, "Pending Notification with ID: $id not found. Exiting.")
3939
result.finish()
40-
return@launch
40+
return@launchOrThrow
4141
}
4242

4343
Log.d(TAG, "Found pending notification with ID: $id: $pending")

0 commit comments

Comments
 (0)