diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/MainActivity.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/MainActivity.kt index b11369d91..0118115f7 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/MainActivity.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/MainActivity.kt @@ -129,9 +129,12 @@ import com.ramcosta.composedestinations.utils.currentDestinationAsState import eu.kanade.tachiyomi.util.lang.withIOContext import java.io.File import java.io.FileOutputStream +import kotlinx.coroutines.channels.BufferOverflow +import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch import moe.tarsin.coroutines.runSuspendCatching import splitties.systemservices.clipboardManager @@ -187,11 +190,12 @@ class MainActivity : EhActivity() { override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) - intentFlow.tryEmit(intent) + intentChannel.trySend(intent) } private val tipFlow = MutableSharedFlow(extraBufferCapacity = 1) - private val intentFlow = MutableSharedFlow(extraBufferCapacity = 4) + private val intentChannel = Channel(capacity = 4, onBufferOverflow = BufferOverflow.DROP_OLDEST) + private val intentFlow = intentChannel.receiveAsFlow() @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") override fun onCreate(savedInstanceState: Bundle?) { @@ -211,8 +215,8 @@ class MainActivity : EhActivity() { val cannotParse = stringResource(R.string.error_cannot_parse_the_url) LaunchedEffect(Unit) { - intentFlow.collect { - when (intent?.action) { + intentFlow.collect { intent -> + when (intent.action) { Intent.ACTION_VIEW -> { val url = intent.data?.toString() if (url != null && !navController.navWithUrl(url)) {