Skip to content

Commit

Permalink
Core: Add debug flag and rename Platform to AppPlatform (#422)
Browse files Browse the repository at this point in the history
### TL;DR
Added debug flag detection and improved platform-specific information handling across Android and iOS.

### What changed?
- Renamed `Platform` interface to `AppPlatform` and `getPlatform()` to `getAppPlatform()`
- Added `isDebug()` function to detect debug builds on both platforms
- Enabled BuildConfig for Android to support debug detection
- Updated `LocalPlatformTypeProvider` to use `staticCompositionLocalOf` with proper platform initialization
- Implemented platform-specific debug detection (BuildConfig.DEBUG for Android, Platform.isDebugBinary for iOS)

### How to test?
1. Build and run the app in both debug and release configurations
2. Verify that `isDebug()` returns the correct boolean value for each build type
3. Confirm platform information is correctly displayed
4. Check that platform-specific features work as expected on both Android and iOS

### Why make this change?
To provide a more robust way to detect debug builds across platforms and improve the platform-specific information architecture. This enables better debugging capabilities and platform-specific optimizations in the codebase.
  • Loading branch information
ksharma-xyz authored Dec 4, 2024
1 parent dd98943 commit 9f04ee0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import org.koin.compose.KoinApplication
import xyz.ksharma.krail.core.appinfo.LocalPlatformTypeProvider
import xyz.ksharma.krail.core.appinfo.getPlatform
import xyz.ksharma.krail.core.appinfo.getAppPlatform
import xyz.ksharma.krail.di.koinConfig
import xyz.ksharma.krail.taj.theme.KrailTheme

@Composable
fun KrailApp() {
KoinApplication(application = koinConfig) {
CompositionLocalProvider(LocalPlatformTypeProvider provides getPlatform().type) {
CompositionLocalProvider(LocalPlatformTypeProvider provides getAppPlatform()) {
KrailTheme {
KrailNavHost()
}
Expand Down
4 changes: 4 additions & 0 deletions core/app-info/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ plugins {

android {
namespace = "xyz.ksharma.krail.core.appinfo"

buildFeatures {
buildConfig = true
}
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package xyz.ksharma.krail.core.appinfo

import android.os.Build

class AndroidPlatform : Platform {
class AndroidAppPlatform : AppPlatform {
override val name: String = "Android ${Build.VERSION.SDK_INT}"
override val type: PlatformType = PlatformType.ANDROID
override fun isDebug(): Boolean = BuildConfig.DEBUG
}

actual fun getPlatform(): Platform = AndroidPlatform()
actual fun getAppPlatform(): AppPlatform = AndroidAppPlatform()
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package xyz.ksharma.krail.core.appinfo

interface Platform {
interface AppPlatform {
val name: String
val type: PlatformType

fun isDebug(): Boolean
}

enum class PlatformType {
Expand All @@ -11,4 +13,4 @@ enum class PlatformType {
UNKNOWN,
}

expect fun getPlatform(): Platform
expect fun getAppPlatform(): AppPlatform
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package xyz.ksharma.krail.core.appinfo

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.staticCompositionLocalOf

val LocalPlatformTypeProvider = compositionLocalOf { PlatformType.UNKNOWN }
val LocalPlatformTypeProvider = staticCompositionLocalOf { getAppPlatform() }
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package xyz.ksharma.krail.core.appinfo

import platform.UIKit.UIDevice
import kotlin.experimental.ExperimentalNativeApi

class IOSPlatform : Platform {
class IOSAppPlatform : AppPlatform {
override val name: String =
UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion

override val type: PlatformType = PlatformType.IOS

@OptIn(ExperimentalNativeApi::class)
override fun isDebug(): Boolean = Platform.isDebugBinary
}

actual fun getPlatform(): Platform = IOSPlatform()
actual fun getAppPlatform(): AppPlatform = IOSAppPlatform()

0 comments on commit 9f04ee0

Please sign in to comment.