From e93fcca22f3b4079f1d85cdd1fb2200f7f76b681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Santos?= Date: Mon, 29 Jul 2024 13:58:33 +0100 Subject: [PATCH] Logging & Platform Info --- composeApp/build.gradle.kts | 4 +++ .../kotlin/org/ooni/probe/MainActivity.kt | 26 +++++++++++++++--- .../commonMain/kotlin/org/ooni/probe/App.kt | 19 +++++++++++++ .../kotlin/org/ooni/probe/di/Dependencies.kt | 2 ++ .../org/ooni/probe/shared/PlatformInfo.kt | 13 +++++++++ .../org/ooni/probe/MainViewController.kt | 27 ++++++++++++++++++- gradle/libs.versions.toml | 22 +++++++++------ iosApp/iosApp.xcodeproj/project.pbxproj | 18 +++++++++++++ 8 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/org/ooni/probe/shared/PlatformInfo.kt diff --git a/composeApp/build.gradle.kts b/composeApp/build.gradle.kts index cb16a249..6f5f9559 100644 --- a/composeApp/build.gradle.kts +++ b/composeApp/build.gradle.kts @@ -54,6 +54,7 @@ kotlin { implementation(compose.components.resources) implementation(compose.components.uiToolingPreview) implementation(libs.kotlin.serialization) + implementation(libs.bundles.tooling) } all { @@ -95,6 +96,9 @@ android { isMinifyEnabled = false } } + buildFeatures { + buildConfig = true + } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 diff --git a/composeApp/src/androidMain/kotlin/org/ooni/probe/MainActivity.kt b/composeApp/src/androidMain/kotlin/org/ooni/probe/MainActivity.kt index 5034f72c..8dcc5492 100644 --- a/composeApp/src/androidMain/kotlin/org/ooni/probe/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/org/ooni/probe/MainActivity.kt @@ -1,20 +1,38 @@ package org.ooni.probe +import android.os.Build import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import org.ooni.engine.AndroidOonimkallBridge import org.ooni.probe.di.Dependencies +import org.ooni.probe.shared.Platform +import org.ooni.probe.shared.PlatformInfo class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val bridge = AndroidOonimkallBridge() - val dependencies = Dependencies(bridge, filesDir.absolutePath) - setContent { - App(dependencies) + App(setupDependencies()) } } + + private fun setupDependencies(): Dependencies { + val platformInfo = + object : PlatformInfo { + override val version = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})" + override val platform = Platform.Android + override val osVersion = Build.VERSION.SDK_INT.toString() + override val model = "${Build.MANUFACTURER} ${Build.MODEL}" + } + val bridge = AndroidOonimkallBridge() + val dependencies = + Dependencies( + platformInfo = platformInfo, + oonimkallBridge = bridge, + baseFileDir = filesDir.absolutePath, + ) + return dependencies + } } diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt index 86cd973c..1cf398e3 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt @@ -4,7 +4,9 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Modifier +import co.touchlab.kermit.Logger import org.jetbrains.compose.ui.tooling.preview.Preview import org.ooni.probe.di.Dependencies import org.ooni.probe.ui.Theme @@ -13,6 +15,10 @@ import org.ooni.probe.ui.main.MainScreen @Composable @Preview fun App(dependencies: Dependencies) { + LaunchedEffect(Unit) { + logAppStart(dependencies) + } + Theme { Surface( modifier = Modifier.fillMaxSize(), @@ -24,3 +30,16 @@ fun App(dependencies: Dependencies) { } } } + +private fun logAppStart(dependencies: Dependencies) { + with(dependencies.platformInfo) { + Logger.i( + """ + ---APP START--- + Platform: $platform ($osVersion)" + Version: $version + Model: $model + """.trimIndent(), + ) + } +} diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt index 8309f950..9ca7635d 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/di/Dependencies.kt @@ -3,9 +3,11 @@ package org.ooni.probe.di import kotlinx.serialization.json.Json import org.ooni.engine.Engine import org.ooni.engine.OonimkallBridge +import org.ooni.probe.shared.PlatformInfo import org.ooni.probe.ui.main.MainViewModel class Dependencies( + val platformInfo: PlatformInfo, private val oonimkallBridge: OonimkallBridge, private val baseFileDir: String, ) { diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/PlatformInfo.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/PlatformInfo.kt new file mode 100644 index 00000000..24b139be --- /dev/null +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/PlatformInfo.kt @@ -0,0 +1,13 @@ +package org.ooni.probe.shared + +interface PlatformInfo { + val version: String + val platform: Platform + val osVersion: String + val model: String +} + +enum class Platform { + Android, + Ios, +} diff --git a/composeApp/src/iosMain/kotlin/org/ooni/probe/MainViewController.kt b/composeApp/src/iosMain/kotlin/org/ooni/probe/MainViewController.kt index c41e982a..8d73fc2b 100644 --- a/composeApp/src/iosMain/kotlin/org/ooni/probe/MainViewController.kt +++ b/composeApp/src/iosMain/kotlin/org/ooni/probe/MainViewController.kt @@ -3,9 +3,34 @@ package org.ooni.probe import androidx.compose.ui.window.ComposeUIViewController import org.ooni.engine.OonimkallBridge import org.ooni.probe.di.Dependencies +import org.ooni.probe.shared.Platform +import org.ooni.probe.shared.PlatformInfo +import platform.Foundation.NSBundle import platform.Foundation.NSTemporaryDirectory +import platform.UIKit.UIDevice fun mainViewController(bridge: OonimkallBridge) = ComposeUIViewController { - App(Dependencies(bridge, NSTemporaryDirectory())) + App(setupDependencies(bridge)) } + +fun setupDependencies(bridge: OonimkallBridge): Dependencies { + return Dependencies( + platformInfo = + object : PlatformInfo { + override val version = + (NSBundle.mainBundle.infoDictionary?.get("CFBundleVersion") as? String).orEmpty() + + override val platform = Platform.Ios + + override val osVersion = + with(UIDevice.currentDevice) { + "$systemName $systemVersion" + } + + override val model = UIDevice.currentDevice.model + }, + oonimkallBridge = bridge, + baseFileDir = NSTemporaryDirectory(), + ) +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 34f548b2..ccb2eaea 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,13 +10,6 @@ compose = "1.6.8" compose-plugin = "1.6.11" kotlin = "2.0.0" -[libraries] -androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } -compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" } -compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" } -android-oonimkall = { module = "org.ooni:oonimkall", version = "2024.05.22-092559" } -kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.7.1" } - [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } androidLibrary = { id = "com.android.library", version.ref = "agp" } @@ -25,4 +18,17 @@ jetbrainsComposeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" } -ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "12.1.1" } \ No newline at end of file +ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "12.1.1" } + +[libraries] +androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } +compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" } +compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "compose" } +android-oonimkall = { module = "org.ooni:oonimkall", version = "2024.05.22-092559" } +kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.7.1" } +kermit = { module = "co.touchlab:kermit", version = "2.0.4" } + +[bundles] +tooling = [ + "kermit" +] diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj index 123f806b..1b90a014 100644 --- a/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/iosApp/iosApp.xcodeproj/project.pbxproj @@ -127,6 +127,7 @@ B92378962B6B1156000C7307 /* Frameworks */, 7555FF79242A565900829871 /* Resources */, 93E977732C4FE022009CCABC /* ShellScript */, + 8C6B45F03EB6D1828FCB533E /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -205,6 +206,23 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; + 8C6B45F03EB6D1828FCB533E /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Copy Pods Resources"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-iosApp/Pods-iosApp-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; 93E977732C4FE022009CCABC /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647;