feat: füge ConnectivityTracker hinzu, erweitere networkModule, aktualisiere DesktopFooterBar mit Gerätestatus und mDNS-Discovery
Signed-off-by: StefanMoCoAt <stefan.mo.co@gmail.com>
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package at.mocode.frontend.core.network
|
||||||
|
|
||||||
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.request.*
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import org.koin.core.component.KoinComponent
|
||||||
|
import org.koin.core.component.inject
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Überwacht die Konnektivität zum API-Gateway.
|
||||||
|
*/
|
||||||
|
class ConnectivityTracker : KoinComponent {
|
||||||
|
private val client: HttpClient by inject(named("baseHttpClient"))
|
||||||
|
private val _isOnline = MutableStateFlow(true)
|
||||||
|
val isOnline: StateFlow<Boolean> = _isOnline.asStateFlow()
|
||||||
|
|
||||||
|
private val scope = CoroutineScope(Dispatchers.Default + SupervisorJob())
|
||||||
|
|
||||||
|
init {
|
||||||
|
startTracking()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun startTracking() {
|
||||||
|
scope.launch {
|
||||||
|
while (isActive) {
|
||||||
|
_isOnline.value = checkConnection()
|
||||||
|
delay(10_000) // Alle 10 Sekunden prüfen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun checkConnection(): Boolean {
|
||||||
|
return try {
|
||||||
|
val response = client.get(NetworkConfig.baseUrl.trimEnd('/') + "/ping")
|
||||||
|
response.status.value in 200..299
|
||||||
|
} catch (e: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopTracking() {
|
||||||
|
scope.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-3
@@ -1,5 +1,7 @@
|
|||||||
package at.mocode.frontend.core.network
|
package at.mocode.frontend.core.network
|
||||||
|
|
||||||
|
import at.mocode.frontend.core.network.discovery.discoveryModule
|
||||||
|
import at.mocode.frontend.core.network.sync.syncModule
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.plugins.*
|
import io.ktor.client.plugins.*
|
||||||
import io.ktor.client.plugins.contentnegotiation.*
|
import io.ktor.client.plugins.contentnegotiation.*
|
||||||
@@ -10,13 +12,13 @@ import kotlinx.serialization.json.Json
|
|||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
import org.koin.core.qualifier.named
|
import org.koin.core.qualifier.named
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import at.mocode.frontend.core.network.discovery.discoveryModule
|
|
||||||
import at.mocode.frontend.core.network.sync.syncModule
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schnittstelle zur Token-Bereitstellung – entkoppelt core-network von core-auth.
|
* Schnittstelle zur Token-Bereitstellung – entkoppelt core-network von core-auth.
|
||||||
*/
|
*/
|
||||||
interface TokenProvider { fun getAccessToken(): String? }
|
interface TokenProvider {
|
||||||
|
fun getAccessToken(): String?
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Koin-Modul mit zwei HttpClient-Instanzen:
|
* Koin-Modul mit zwei HttpClient-Instanzen:
|
||||||
@@ -26,6 +28,8 @@ interface TokenProvider { fun getAccessToken(): String? }
|
|||||||
val networkModule: Module = module {
|
val networkModule: Module = module {
|
||||||
includes(discoveryModule, syncModule)
|
includes(discoveryModule, syncModule)
|
||||||
|
|
||||||
|
single<ConnectivityTracker> { ConnectivityTracker() }
|
||||||
|
|
||||||
// 1. Basis-Client (für Auth-Endpunkte, ohne Bearer-Token)
|
// 1. Basis-Client (für Auth-Endpunkte, ohne Bearer-Token)
|
||||||
single(named("baseHttpClient")) {
|
single(named("baseHttpClient")) {
|
||||||
HttpClient {
|
HttpClient {
|
||||||
|
|||||||
+54
-20
@@ -21,6 +21,8 @@ import at.mocode.desktop.screens.onboarding.SettingsManager
|
|||||||
import at.mocode.frontend.core.designsystem.theme.AppColors
|
import at.mocode.frontend.core.designsystem.theme.AppColors
|
||||||
import at.mocode.frontend.core.designsystem.theme.Dimens
|
import at.mocode.frontend.core.designsystem.theme.Dimens
|
||||||
import at.mocode.frontend.core.navigation.AppScreen
|
import at.mocode.frontend.core.navigation.AppScreen
|
||||||
|
import at.mocode.frontend.core.network.ConnectivityTracker
|
||||||
|
import at.mocode.frontend.core.network.discovery.NetworkDiscoveryService
|
||||||
import at.mocode.frontend.features.billing.presentation.BillingScreen
|
import at.mocode.frontend.features.billing.presentation.BillingScreen
|
||||||
import at.mocode.frontend.features.billing.presentation.BillingViewModel
|
import at.mocode.frontend.features.billing.presentation.BillingViewModel
|
||||||
import at.mocode.frontend.features.nennung.presentation.NennungViewModel
|
import at.mocode.frontend.features.nennung.presentation.NennungViewModel
|
||||||
@@ -40,8 +42,10 @@ import at.mocode.turnier.feature.presentation.TurnierDetailScreen
|
|||||||
import at.mocode.veranstaltung.feature.presentation.AdminUebersichtScreen
|
import at.mocode.veranstaltung.feature.presentation.AdminUebersichtScreen
|
||||||
import at.mocode.veranstaltung.feature.presentation.VeranstaltungDetailScreen
|
import at.mocode.veranstaltung.feature.presentation.VeranstaltungDetailScreen
|
||||||
import at.mocode.veranstaltung.feature.presentation.VeranstaltungNeuScreen
|
import at.mocode.veranstaltung.feature.presentation.VeranstaltungNeuScreen
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import org.koin.compose.koinInject
|
import org.koin.compose.koinInject
|
||||||
import org.koin.compose.viewmodel.koinViewModel
|
import org.koin.compose.viewmodel.koinViewModel
|
||||||
|
import kotlin.time.Duration.Companion.milliseconds
|
||||||
|
|
||||||
// Primärfarbe der TopBar (kann später ins Theme ausgelagert werden)
|
// Primärfarbe der TopBar (kann später ins Theme ausgelagert werden)
|
||||||
private val TopBarColor = Color(0xFF1E3A8A)
|
private val TopBarColor = Color(0xFF1E3A8A)
|
||||||
@@ -91,7 +95,7 @@ fun DesktopMainLayout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
HorizontalDivider(thickness = Dimens.BorderThin, color = MaterialTheme.colorScheme.outlineVariant)
|
HorizontalDivider(thickness = Dimens.BorderThin, color = MaterialTheme.colorScheme.outlineVariant)
|
||||||
DesktopFooterBar()
|
DesktopFooterBar(settings = onboardingSettings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,7 +253,10 @@ private fun DesktopTopHeader(
|
|||||||
BreadcrumbContent(currentScreen, onNavigate)
|
BreadcrumbContent(currentScreen, onNavigate)
|
||||||
}
|
}
|
||||||
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(Dimens.SpacingM)) {
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(Dimens.SpacingM)
|
||||||
|
) {
|
||||||
// Profil / Logout Bereich
|
// Profil / Logout Bereich
|
||||||
Text(
|
Text(
|
||||||
text = "Administrator",
|
text = "Administrator",
|
||||||
@@ -296,6 +303,7 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.VeranstalterDetail -> {
|
is AppScreen.VeranstalterDetail -> {
|
||||||
BreadcrumbSeparator()
|
BreadcrumbSeparator()
|
||||||
Text(
|
Text(
|
||||||
@@ -309,6 +317,7 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.VeranstaltungProfil -> {
|
is AppScreen.VeranstaltungProfil -> {
|
||||||
BreadcrumbSeparator()
|
BreadcrumbSeparator()
|
||||||
Text(
|
Text(
|
||||||
@@ -330,6 +339,7 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.VeranstaltungDetail -> {
|
is AppScreen.VeranstaltungDetail -> {
|
||||||
BreadcrumbSeparator()
|
BreadcrumbSeparator()
|
||||||
Text(
|
Text(
|
||||||
@@ -337,6 +347,7 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.VeranstaltungNeu -> {
|
is AppScreen.VeranstaltungNeu -> {
|
||||||
BreadcrumbSeparator()
|
BreadcrumbSeparator()
|
||||||
Text(
|
Text(
|
||||||
@@ -344,6 +355,7 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.TurnierDetail -> {
|
is AppScreen.TurnierDetail -> {
|
||||||
BreadcrumbSeparator()
|
BreadcrumbSeparator()
|
||||||
Text(
|
Text(
|
||||||
@@ -359,6 +371,7 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.Billing -> {
|
is AppScreen.Billing -> {
|
||||||
BreadcrumbSeparator()
|
BreadcrumbSeparator()
|
||||||
Text(
|
Text(
|
||||||
@@ -382,6 +395,7 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.TurnierNeu -> {
|
is AppScreen.TurnierNeu -> {
|
||||||
BreadcrumbSeparator()
|
BreadcrumbSeparator()
|
||||||
Text(
|
Text(
|
||||||
@@ -413,6 +427,7 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.Meisterschaften -> {
|
is AppScreen.Meisterschaften -> {
|
||||||
BreadcrumbSeparator()
|
BreadcrumbSeparator()
|
||||||
Text(
|
Text(
|
||||||
@@ -420,6 +435,7 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.Cups -> {
|
is AppScreen.Cups -> {
|
||||||
BreadcrumbSeparator()
|
BreadcrumbSeparator()
|
||||||
Text(
|
Text(
|
||||||
@@ -427,21 +443,22 @@ private fun BreadcrumbContent(
|
|||||||
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.SemiBold),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hilfsfunktion: OEPS-Bundeslandcode → Abkürzung
|
// Hilfsfunktion: OEPS-Bundeslandcode → Abkürzung
|
||||||
private fun mapOepsToBundesland(code: String): String = when (code.uppercase()) {
|
private fun mapOepsToBundesland(code: String): String = when (code.uppercase()) {
|
||||||
"OOE" -> "OÖ"
|
"OÖ" -> "Oberösterreich"
|
||||||
"NOE" -> "NÖ"
|
"NÖ" -> "Niederösterreich"
|
||||||
"ST" -> "Stmk."
|
"ST" -> "Steiermark"
|
||||||
"W" -> "Wien"
|
"W" -> "Wien"
|
||||||
"BGLD", "B" -> "Bgld."
|
"B" -> "Burgenland"
|
||||||
"K" -> "Ktn."
|
"K" -> "Kärnten"
|
||||||
"S" -> "Sbg."
|
"S" -> "Salzburg"
|
||||||
"T" -> "Tirol"
|
"T" -> "Tirol"
|
||||||
"V" -> "Vbg."
|
"V" -> "Vorarlberg"
|
||||||
else -> code
|
else -> code
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,6 +638,7 @@ private fun DesktopContentArea(
|
|||||||
onCancel = onBack,
|
onCancel = onBack,
|
||||||
onVereinCreated = { newId -> onNavigate(AppScreen.VeranstalterProfil(newId)) }
|
onVereinCreated = { newId -> onNavigate(AppScreen.VeranstalterProfil(newId)) }
|
||||||
)
|
)
|
||||||
|
|
||||||
is AppScreen.VeranstalterDetail -> {
|
is AppScreen.VeranstalterDetail -> {
|
||||||
val vId = currentScreen.veranstalterId
|
val vId = currentScreen.veranstalterId
|
||||||
if (vId != 1L) { // Temporärer Check für Mock-Daten
|
if (vId != 1L) { // Temporärer Check für Mock-Daten
|
||||||
@@ -637,6 +655,7 @@ private fun DesktopContentArea(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.VeranstaltungKonfig -> {
|
is AppScreen.VeranstaltungKonfig -> {
|
||||||
val vId = currentScreen.veranstalterId
|
val vId = currentScreen.veranstalterId
|
||||||
// Falls vId == 0, kommen wir aus der Gesamtübersicht und wählen erst im Wizard
|
// Falls vId == 0, kommen wir aus der Gesamtübersicht und wählen erst im Wizard
|
||||||
@@ -694,7 +713,8 @@ private fun DesktopContentArea(
|
|||||||
val v = at.mocode.desktop.v2.StoreV2.vereine.firstOrNull { vv ->
|
val v = at.mocode.desktop.v2.StoreV2.vereine.firstOrNull { vv ->
|
||||||
at.mocode.desktop.v2.StoreV2.eventsFor(vv.id).any { it.id == currentScreen.id }
|
at.mocode.desktop.v2.StoreV2.eventsFor(vv.id).any { it.id == currentScreen.id }
|
||||||
}
|
}
|
||||||
val veranstaltung = v?.let { at.mocode.desktop.v2.StoreV2.eventsFor(it.id).firstOrNull { e -> e.id == currentScreen.id } }
|
val veranstaltung =
|
||||||
|
v?.let { at.mocode.desktop.v2.StoreV2.eventsFor(it.id).firstOrNull { e -> e.id == currentScreen.id } }
|
||||||
val list = at.mocode.desktop.v2.TurnierStoreV2.list(currentScreen.id)
|
val list = at.mocode.desktop.v2.TurnierStoreV2.list(currentScreen.id)
|
||||||
val newId = (list.maxOfOrNull { it.id } ?: 0L) + 1L
|
val newId = (list.maxOfOrNull { it.id } ?: 0L) + 1L
|
||||||
val draft = at.mocode.desktop.v2.TurnierV2(
|
val draft = at.mocode.desktop.v2.TurnierV2(
|
||||||
@@ -709,6 +729,7 @@ private fun DesktopContentArea(
|
|||||||
},
|
},
|
||||||
onTurnierOeffnen = { tid -> onNavigate(AppScreen.TurnierDetail(currentScreen.id, tid)) },
|
onTurnierOeffnen = { tid -> onNavigate(AppScreen.TurnierDetail(currentScreen.id, tid)) },
|
||||||
)
|
)
|
||||||
|
|
||||||
is AppScreen.VeranstaltungNeu -> VeranstaltungNeuScreen(
|
is AppScreen.VeranstaltungNeu -> VeranstaltungNeuScreen(
|
||||||
onBack = onBack,
|
onBack = onBack,
|
||||||
onSave = { onBack() },
|
onSave = { onBack() },
|
||||||
@@ -743,6 +764,7 @@ private fun DesktopContentArea(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is AppScreen.TurnierNeu -> {
|
is AppScreen.TurnierNeu -> {
|
||||||
val evtId = currentScreen.veranstaltungId
|
val evtId = currentScreen.veranstaltungId
|
||||||
// V2: Wir erlauben Turnier-Nr nur, wenn die Veranstaltung im V2-Store existiert
|
// V2: Wir erlauben Turnier-Nr nur, wenn die Veranstaltung im V2-Store existiert
|
||||||
@@ -832,11 +854,22 @@ private fun DesktopContentArea(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DesktopFooterBar() {
|
private fun DesktopFooterBar(settings: OnboardingSettings) {
|
||||||
// Echte Status-Logik vorbereitet
|
val connectivityTracker = koinInject<ConnectivityTracker>()
|
||||||
val online = remember { mutableStateOf(true) }
|
val discoveryService = koinInject<NetworkDiscoveryService>()
|
||||||
val deviceConnected = remember { mutableStateOf(true) }
|
|
||||||
val deviceName = "Richter-Turm"
|
val online by connectivityTracker.isOnline.collectAsState()
|
||||||
|
val discoveredServices = remember { mutableStateOf(discoveryService.getDiscoveredServices()) }
|
||||||
|
val deviceName = settings.geraetName.ifBlank { "Unbekannt" }
|
||||||
|
|
||||||
|
// Periodisches Update der LAN-Geräte (mDNS)
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
discoveryService.startDiscovery()
|
||||||
|
while (true) {
|
||||||
|
discoveredServices.value = discoveryService.getDiscoveredServices()
|
||||||
|
delay(5000.milliseconds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Surface(
|
Surface(
|
||||||
color = MaterialTheme.colorScheme.surface,
|
color = MaterialTheme.colorScheme.surface,
|
||||||
@@ -854,18 +887,19 @@ private fun DesktopFooterBar() {
|
|||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
// Status: Cloud Sync
|
// Status: Cloud Sync
|
||||||
StatusIndicator(
|
StatusIndicator(
|
||||||
icon = if (online.value) Icons.Filled.CloudDone else Icons.Filled.CloudOff,
|
icon = if (online) Icons.Filled.CloudDone else Icons.Filled.CloudOff,
|
||||||
label = if (online.value) "Cloud synchronisiert" else "Offline (Lokal)",
|
label = if (online) "Cloud synchronisiert" else "Offline (Lokal)",
|
||||||
color = if (online.value) Color(0xFF2E7D32) else MaterialTheme.colorScheme.error
|
color = if (online) Color(0xFF2E7D32) else MaterialTheme.colorScheme.error
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(Modifier.width(Dimens.SpacingM))
|
Spacer(Modifier.width(Dimens.SpacingM))
|
||||||
|
|
||||||
// Status: LAN Devices (mDNS)
|
// Status: LAN Devices (mDNS)
|
||||||
|
val deviceCount = discoveredServices.value.size
|
||||||
StatusIndicator(
|
StatusIndicator(
|
||||||
icon = Icons.Filled.Lan,
|
icon = Icons.Filled.Lan,
|
||||||
label = if (deviceConnected.value) "Verbunden: $deviceName" else "Suche nach Geräten...",
|
label = if (deviceCount > 0) "Verbunden: $deviceName ($deviceCount im Netz)" else "Lokal: $deviceName",
|
||||||
color = if (deviceConnected.value) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.outline
|
color = if (deviceCount > 0) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.outline
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user