Commit 519c2244 authored by dsq's avatar dsq

修改版本

parent ca60f7f3
...@@ -13,6 +13,8 @@ import kotlinx.coroutines.delay ...@@ -13,6 +13,8 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlin.time.TimeSource import kotlin.time.TimeSource
private const val TIMER_MAX_SECONDS = 20 * 60L // 20 分钟上限
@OptIn(ExperimentalLayoutApi::class) @OptIn(ExperimentalLayoutApi::class)
@Composable @Composable
internal fun HighLogDemo() { internal fun HighLogDemo() {
...@@ -27,13 +29,20 @@ internal fun HighLogDemo() { ...@@ -27,13 +29,20 @@ internal fun HighLogDemo() {
val timeSource = remember { TimeSource.Monotonic } val timeSource = remember { TimeSource.Monotonic }
var startTimeMark by remember { mutableStateOf(timeSource.markNow()) } var startTimeMark by remember { mutableStateOf(timeSource.markNow()) }
// 使用 LaunchedEffect 实现计时器 // 使用 LaunchedEffect 实现计时器,达到 20 分钟自动停止
LaunchedEffect(isTimerRunning) { LaunchedEffect(isTimerRunning) {
if (isTimerRunning) { if (isTimerRunning) {
startTimeMark = timeSource.markNow() startTimeMark = timeSource.markNow()
while (isActive && isTimerRunning) { while (isActive && isTimerRunning) {
delay(1000) // 每 1000ms 更新一次显示 delay(1000) // 每 1000ms 更新一次显示
displayTime = startTimeMark.elapsedNow().inWholeSeconds val elapsed = startTimeMark.elapsedNow().inWholeSeconds
displayTime = elapsed
if (elapsed >= TIMER_MAX_SECONDS) {
isTimerRunning = false
isGenerating = false
displayTime = TIMER_MAX_SECONDS
break
}
} }
} else { } else {
// 暂停时重置时间 // 暂停时重置时间
...@@ -67,7 +76,7 @@ internal fun HighLogDemo() { ...@@ -67,7 +76,7 @@ internal fun HighLogDemo() {
.padding(16.dp) .padding(16.dp)
) { ) {
Text( Text(
"运行时间", "运行时间(上限 20 分钟)",
style = MaterialTheme.typography.h6, style = MaterialTheme.typography.h6,
modifier = Modifier.padding(bottom = 12.dp) modifier = Modifier.padding(bottom = 12.dp)
) )
......
{ {
"modelVersion": "6.0.0", "modelVersion": "5.0.5",
"dependencies": { "dependencies": {
}, },
"execution": { "execution": {
......
{ {
"modelVersion": "6.0.0", "modelVersion": "5.0.5",
"description": "Please describe the basic information.", "description": "Please describe the basic information.",
"dependencies": { "dependencies": {
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment