diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt index 9b64f44..c7a3d8f 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/MainActivity.kt @@ -6,15 +6,33 @@ import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview +import androidx.lifecycle.lifecycleScope +import kotlinx.coroutines.launch +import java.io.File class MainActivity : ComponentActivity() { + private val nostr = Nostr() + override fun onCreate(savedInstanceState: Bundle?) { enableEdgeToEdge() super.onCreate(savedInstanceState) + // Get database directory + val dbDir = File(filesDir, "nostr") + dbDir.mkdirs() + + // Initialize nostr client + nostr.init(dbDir.absolutePath) + + // Connect to bootstrap relays + lifecycleScope.launch { + nostr.connect() + } + setContent { App() } + } } diff --git a/gradle.properties b/gradle.properties index 6f8e6ea..1f172e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,14 @@ org.gradle.caching=true #Android android.nonTransitiveRClass=true -android.useAndroidX=true \ No newline at end of file +android.useAndroidX=true +android.defaults.buildfeatures.resvalues=true +android.sdk.defaultTargetSdkToCompileSdkIfUnset=false +android.enableAppCompileTimeRClass=false +android.usesSdkInManifest.disallowed=false +android.uniquePackageNames=false +android.dependency.useConstraints=true +android.r8.strictFullModeForKeepRules=false +android.r8.optimizedResourceShrinking=false +android.builtInKotlin=false +android.newDsl=false \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1fc7948..76c4c43 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -agp = "8.13.2" +agp = "9.2.0" android-compileSdk = "36" android-minSdk = "24" android-targetSdk = "36" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d4081da..c61a118 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 34b4167..eb41203 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -24,7 +24,7 @@ kotlin { sourceSets { commonMain.dependencies { - // put your Multiplatform dependencies here + implementation("org.rust-nostr:nostr-sdk-kmp:0.44.3") } commonTest.dependencies { implementation(libs.kotlin.test) diff --git a/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt new file mode 100644 index 0000000..360aa97 --- /dev/null +++ b/shared/src/commonMain/kotlin/su/reya/coop/Nostr.kt @@ -0,0 +1,28 @@ +package su.reya.coop + +import rust.nostr.sdk.Client +import rust.nostr.sdk.ClientBuilder +import rust.nostr.sdk.ClientOptions +import rust.nostr.sdk.NostrDatabase +import rust.nostr.sdk.NostrGossip +import rust.nostr.sdk.RelayUrl + +class Nostr { + var client: Client? = null + private set + + fun init(dbPath: String) { + val lmdb = NostrDatabase.lmdb(dbPath) + val gossip = NostrGossip.inMemory() + val opts = ClientOptions().automaticAuthentication(false) + + client = ClientBuilder().database(lmdb).gossip(gossip).opts(opts).build() + } + + suspend fun connect() { + this.client?.addRelay(RelayUrl.parse("wss://relay.damus.io")) + this.client?.addRelay(RelayUrl.parse("wss://relay.primal.net")) + this.client?.addRelay(RelayUrl.parse("wss://user.kindpag.es")) + this.client?.connect() + } +}