Is there a multiplatform library that provides inf...
# multiplatform
z
Is there a multiplatform library that provides information about the operating system and hardware the program is running on? Something like this but KMP: https://github.com/oshi/oshi
b
Would be nice indeed. till then you can use the following an improve upon it
Copy code
Platform.kt

interface Platform {
    val name: String
}

expect fun getPlatform(): Platform


Platform.ios.kt

class IOSPlatform: Platform {
    override val name: String = "My app name; iOS; ${UIDevice.currentDevice.systemName()}; ${UIDevice.currentDevice.systemVersion}"
}

actual fun getPlatform(): Platform = IOSPlatform()



Platform.jvm.kt

class JVMPlatform: Platform {
    override val name: String = "My app name; Desktop; Java ${System.getProperty("java.version")}; ${System.getProperty("os.name")}"
}

actual fun getPlatform(): Platform = JVMPlatform()



Platform.android.kt

class AndroidPlatform : Platform {
    private val manufacturer = Build.MANUFACTURER
    private val model = Build.MODEL
    private val versionApi = Build.VERSION.SDK_INT
    private val versionRelease = Build.VERSION.RELEASE

    override val name: String = "My app name; Android; $versionRelease ($versionApi); $manufacturer - $model"
}

actual fun getPlatform(): Platform = AndroidPlatform()



Platform.wasm.kt

class WasmPlatform: Platform {
    override val name: String = "Web with Kotlin/Wasm" // TODO browser details
}

actual fun getPlatform(): Platform = WasmPlatform()
z
I might try to make this a reality. I'm curious if it would be better to write my own JVM code so that it can be fully kotlin or to bridge to the oshi library
b
It would only be for the JVM but sure it's totally acceptable to delegate that to OSHI