|
@@ -1,27 +1,37 @@
|
|
|
package eu.mjdev.desktop.components.controlcenter.pages
|
|
package eu.mjdev.desktop.components.controlcenter.pages
|
|
|
|
|
|
|
|
import androidx.compose.desktop.ui.tooling.preview.Preview
|
|
import androidx.compose.desktop.ui.tooling.preview.Preview
|
|
|
|
|
+import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.layout.*
|
|
import androidx.compose.foundation.layout.*
|
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
|
|
|
+import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
|
|
+import androidx.compose.material.*
|
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.Icons
|
|
|
import androidx.compose.material.icons.filled.Wifi
|
|
import androidx.compose.material.icons.filled.Wifi
|
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.runtime.collectAsState
|
|
import androidx.compose.runtime.collectAsState
|
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.runtime.setValue
|
|
|
|
|
+import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
+import androidx.compose.ui.text.font.FontWeight
|
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
|
|
|
+import androidx.compose.ui.unit.dp
|
|
|
import eu.mjdev.desktop.components.controlcenter.base.ControlCenterPage
|
|
import eu.mjdev.desktop.components.controlcenter.base.ControlCenterPage
|
|
|
import eu.mjdev.desktop.components.text.TextAny
|
|
import eu.mjdev.desktop.components.text.TextAny
|
|
|
|
|
+import eu.mjdev.desktop.data.WifiInfo
|
|
|
|
|
+import eu.mjdev.desktop.extensions.ColorUtils.alpha
|
|
|
import eu.mjdev.desktop.extensions.Compose.launchedEffect
|
|
import eu.mjdev.desktop.extensions.Compose.launchedEffect
|
|
|
import eu.mjdev.desktop.extensions.Compose.rememberState
|
|
import eu.mjdev.desktop.extensions.Compose.rememberState
|
|
|
|
|
+import eu.mjdev.desktop.extensions.Custom.flowBlock
|
|
|
import eu.mjdev.desktop.helpers.system.Shell
|
|
import eu.mjdev.desktop.helpers.system.Shell
|
|
|
import eu.mjdev.desktop.helpers.system.Shell.Companion.CMD_NMCLI
|
|
import eu.mjdev.desktop.helpers.system.Shell.Companion.CMD_NMCLI
|
|
|
|
|
+import eu.mjdev.desktop.provider.DesktopScope.Companion.withDesktopScope
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.delay
|
|
import kotlinx.coroutines.delay
|
|
|
-import kotlinx.coroutines.flow.flow
|
|
|
|
|
import kotlinx.coroutines.flow.flowOn
|
|
import kotlinx.coroutines.flow.flowOn
|
|
|
|
|
+import eu.mjdev.desktop.components.icon.WifiLevelIcon
|
|
|
|
|
|
|
|
// nmcli -t -f ALL dev wifi
|
|
// nmcli -t -f ALL dev wifi
|
|
|
// nmcli device show
|
|
// nmcli device show
|
|
@@ -32,11 +42,8 @@ fun WifiSettingsPage() = ControlCenterPage(
|
|
|
condition = { connectionManager.isWifiAdapterAvailable }
|
|
condition = { connectionManager.isWifiAdapterAvailable }
|
|
|
) {
|
|
) {
|
|
|
var lastSeen by rememberState(0L)
|
|
var lastSeen by rememberState(0L)
|
|
|
- val list by flow<List<List<String>>> {
|
|
|
|
|
- Shell.executeAndReadLines(
|
|
|
|
|
- CMD_NMCLI, "-t", " -f", "ALL", "dev", "wifi"
|
|
|
|
|
- ).map { ws ->
|
|
|
|
|
- println(ws)
|
|
|
|
|
|
|
+ val list by flowBlock {
|
|
|
|
|
+ Shell.executeAndReadLines(CMD_NMCLI, "-t", "-f", "ALL", "dev", "wifi").map { ws ->
|
|
|
ws.split(":")
|
|
ws.split(":")
|
|
|
}
|
|
}
|
|
|
}.flowOn(Dispatchers.IO).collectAsState(emptyList())
|
|
}.flowOn(Dispatchers.IO).collectAsState(emptyList())
|
|
@@ -48,7 +55,7 @@ fun WifiSettingsPage() = ControlCenterPage(
|
|
|
) {
|
|
) {
|
|
|
list.forEach { wr ->
|
|
list.forEach { wr ->
|
|
|
item {
|
|
item {
|
|
|
- WifiRow(wr)
|
|
|
|
|
|
|
+ WifiRow(WifiInfo(wr))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -59,40 +66,59 @@ fun WifiSettingsPage() = ControlCenterPage(
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 0 : AP[n]
|
|
|
|
|
-// 1 : ssid
|
|
|
|
|
-// 2 : ? 57692D737472656C
|
|
|
|
|
-// 3 : IPV6 or IP
|
|
|
|
|
-// 4 : ? Infra
|
|
|
|
|
-// 5 : freq type
|
|
|
|
|
-// 6 : speed
|
|
|
|
|
-// 7 : freq
|
|
|
|
|
-// 8 : level in db
|
|
|
|
|
-// 9 : level semi-graph
|
|
|
|
|
-// 10 : encryption
|
|
|
|
|
-// 11 : ?
|
|
|
|
|
-// 12 : device
|
|
|
|
|
-// 14 : ?
|
|
|
|
|
-// 15 : connected [* || ""]
|
|
|
|
|
-// 16 : config point
|
|
|
|
|
@Composable
|
|
@Composable
|
|
|
-fun WifiRow(item: List<String>) = Row(
|
|
|
|
|
- modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
-) {
|
|
|
|
|
- TextAny(
|
|
|
|
|
- modifier = Modifier.weight(1f),
|
|
|
|
|
- text = item.getOrNull(1).orEmpty(),
|
|
|
|
|
- color = Color.White,
|
|
|
|
|
- textAlign = TextAlign.Start,
|
|
|
|
|
- textSelectionEnabled = true
|
|
|
|
|
- )
|
|
|
|
|
- TextAny(
|
|
|
|
|
- modifier = Modifier.wrapContentWidth(),
|
|
|
|
|
- text = item.getOrNull(9).orEmpty(),
|
|
|
|
|
- color = Color.White,
|
|
|
|
|
- textAlign = TextAlign.Start,
|
|
|
|
|
- textSelectionEnabled = true
|
|
|
|
|
- )
|
|
|
|
|
|
|
+fun WifiRow(
|
|
|
|
|
+ info: WifiInfo
|
|
|
|
|
+) = withDesktopScope {
|
|
|
|
|
+ Row(
|
|
|
|
|
+ modifier = Modifier
|
|
|
|
|
+ .padding(4.dp)
|
|
|
|
|
+ .fillMaxWidth()
|
|
|
|
|
+ .background(
|
|
|
|
|
+ Color.White.copy(alpha = 0.1f),
|
|
|
|
|
+ RoundedCornerShape(8.dp)
|
|
|
|
|
+ )
|
|
|
|
|
+ .padding(8.dp),
|
|
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
|
|
+ ) {
|
|
|
|
|
+ TextAny(
|
|
|
|
|
+ modifier = Modifier.weight(1f),
|
|
|
|
|
+ text = info.ssid,
|
|
|
|
|
+ color = textColor,
|
|
|
|
|
+ fontWeight = FontWeight.Bold,
|
|
|
|
|
+ textAlign = TextAlign.Start,
|
|
|
|
|
+ singleLine = true,
|
|
|
|
|
+ textSelectionEnabled = false
|
|
|
|
|
+ )
|
|
|
|
|
+ Row(
|
|
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
|
|
+ ) {
|
|
|
|
|
+ TextAny(
|
|
|
|
|
+ modifier = Modifier.padding(start = 8.dp).wrapContentWidth(),
|
|
|
|
|
+ text = info.encryption,
|
|
|
|
|
+ fontWeight = FontWeight.Bold,
|
|
|
|
|
+ color = textColor,
|
|
|
|
|
+ textAlign = TextAlign.Start,
|
|
|
|
|
+ singleLine = true,
|
|
|
|
|
+ textSelectionEnabled = false
|
|
|
|
|
+ )
|
|
|
|
|
+ WifiLevelIcon(
|
|
|
|
|
+ modifier = Modifier.padding(start = 8.dp).size(28.dp),
|
|
|
|
|
+ color = textColor,
|
|
|
|
|
+ level = info.signalLevel.toInt()
|
|
|
|
|
+ )
|
|
|
|
|
+ RadioButton(
|
|
|
|
|
+ modifier = Modifier.padding(start = 8.dp).size(24.dp),
|
|
|
|
|
+ selected = true,
|
|
|
|
|
+ onClick = {},
|
|
|
|
|
+ colors = RadioButtonDefaults.colors(
|
|
|
|
|
+ selectedColor = textColor,
|
|
|
|
|
+ unselectedColor = textColor,
|
|
|
|
|
+ disabledColor = textColor.alpha(0.5f)
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Preview
|
|
@Preview
|