feat(platform): add device info and network summary support

This adds DeviceInfo to the Platform interface and implements it for Android, iOS, and JVM, including battery level and active network summary where available.

Co-authored-by: Junie <junie@jetbrains.com>
This commit is contained in:
2026-07-07 16:55:27 +02:00
parent 3d52e62e81
commit 912874fd0c
5 changed files with 109 additions and 2 deletions

View File

@@ -1,11 +1,37 @@
package com.vnidrop.app
import java.net.NetworkInterface
class JVMPlatform : Platform {
override val name: String = "Java ${System.getProperty("java.version")}"
override val defaultCoreDataDir: String =
System.getProperty("user.home") + "/.vnidrop"
override val defaultReceiveDir: String =
System.getProperty("user.home") + "/Downloads"
override val deviceInfo: DeviceInfo = DeviceInfo(
deviceName = System.getenv("COMPUTERNAME")
?: System.getenv("HOSTNAME")
?: System.getProperty("user.name"),
deviceModel = listOfNotNull(
System.getProperty("os.arch"),
System.getProperty("java.vm.name"),
).joinToString(" | ").ifBlank { null },
operatingSystem = listOfNotNull(
System.getProperty("os.name"),
System.getProperty("os.version"),
).joinToString(" ").ifBlank { name },
network = activeNetworkSummary(),
batteryLevel = null,
)
}
actual fun getPlatform(): Platform = JVMPlatform()
private fun activeNetworkSummary(): String? =
runCatching {
NetworkInterface.getNetworkInterfaces()
.asSequence()
.filter { it.isUp && !it.isLoopback }
.map { it.displayName }
.firstOrNull()
}.getOrNull()