mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 18:39:55 +02:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user