diff --git a/compositeBuilds/shared/platform/src/main/kotlin/ir/amirab/util/platform/Platform.kt b/compositeBuilds/shared/platform/src/main/kotlin/ir/amirab/util/platform/Platform.kt index ff7f976..5290c8e 100644 --- a/compositeBuilds/shared/platform/src/main/kotlin/ir/amirab/util/platform/Platform.kt +++ b/compositeBuilds/shared/platform/src/main/kotlin/ir/amirab/util/platform/Platform.kt @@ -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 +} diff --git a/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/App.kt b/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/App.kt index 63521dd..8eeb809 100644 --- a/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/App.kt +++ b/desktop/app/src/main/kotlin/com/abdownloadmanager/desktop/App.kt @@ -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