fix(conifg): implement sessionPasskey handling for admin requests (#1263)

This commit is contained in:
Andre K 2024-09-20 06:07:35 -03:00 committed by GitHub
parent 16b822cec4
commit 36a13d7687
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 68 additions and 29 deletions

View file

@ -163,6 +163,14 @@ class DeviceSettingsFragment : ScreenFragment("Radio Configuration"), Logging {
}
}
enum class AdminRoute(@StringRes val title: Int) {
REBOOT(R.string.reboot),
SHUTDOWN(R.string.shutdown),
FACTORY_RESET(R.string.factory_reset),
NODEDB_RESET(R.string.nodedb_reset),
;
}
// Config (configType = AdminProtos.AdminMessage.ConfigType)
enum class ConfigRoute(val title: String, val configType: Int = 0) {
USER("User"),
@ -197,6 +205,7 @@ enum class ModuleRoute(val title: String, val configType: Int = 0) {
}
private fun getName(route: Any): String = when (route) {
is AdminRoute -> route.name
is ConfigRoute -> route.name
is ModuleRoute -> route.name
else -> ""
@ -304,8 +313,11 @@ fun RadioConfigNavHost(
},
onComplete = {
val route = radioConfigState.route
if (route.isNotEmpty()) navController.navigate(route)
viewModel.clearPacketResponse()
if (ConfigRoute.entries.any { it.name == route } ||
ModuleRoute.entries.any { it.name == route }) {
navController.navigate(route)
viewModel.clearPacketResponse()
}
}
)
@ -346,20 +358,8 @@ fun RadioConfigNavHost(
showEditDeviceProfileDialog = true
}
"REBOOT" -> {
viewModel.requestReboot(destNum)
}
"SHUTDOWN" -> {
viewModel.requestShutdown(destNum)
}
"FACTORY_RESET" -> {
viewModel.requestFactoryReset(destNum)
}
"NODEDB_RESET" -> {
viewModel.requestNodedbReset(destNum)
is AdminRoute -> {
viewModel.getSessionPasskey(destNum)
}
is ConfigRoute -> {
@ -753,10 +753,7 @@ private fun RadioSettingsScreen(
item { NavCard("Export configuration", enabled = enabled) { onRouteClick("EXPORT") } }
}
item { NavButton(R.string.reboot, enabled) { onRouteClick("REBOOT") } }
item { NavButton(R.string.shutdown, enabled) { onRouteClick("SHUTDOWN") } }
item { NavButton(R.string.factory_reset, enabled) { onRouteClick("FACTORY_RESET") } }
item { NavButton(R.string.nodedb_reset, enabled) { onRouteClick("NODEDB_RESET") } }
items(AdminRoute.entries) { NavButton(it.title, enabled) { onRouteClick(it) } }
}
}