feat(connections): Connecting state refactor (#3722)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2025-11-17 15:15:22 -06:00 committed by GitHub
parent 12ccb34553
commit 73d933fe14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 379 additions and 263 deletions

View file

@ -17,17 +17,24 @@
package org.meshtastic.core.service
enum class ConnectionState {
sealed class ConnectionState {
/** We are disconnected from the device, and we should be trying to reconnect. */
DISCONNECTED,
data object Disconnected : ConnectionState()
/** We are currently attempting to connect to the device. */
data object Connecting : ConnectionState()
/** We are connected to the device and communicating normally. */
CONNECTED,
data object Connected : ConnectionState()
/** The device is in a light sleep state, and we are waiting for it to wake up and reconnect to us. */
DEVICE_SLEEP,
data object DeviceSleep : ConnectionState()
;
fun isConnected() = this == Connected
fun isConnected() = this != DISCONNECTED
fun isConnecting() = this == Connecting
fun isDisconnected() = this == Disconnected
fun isDeviceSleep() = this == DeviceSleep
}

View file

@ -41,7 +41,7 @@ class ServiceRepository @Inject constructor() {
}
// Connection state to our radio device
private val _connectionState = MutableStateFlow(ConnectionState.DISCONNECTED)
private val _connectionState: MutableStateFlow<ConnectionState> = MutableStateFlow(ConnectionState.Disconnected)
val connectionState: StateFlow<ConnectionState>
get() = _connectionState
@ -81,7 +81,7 @@ class ServiceRepository @Inject constructor() {
get() = _statusMessage
fun setStatusMessage(text: String) {
if (connectionState.value != ConnectionState.CONNECTED) {
if (connectionState.value != ConnectionState.Connected) {
_statusMessage.value = text
}
}

View file

@ -210,6 +210,7 @@
<string name="connection_status">Current connections:</string>
<string name="wifi_ip">Wifi IP:</string>
<string name="ethernet_ip">Ethernet IP:</string>
<string name="connecting">Connecting</string>
<string name="not_connected">Not connected</string>
<string name="connected_sleeping">Connected to radio, but it is sleeping</string>
<string name="app_too_old">Application update required</string>
@ -953,4 +954,5 @@
<string name="unset">Unset - 0</string>
<string name="relayed_by">Relayed by: %1$s</string>
<string name="preserve_favorites">Preserve Favorites?</string>
<string name="usb_devices">USB Devices</string>
</resources>