Unverified Commit 20bc1d2f authored by Ivan Matkov's avatar Ivan Matkov Committed by GitHub

Add OsVersion (#732)

parent d1b97510
package org.jetbrains.skiko
data class OSVersion(
val major: Int,
val minor: Int = 0,
val patch: Int = 0
) : Comparable<OSVersion> {
init {
require(major >= 0) { "Major version must be a positive number" }
require(minor >= 0) { "Minor version must be a positive number" }
require(patch >= 0) { "Patch version must be a positive number" }
}
override fun toString(): String = "$major.$minor.$patch"
override fun compareTo(other: OSVersion): Int {
if (major > other.major) return 1
if (major < other.major) return -1
if (minor > other.minor) return 1
if (minor < other.minor) return -1
if (patch > other.patch) return 1
if (patch < other.patch) return -1
return 0
}
}
package org.jetbrains.skiko
import kotlinx.cinterop.useContents
import platform.Foundation.NSProcessInfo
val hostOSVersion: OSVersion
get() = NSProcessInfo.processInfo.operatingSystemVersion.useContents {
OSVersion(
majorVersion.toInt(),
minorVersion.toInt(),
patchVersion.toInt()
)
}
fun available(vararg pairs: Pair<OS, OSVersion>) =
pairs.find { it.first == hostOs }?.let { it.second <= hostOSVersion } ?: false
package org.jetbrains.skiko package org.jetbrains.skiko
import kotlinx.cinterop.useContents import platform.UIKit.UITraitCollection
import platform.Foundation.NSProcessInfo import platform.UIKit.UIUserInterfaceStyle.UIUserInterfaceStyleDark
import platform.UIKit.* import platform.UIKit.UIUserInterfaceStyle.UIUserInterfaceStyleLight
import platform.UIKit.UIUserInterfaceStyle.* import platform.UIKit.currentTraitCollection
actual val currentSystemTheme: SystemTheme actual val currentSystemTheme: SystemTheme
get() = if (supportsCurrentTraitCollectionApi) { get() = if (available(OS.Ios to OSVersion(13))) {
/*
* Getting trait collection for the current execution context supports only on iOS 13.0+
* https://developer.apple.com/documentation/uikit/uitraitcollection/3238080-currenttraitcollection?language=objc
*/
when (UITraitCollection.currentTraitCollection.userInterfaceStyle) { when (UITraitCollection.currentTraitCollection.userInterfaceStyle) {
UIUserInterfaceStyleDark -> SystemTheme.DARK UIUserInterfaceStyleDark -> SystemTheme.DARK
UIUserInterfaceStyleLight -> SystemTheme.LIGHT UIUserInterfaceStyleLight -> SystemTheme.LIGHT
...@@ -15,11 +19,3 @@ actual val currentSystemTheme: SystemTheme ...@@ -15,11 +19,3 @@ actual val currentSystemTheme: SystemTheme
} else { } else {
SystemTheme.LIGHT SystemTheme.LIGHT
} }
/*
* Getting trait collection for the current execution context supports only on iOS 13.0+
* https://developer.apple.com/documentation/uikit/uitraitcollection/3238080-currenttraitcollection?language=objc
*/
private val supportsCurrentTraitCollectionApi get() = NSProcessInfo.processInfo.operatingSystemVersion.useContents {
majorVersion >= 13
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment