Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ooni/probe-multiplatform into feat/…
Browse files Browse the repository at this point in the history
…flavor-support
  • Loading branch information
aanorbel committed Jul 29, 2024
2 parents 0120815 + d020530 commit 31c1688
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 17 deletions.
13 changes: 8 additions & 5 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ val appConfig =
AppConfig(
appId = "org.dw.probe",
appName = "News Media Scan",
srcRoot = "src/ooniMain/kotlin",
resRoot = "src/ooniMain/resources",
srcRoot = "src/dwMain/kotlin",
resRoot = "src/dwMain/resources",
),
"ooni" to
AppConfig(
appId = "org.ooni.probe",
appName = "OONI Probe",
srcRoot = "src/dwMain/kotlin",
resRoot = "src/dwMain/resources",
srcRoot = "src/ooniMain/kotlin",
resRoot = "src/ooniMain/resources",
),
)

Expand Down Expand Up @@ -78,8 +78,8 @@ kotlin {
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.kotlin.serialization)
implementation(libs.bundles.tooling)

// add source directories and resources based on flavor
getByName("commonMain") {
kotlin.srcDir(config.srcRoot)
}
Expand Down Expand Up @@ -131,6 +131,9 @@ android {
isMinifyEnabled = false
}
}
buildFeatures {
buildConfig = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
26 changes: 22 additions & 4 deletions composeApp/src/androidMain/kotlin/org/ooni/probe/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
21 changes: 21 additions & 0 deletions composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package org.ooni.probe

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.AppTheme
Expand All @@ -12,13 +15,31 @@ import org.ooni.probe.ui.main.MainScreen
@Composable
@Preview
fun App(dependencies: Dependencies) {
LaunchedEffect(Unit) {
logAppStart(dependencies)
}

AppTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background,
) {
MainScreen(
dependencies.mainViewModel,
)
}
}
}

private fun logAppStart(dependencies: Dependencies) {
with(dependencies.platformInfo) {
Logger.i(
"""
---APP START---
Platform: $platform ($osVersion)"
Version: $version
Model: $model
""".trimIndent(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
20 changes: 13 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ compose = "1.6.8"
compose-plugin = "1.7.0-alpha02"
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" }
Expand All @@ -26,3 +19,16 @@ kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref =
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" }

[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"
]
18 changes: 18 additions & 0 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
B92378962B6B1156000C7307 /* Frameworks */,
7555FF79242A565900829871 /* Resources */,
93E977732C4FE022009CCABC /* ShellScript */,
8C6B45F03EB6D1828FCB533E /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 31c1688

Please sign in to comment.