add extensions to platform util

This commit is contained in:
AmirHossein Abdolmotallebi 2025-02-06 21:21:54 +03:30
parent 62a37606fd
commit 5468ed159d
2 changed files with 29 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package ir.amirab.util.platform
import ir.amirab.util.platform.Platform.Android
import ir.amirab.util.platform.Platform.Desktop
import kotlin.contracts.contract
sealed class Platform(val name: String) {
data object Android : Platform("Android")
@ -67,4 +68,30 @@ private class JvmPlatformFinder : PlatformFInder {
sealed interface DesktopPlatform
/**
* use this only in desktop environments
*/
fun PlatformFInder.asDesktop(): Desktop {
val platform = getCurrentPlatform()
if (platform is Desktop) {
return platform
} else {
error("Current platform is not a desktop platform")
}
}
fun PlatformFInder.isWindows(): Boolean {
return getCurrentPlatform() == Desktop.Windows
}
fun PlatformFInder.isMac(): Boolean {
return getCurrentPlatform() == Desktop.MacOS
}
fun PlatformFInder.isLinux(): Boolean {
return getCurrentPlatform() == Desktop.Linux
}
fun PlatformFInder.isAndroid(): Boolean {
return getCurrentPlatform() == Android
}

View File

@ -12,6 +12,7 @@ import com.abdownloadmanager.integration.Integration
import com.abdownloadmanager.shared.utils.DownloadSystem
import com.abdownloadmanager.shared.utils.appinfo.PreviousVersion
import ir.amirab.util.platform.Platform
import ir.amirab.util.platform.isWindows
import kotlinx.coroutines.runBlocking
import okio.Path.Companion.toOkioPath
import org.koin.core.component.KoinComponent
@ -176,7 +177,7 @@ private fun defaultApp(
System.getProperty("skiko.renderApi") != null
if (!customRenderApiRequested) {
if (Platform.getCurrentPlatform() == Platform.Desktop.Windows) {
if (Platform.isWindows()) {
// At the moment default render api have some problems on windows!
// - when I resize a window, the contents of the window will be stretched
// - sometimes when I close a window, the window flashes on exiting