fix pip screen bug

This commit is contained in:
2026-10-02 14:32:04 +08:00
parent cf7a5ed2ed
commit 926dbd9ff3
5 changed files with 48 additions and 64 deletions
@@ -276,13 +276,13 @@ private fun ObserveDesktopLyricLifecycle() {
DisposableEffect(owner) {
val observer = LifecycleEventObserver { _, event ->
when (event) {
Lifecycle.Event.ON_PAUSE -> AppContainer.setAppInBackground(true)
Lifecycle.Event.ON_RESUME -> AppContainer.setAppInBackground(false)
Lifecycle.Event.ON_STOP -> AppContainer.setAppInBackground(true)
Lifecycle.Event.ON_START -> AppContainer.setAppInBackground(false)
else -> Unit
}
}
owner.lifecycle.addObserver(observer)
if (!owner.lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
if (!owner.lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
AppContainer.setAppInBackground(true)
}
onDispose { owner.lifecycle.removeObserver(observer) }
@@ -223,12 +223,15 @@ private fun CoverAsyncImage(
// 进程级 Image 底图:LazyList dispose 会丢弃 remember(Painter),导致
// Loading(null) → 空白,即使磁盘/内存仍有封面。
val baseCacheKey = remember(modelUri, stableCacheKey) {
stableCacheKey?.takeIf { it.isNotBlank() }
?: if (modelUri.startsWith("http", ignoreCase = true)) {
modelUri.toImageCacheKey()
} else {
modelUri
}
if (
modelUri.startsWith("http://", ignoreCase = true) ||
modelUri.startsWith("https://", ignoreCase = true)
) {
// 远程封面以 URL 为内容身份:同一专辑在列表、详情和歌曲条目间共享缓存。
modelUri.toImageCacheKey()
} else {
stableCacheKey?.takeIf { it.isNotBlank() } ?: modelUri
}
}
val bucketPx = remember(decodeSize, density) {
decodeSize?.let { dp ->
@@ -29,6 +29,7 @@ import coil3.memory.MemoryCache
import coil3.network.CacheStrategy
import coil3.network.CacheStrategy.ReadResult
import coil3.network.CacheStrategy.WriteResult
import coil3.network.DeDupeConcurrentRequestStrategy
import coil3.network.NetworkRequest
import coil3.network.NetworkResponse
import coil3.network.ktor3.KtorNetworkFetcherFactory
@@ -193,6 +194,9 @@ fun createLlmpImageLoader(context: PlatformContext): ImageLoader {
add(
KtorNetworkFetcherFactory(
cacheStrategy = { PermanentImageCacheStrategy },
// Hero/页面切换期间同一封面可能被不同尺寸的组件同时请求。
// 以磁盘缓存键合并并发网络请求,避免相同 URL 重复下载。
concurrentRequestStrategy = { DeDupeConcurrentRequestStrategy() },
),
)
}
@@ -239,8 +243,10 @@ fun LlmpAsyncImage(
val context = LocalPlatformContext.current
val density = LocalDensity.current
val httpUrl = (model as? String)?.takeIf { it.isHttpUrl() }
val baseCacheKey = stableCacheKey?.takeIf { it.isNotBlank() }
?: httpUrl?.toImageCacheKey()
// 远程图片按 URL 复用原始字节,避免同一专辑封面因 music/album id 不同而重复下载。
// stableCacheKey 仅用于没有远程 URL 的资源;解码尺寸仍只区分内存缓存。
val baseCacheKey = httpUrl?.toImageCacheKey()
?: stableCacheKey?.takeIf { it.isNotBlank() }
val bucketPx = remember(decodeSize, density) {
decodeSize?.let { dp ->
decodeSizeBucketPx(with(density) { dp.roundToPx() })