tracks and displays connection tentatives on relay settings
This commit is contained in:
+9
-3
@@ -33,6 +33,7 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.service.countToHumanReadable
|
import com.vitorpamplona.amethyst.service.countToHumanReadable
|
||||||
import com.vitorpamplona.amethyst.service.countToHumanReadableBytes
|
import com.vitorpamplona.amethyst.service.countToHumanReadableBytes
|
||||||
@@ -43,6 +44,7 @@ import com.vitorpamplona.amethyst.ui.theme.HalfStartPadding
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.Size15Modifier
|
import com.vitorpamplona.amethyst.ui.theme.Size15Modifier
|
||||||
import com.vitorpamplona.amethyst.ui.theme.allGoodColor
|
import com.vitorpamplona.amethyst.ui.theme.allGoodColor
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
|
import com.vitorpamplona.amethyst.ui.theme.redColorOnSecondSurface
|
||||||
import com.vitorpamplona.amethyst.ui.theme.warningColor
|
import com.vitorpamplona.amethyst.ui.theme.warningColor
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -126,18 +128,22 @@ fun RelayStatusRow(
|
|||||||
onLongPress = {
|
onLongPress = {
|
||||||
accountViewModel.toastManager.toast(
|
accountViewModel.toastManager.toast(
|
||||||
R.string.errors,
|
R.string.errors,
|
||||||
R.string.errors_description,
|
R.string.connection_success_rate_description,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
val successRate = ((item.relayStat.connectionCompleted / item.relayStat.connectionTentatives.toFloat()) * 100).toInt()
|
||||||
|
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.SyncProblem,
|
imageVector = Icons.Default.SyncProblem,
|
||||||
stringRes(R.string.errors),
|
stringRes(R.string.errors),
|
||||||
modifier = Size15Modifier,
|
modifier = Size15Modifier,
|
||||||
tint =
|
tint =
|
||||||
if (item.relayStat.errorCounter > 0) {
|
if (successRate < 0.1) {
|
||||||
|
MaterialTheme.colorScheme.redColorOnSecondSurface
|
||||||
|
} else if (successRate < 0.60) {
|
||||||
MaterialTheme.colorScheme.warningColor
|
MaterialTheme.colorScheme.warningColor
|
||||||
} else {
|
} else {
|
||||||
MaterialTheme.colorScheme.allGoodColor
|
MaterialTheme.colorScheme.allGoodColor
|
||||||
@@ -145,7 +151,7 @@ fun RelayStatusRow(
|
|||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = countToHumanReadable(item.relayStat.errorCounter, "errors"),
|
text = stringResource(R.string.uptime, successRate),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
fontSize = Font12SP,
|
fontSize = Font12SP,
|
||||||
modifier = HalfStartPadding,
|
modifier = HalfStartPadding,
|
||||||
|
|||||||
@@ -137,6 +137,7 @@
|
|||||||
<string name="bytes">Bytes</string>
|
<string name="bytes">Bytes</string>
|
||||||
<string name="error">Error</string>
|
<string name="error">Error</string>
|
||||||
<string name="errors">Errors</string>
|
<string name="errors">Errors</string>
|
||||||
|
<string name="connection_success_rate_description">Percentage of successful connections to the relay</string>
|
||||||
<string name="errors_description">The number of connection errors in this session</string>
|
<string name="errors_description">The number of connection errors in this session</string>
|
||||||
<string name="home_feed">Home Feed</string>
|
<string name="home_feed">Home Feed</string>
|
||||||
<string name="private_message_feed">Private Message Feed</string>
|
<string name="private_message_feed">Private Message Feed</string>
|
||||||
@@ -1743,4 +1744,5 @@
|
|||||||
<string name="following_accounts">Following %1$d accounts…</string>
|
<string name="following_accounts">Following %1$d accounts…</string>
|
||||||
<string name="import_follows_tips">"Enter the profile of a friend or community leader. You can use their npub, NIP-05 address, or a Namecoin name like alice@example.bit or id/alice for blockchain-verified identities."</string>
|
<string name="import_follows_tips">"Enter the profile of a friend or community leader. You can use their npub, NIP-05 address, or a Namecoin name like alice@example.bit or id/alice for blockchain-verified identities."</string>
|
||||||
<string name="select_all">Select All</string>
|
<string name="select_all">Select All</string>
|
||||||
|
<string name="uptime">%1$d% uptime</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
+10
@@ -32,6 +32,8 @@ class RelayStat(
|
|||||||
var errorCounter: Int = 0,
|
var errorCounter: Int = 0,
|
||||||
var pingInMs: Int = 0,
|
var pingInMs: Int = 0,
|
||||||
var compression: Boolean = false,
|
var compression: Boolean = false,
|
||||||
|
var connectionTentatives: Int = 0,
|
||||||
|
var connectionCompleted: Int = 0,
|
||||||
) {
|
) {
|
||||||
val messages = LruCache<IRelayDebugMessage, IRelayDebugMessage>(100)
|
val messages = LruCache<IRelayDebugMessage, IRelayDebugMessage>(100)
|
||||||
|
|
||||||
@@ -63,6 +65,14 @@ class RelayStat(
|
|||||||
sentBytes += bytesUsedInMemory
|
sentBytes += bytesUsedInMemory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun newConnection() {
|
||||||
|
connectionTentatives++
|
||||||
|
}
|
||||||
|
|
||||||
|
fun connectionCompleted() {
|
||||||
|
connectionCompleted++
|
||||||
|
}
|
||||||
|
|
||||||
fun newSpam(
|
fun newSpam(
|
||||||
link1: String,
|
link1: String,
|
||||||
link2: String,
|
link2: String,
|
||||||
|
|||||||
+8
@@ -46,6 +46,13 @@ class RelayStats(
|
|||||||
|
|
||||||
private val clientListener =
|
private val clientListener =
|
||||||
object : IRelayClientListener {
|
object : IRelayClientListener {
|
||||||
|
override fun onConnecting(relay: IRelayClient) {
|
||||||
|
super.onConnecting(relay)
|
||||||
|
with(get(relay.url)) {
|
||||||
|
newConnection()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onConnected(
|
override fun onConnected(
|
||||||
relay: IRelayClient,
|
relay: IRelayClient,
|
||||||
pingMillis: Int,
|
pingMillis: Int,
|
||||||
@@ -54,6 +61,7 @@ class RelayStats(
|
|||||||
with(get(relay.url)) {
|
with(get(relay.url)) {
|
||||||
pingInMs = pingMillis
|
pingInMs = pingMillis
|
||||||
compression = compressed
|
compression = compressed
|
||||||
|
connectionCompleted()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user