Skip to content

Commit a2de7fa

Browse files
committed
logging sample
1 parent 72132a4 commit a2de7fa

5 files changed

Lines changed: 38 additions & 7 deletions

File tree

iosApp/iosApp/iosApp.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import ComposeApp
44

55
@main
66
struct iosApp: App {
7+
8+
init() {
9+
MainKt.debugBuild()
10+
}
11+
712
var body: some Scene {
813
WindowGroup {
914
ContentView()

sampleApp/src/androidMain/kotlin/com/softartdev/kronos/sample/App.android.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import android.os.Bundle
77
import androidx.activity.ComponentActivity
88
import androidx.activity.compose.setContent
99
import com.softartdev.kronos.NetworkClock
10+
import io.github.aakira.napier.DebugAntilog
11+
import io.github.aakira.napier.Napier
1012

1113
class AndroidApp : Application() {
1214
companion object {
@@ -16,6 +18,7 @@ class AndroidApp : Application() {
1618
override fun onCreate() {
1719
super.onCreate()
1820
INSTANCE = this
21+
Napier.base(DebugAntilog())
1922
NetworkClock.sync(applicationContext)
2023
}
2124
}

sampleApp/src/commonMain/kotlin/com/softartdev/kronos/sample/App.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import androidx.compose.ui.Alignment
1010
import androidx.compose.ui.Modifier
1111
import com.softartdev.kronos.Greeting
1212
import com.softartdev.kronos.NetworkClock
13+
import io.github.aakira.napier.Napier
14+
import kotlinx.datetime.Clock
1315

1416
@Composable
1517
internal fun App() = AppTheme {
@@ -21,7 +23,7 @@ internal fun App() = AppTheme {
2123
) {
2224
Text(text = "Network time millis: $ntpTimeMs")
2325
Button(
24-
onClick = { ntpTimeMs = NetworkClock.getCurrentNtpTimeMs() }
26+
onClick = { ntpTimeMs = logNtpTimeMs() }
2527
) {
2628
Text(text = "Refresh network time millis")
2729
}
@@ -34,4 +36,14 @@ internal fun App() = AppTheme {
3436
}
3537
}
3638

39+
private fun logNtpTimeMs(): Long? {
40+
val networkTimeMs = NetworkClock.getCurrentNtpTimeMs()
41+
Napier.d(tag = "⌚️", message = "Network time millis: $networkTimeMs")
42+
val systemTimeMs = Clock.System.now().toEpochMilliseconds()
43+
Napier.d(tag = "⌚️", message = "System time millis: $systemTimeMs")
44+
val diff = networkTimeMs?.minus(systemTimeMs)
45+
Napier.d(tag = "⌚️", message = "Diff: $diff")
46+
return networkTimeMs
47+
}
48+
3749
internal expect fun openUrl(url: String?)

sampleApp/src/desktopMain/kotlin/main.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ import androidx.compose.ui.window.application
44
import androidx.compose.ui.window.rememberWindowState
55
import com.softartdev.kronos.NetworkClock
66
import com.softartdev.kronos.sample.App
7+
import io.github.aakira.napier.DebugAntilog
8+
import io.github.aakira.napier.Napier
79

8-
fun main() = application {
10+
fun main() {
11+
Napier.base(DebugAntilog())
912

1013
NetworkClock.sync()
1114

12-
Window(
13-
title = "Kronos Multiplatform",
14-
state = rememberWindowState(width = 600.dp, height = 400.dp),
15-
onCloseRequest = ::exitApplication,
16-
) { App() }
15+
application {
16+
Window(
17+
title = "Kronos Multiplatform",
18+
state = rememberWindowState(width = 600.dp, height = 400.dp),
19+
onCloseRequest = ::exitApplication,
20+
) { App() }
21+
}
1722
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import androidx.compose.ui.window.ComposeUIViewController
22
import com.softartdev.kronos.sample.App
3+
import io.github.aakira.napier.DebugAntilog
4+
import io.github.aakira.napier.Napier
35
import platform.UIKit.UIViewController
46

7+
fun debugBuild() {
8+
Napier.base(DebugAntilog())
9+
}
10+
511
fun MainViewController(): UIViewController {
612
return ComposeUIViewController { App() }
713
}

0 commit comments

Comments
 (0)