Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
TestToolChainDemo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
dsq
TestToolChainDemo
Commits
519c2244
Commit
519c2244
authored
Mar 16, 2026
by
dsq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改版本
parent
ca60f7f3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
5 deletions
+14
-5
HighLogDemo.kt
...src/commonMain/kotlin/com.dong.demo013/Log/HighLogDemo.kt
+12
-3
hvigor-config.json5
harmonyApp/hvigor/hvigor-config.json5
+1
-1
oh-package.json5
harmonyApp/oh-package.json5
+1
-1
No files found.
composeApp/src/commonMain/kotlin/com.dong.demo013/Log/HighLogDemo.kt
View file @
519c2244
...
@@ -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
)
)
)
...
...
harmonyApp/hvigor/hvigor-config.json5
View file @
519c2244
{
{
"modelVersion": "
6.0.0
",
"modelVersion": "
5.0.5
",
"dependencies": {
"dependencies": {
},
},
"execution": {
"execution": {
...
...
harmonyApp/oh-package.json5
View file @
519c2244
{
{
"modelVersion": "
6.0.0
",
"modelVersion": "
5.0.5
",
"description": "Please describe the basic information.",
"description": "Please describe the basic information.",
"dependencies": {
"dependencies": {
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment