Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
20bc1d2f
Unverified
Commit
20bc1d2f
authored
Jun 29, 2023
by
Ivan Matkov
Committed by
GitHub
Jun 29, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add OsVersion (#732)
parent
d1b97510
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
13 deletions
+52
-13
OsVersion.kt
skiko/src/commonMain/kotlin/org/jetbrains/skiko/OsVersion.kt
+27
-0
OsVersion.apple.kt
.../darwinMain/kotlin/org/jetbrains/skiko/OsVersion.apple.kt
+16
-0
SystemTheme.ios.kt
...src/iosMain/kotlin/org/jetbrains/skiko/SystemTheme.ios.kt
+9
-13
No files found.
skiko/src/commonMain/kotlin/org/jetbrains/skiko/OsVersion.kt
0 → 100644
View file @
20bc1d2f
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
}
}
skiko/src/darwinMain/kotlin/org/jetbrains/skiko/OsVersion.apple.kt
0 → 100644
View file @
20bc1d2f
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
skiko/src/iosMain/kotlin/org/jetbrains/skiko/SystemTheme.ios.kt
View file @
20bc1d2f
package
org.jetbrains.skiko
import
kotlinx.cinterop.useContents
import
platform.
Foundation.NSProcessInfo
import
platform.UIKit.
*
import
platform.UIKit.
UIUserInterfaceStyle.*
import
platform.UIKit.UITraitCollection
import
platform.
UIKit.UIUserInterfaceStyle.UIUserInterfaceStyleDark
import
platform.UIKit.
UIUserInterfaceStyle.UIUserInterfaceStyleLight
import
platform.UIKit.
currentTraitCollection
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
)
{
UIUserInterfaceStyleDark
->
SystemTheme
.
DARK
UIUserInterfaceStyleLight
->
SystemTheme
.
LIGHT
...
...
@@ -15,11 +19,3 @@ actual val currentSystemTheme: SystemTheme
}
else
{
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment