Skip to content

Commit ce85786

Browse files
author
Hussein Habibi Juybari
committed
Update CHANGELOG.md for v0.10.0 release; expose LogTap server address in sample app
1 parent 449381a commit ce85786

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file.
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
### v0.10.0
7+
Expose LogTap server address and display in sample app
8+
9+
- Introduce `LogTap.resolvedAddress` as a `StateFlow` to observe the server address.
10+
- Update the sample app to display the resolved server address.
11+
612
### v0.9.0
713

814
- Fix GitHub links in Resources.kt to point to the correct repository

LogTap-Noop/src/main/java/com/github/husseinhj/logtap/LogTap.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.github.husseinhj.logtap
22

33
import android.content.Context
4+
import kotlinx.coroutines.flow.StateFlow
5+
import kotlinx.coroutines.flow.asStateFlow
6+
import kotlinx.coroutines.flow.MutableStateFlow
47

58
object LogTap {
69
data class Config(
@@ -11,6 +14,8 @@ object LogTap {
1114
val enableOnRelease: Boolean = false
1215
)
1316

17+
val resolvedAddress: StateFlow<String?> = MutableStateFlow(null).asStateFlow()
18+
1419
@Synchronized
1520
fun start(context: Context, config: Config = Config()) {}
1621

LogTap/src/main/java/com/github/husseinhj/logtap/LogTap.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import android.net.ConnectivityManager
1515
import kotlinx.coroutines.SupervisorJob
1616
import kotlinx.coroutines.sync.withLock
1717
import kotlinx.coroutines.CoroutineScope
18+
import kotlinx.coroutines.flow.asStateFlow
1819
import io.ktor.server.engine.embeddedServer
1920
import io.ktor.server.engine.ApplicationEngine
2021
import com.github.husseinhj.logtap.log.LogStore
2122
import kotlinx.coroutines.CancellationException
23+
import kotlinx.coroutines.flow.MutableStateFlow
2224
import kotlinx.coroutines.CoroutineExceptionHandler
2325
import com.github.husseinhj.logtap.utils.isDebuggable
2426
import com.github.husseinhj.logtap.logger.LogTapLogger
@@ -35,6 +37,9 @@ object LogTap {
3537
val enableOnRelease: Boolean = false
3638
)
3739

40+
private val _resolvedAddress: MutableStateFlow<String?> = MutableStateFlow(null)
41+
val resolvedAddress = _resolvedAddress.asStateFlow()
42+
3843
@Volatile private var server: ApplicationEngine? = null
3944
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
4045
private val bgErrorHandler = CoroutineExceptionHandler { _, t -> Log.e(TAG, "LogTap background error", t) }
@@ -112,6 +117,7 @@ object LogTap {
112117
resolvedPort = port
113118

114119
val ip = getDeviceIp(context)
120+
_resolvedAddress.value = "http://$ip:$port/"
115121
LogTapLogger.i("LogTap server ready at http://$ip:$port/")
116122
} catch (ce: CancellationException) {
117123
// engine/coroutine cancelled ⇒ do not crash app

app/src/main/java/com/github/husseinhj/logtapsample/MainActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import androidx.compose.runtime.Composable
2121
import androidx.compose.ui.Modifier
2222
import androidx.compose.ui.unit.dp
2323
import androidx.compose.ui.tooling.preview.Preview
24+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
25+
import com.github.husseinhj.logtap.LogTap
2426
import com.github.husseinhj.logtap.logger.LogTapLogger
25-
import com.github.husseinhj.logtap.utils.logW
2627
import com.github.husseinhj.logtap.utils.newWebSocketWithLogging
2728
import com.github.husseinhj.logtapsample.ui.theme.LogTapSampleTheme
2829
import okhttp3.Call
@@ -56,10 +57,14 @@ class MainActivity : ComponentActivity() {
5657
@OptIn(ExperimentalLayoutApi::class)
5758
@Composable
5859
fun LogTapPlaygroundScreen(name: String, modifier: Modifier = Modifier) {
60+
val resolvedAddress = LogTap.resolvedAddress.collectAsStateWithLifecycle(
61+
"not started"
62+
)
5963
Column(modifier = modifier.fillMaxSize().padding(16.dp).verticalScroll(rememberScrollState())) {
6064
Text(text = "LogTap Playground", style = MaterialTheme.typography.headlineSmall)
6165
Spacer(Modifier.height(8.dp))
6266
Text(text = "Hello $name! Use these to generate HTTP, WebSocket, and Logger events.", style = MaterialTheme.typography.bodyMedium)
67+
Text(text = "Address: ${resolvedAddress.value}", style = MaterialTheme.typography.bodyLarge)
6368
Spacer(Modifier.height(16.dp))
6469

6570
// ===== Logger Demos =====

0 commit comments

Comments
 (0)