optimize orientation container position

This commit is contained in:
2026-10-03 19:07:41 +08:00
parent 52ab485e9c
commit 53897bda1a
5 changed files with 174 additions and 84 deletions
@@ -1,12 +1,55 @@
package com.zhushenwudi.lovelivemusicplayer.lyric
import kotlinx.cinterop.BooleanVar
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.alloc
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.ptr
import kotlinx.cinterop.value
import platform.Foundation.NSBundle
import platform.Foundation.NSDocumentDirectory
import platform.Foundation.NSFileManager
import platform.Foundation.NSSearchPathForDirectoriesInDomains
import platform.Foundation.NSUserDomainMask
/**
* 解锁目录名。Info.plist 开了 UIFileSharingEnabled,
* 用户可在「文件」App 的本应用目录下自行新建它。
*/
private const val UNLOCK_DIR_NAME = "LLMP"
actual object PlatformInfo {
// iOS 在 EULA 未接受前可能限制日文/罗马音歌词。
actual val allowEulaLyric: Boolean = true
/**
* iOS 默认只提供中文歌词;Documents 下存在 LLMP 目录才解锁日文/罗马音。
*
* 刻意只在首次读取时查一次盘:[LyricService.lrcType] 的初值、歌词下载分支、
* 以及多处 UI 分支都依赖这个值,运行中途翻转会让它们对不上
* (例如 lrcType 停在 0 要显示日文,而日文根本没下载过)。
* 用户新建目录后重启应用生效。
*/
actual val allowEulaLyric: Boolean by lazy { unlockDirExists() }
actual val isIos: Boolean = true
actual val appVersion: String =
NSBundle.mainBundle.objectForInfoDictionaryKey("CFBundleShortVersionString") as? String
?: ""
}
@OptIn(ExperimentalForeignApi::class)
private fun unlockDirExists(): Boolean {
val docs = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask,
true,
).firstOrNull() as? String ?: return false
val path = if (docs.endsWith("/")) {
"$docs$UNLOCK_DIR_NAME"
} else {
"$docs/$UNLOCK_DIR_NAME"
}
return memScoped {
val isDir = alloc<BooleanVar>()
// 必须是目录:同名文件不算解锁。
NSFileManager.defaultManager.fileExistsAtPath(path, isDirectory = isDir.ptr) &&
isDir.value
}
}