Platform Detection
Kore provides a type-safe way to detect the underlying operating system and environment. This avoids the use of "magic strings" and provides a consistent API across all Kotlin targets.
The Platform Object
The main entry point is the com.davils.kore.system.platform.Platform object. It provides boolean properties for quick checks and access to the current Os enum.
Operating System Checks
You can check for specific operating systems using the following properties:
Platform.isWindowsPlatform.isLinuxPlatform.isMacosPlatform.isIosPlatform.isAndroidPlatform.isTvOsPlatform.isWatchOs
Grouped Checks
For convenience, some platforms are grouped:
Platform.isApple: Returnstruefor macOS, iOS, tvOS, and watchOS.Platform.isUnix: Returnstruefor Linux and all Apple platforms.Platform.isMobile: Returnstruefor iOS and Android.
Environment Checks
You can also detect the runtime environment:
Platform.isJvm: Returnstrueif running on a Java Virtual Machine (including Android).Platform.isWeb: Returnstrueif running in a Browser (either JS or Wasm).
The Os Enum
If you need to perform more complex logic or use a when expression, you can access Platform.current, which returns an Os enum value.
Internal Detection
Under the hood, Kore uses expect/actual declarations with the OsDetector object to provide native performance and accuracy for each target platform.