feat(widget): Add Local Stats glance widget (#4642)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2026-02-25 13:39:00 -06:00 committed by GitHub
parent 692ad78c80
commit 9970d31520
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 1256 additions and 24 deletions

View file

@ -18,23 +18,36 @@ package org.meshtastic.core.resources
import kotlinx.coroutines.runBlocking
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.getString
import org.jetbrains.compose.resources.getString as composeGetString
/** Retrieves a string from the [StringResource] in a blocking manner. Use primarily in non-composable code. */
fun getString(stringResource: StringResource): String = runBlocking {
org.jetbrains.compose.resources.getString(stringResource)
}
fun getString(stringResource: StringResource): String = runBlocking { composeGetString(stringResource) }
/** Retrieves a formatted string from the [StringResource] in a blocking manner. */
fun getString(stringResource: StringResource, vararg formatArgs: Any): String = runBlocking {
val resolvedArgs =
formatArgs.map { arg ->
if (arg is StringResource) {
getString(arg)
} else {
arg
}
}
@Suppress("SpreadOperator")
org.jetbrains.compose.resources.getString(stringResource, *resolvedArgs.toTypedArray())
getStringSuspend(stringResource, *formatArgs)
}
/** Retrieves a string from the [StringResource] in a suspending manner. */
suspend fun getStringSuspend(stringResource: StringResource): String = composeGetString(stringResource)
/** Retrieves a formatted string from the [StringResource] in a suspending manner. */
suspend fun getStringSuspend(stringResource: StringResource, vararg formatArgs: Any): String {
val resolvedArgs =
formatArgs
.map { arg ->
if (arg is StringResource) {
// Resolve nested StringResources recursively
getStringSuspend(arg)
} else {
arg
}
}
.toTypedArray()
// Compose Multiplatform doesn't fully support complex formatting like %.2f
// Fetch the raw string and format it using standard Java String.format.
val rawString = composeGetString(stringResource)
@Suppress("SpreadOperator")
return String.format(java.util.Locale.getDefault(), rawString, *resolvedArgs)
}