Skip to content

Commit 6a4bc1d

Browse files
authored
Merge pull request #270 from synonymdev/feat/vss-rust-client-ffi
Integrate VSS rust client bindings for backups
2 parents 67934d9 + 6b32514 commit 6a4bc1d

File tree

23 files changed

+1830
-984
lines changed

23 files changed

+1830
-984
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Bitkit Android (Native)
22

33
> [!CAUTION]
4-
> ⚠️This **NOT** the repository of the Bitkit app from the app stores!<br>
4+
> ⚠️This is **NOT** the repository of the Bitkit app from the app stores!<br>
55
> ⚠️Work-in-progress<br>
66
> The Bitkit app repository is here: **[github.com/synonymdev/bitkit](https://github.com/synonymdev/bitkit)**
77

app/build.gradle.kts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ plugins {
1010
alias(libs.plugins.ksp)
1111
alias(libs.plugins.hilt.android)
1212
alias(libs.plugins.google.services)
13-
alias(libs.plugins.protobuf)
1413
alias(libs.plugins.room)
1514
alias(libs.plugins.detekt)
1615
}
@@ -157,21 +156,6 @@ android {
157156
}
158157
}
159158

160-
protobuf {
161-
protoc {
162-
artifact = "com.google.protobuf:protoc:3.21.12"
163-
}
164-
generateProtoTasks {
165-
all().forEach { task ->
166-
task.builtins {
167-
create("java") {
168-
option("lite")
169-
}
170-
}
171-
}
172-
}
173-
}
174-
175159
composeCompiler {
176160
featureFlags = setOf(
177161
ComposeFeatureFlag.StrongSkipping.disabled(),
@@ -266,8 +250,6 @@ dependencies {
266250
// Logging
267251
runtimeOnly(libs.slf4j.simple)
268252
implementation(libs.slf4j.api)
269-
// Protobuf
270-
implementation(libs.protobuf.javalite)
271253
// Room - DB
272254
implementation(libs.room.ktx)
273255
implementation(libs.room.runtime)

app/detekt-baseline.xml

Lines changed: 310 additions & 45 deletions
Large diffs are not rendered by default.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package to.bitkit.data.backup
2+
3+
import kotlinx.coroutines.CompletableDeferred
4+
import kotlinx.coroutines.CoroutineDispatcher
5+
import kotlinx.coroutines.withContext
6+
import kotlinx.coroutines.withTimeout
7+
import to.bitkit.di.BgDispatcher
8+
import to.bitkit.env.Env
9+
import to.bitkit.utils.Logger
10+
import uniffi.vss_rust_client_ffi.VssItem
11+
import uniffi.vss_rust_client_ffi.vssGet
12+
import uniffi.vss_rust_client_ffi.vssNewClient
13+
import uniffi.vss_rust_client_ffi.vssStore
14+
import javax.inject.Inject
15+
import javax.inject.Singleton
16+
import kotlin.time.Duration.Companion.seconds
17+
18+
@Singleton
19+
class VssBackupClient @Inject constructor(
20+
@BgDispatcher private val bgDispatcher: CoroutineDispatcher,
21+
private val vssStoreIdProvider: VssStoreIdProvider,
22+
) {
23+
private val isSetup = CompletableDeferred<Unit>()
24+
25+
suspend fun setup() = withContext(bgDispatcher) {
26+
try {
27+
withTimeout(30.seconds) {
28+
Logger.debug("VSS client setting up…", context = TAG)
29+
vssNewClient(
30+
baseUrl = Env.vssServerUrl,
31+
storeId = vssStoreIdProvider.getVssStoreId(),
32+
)
33+
isSetup.complete(Unit)
34+
Logger.info("VSS client setup ok", context = TAG)
35+
}
36+
} catch (e: Throwable) {
37+
isSetup.completeExceptionally(e)
38+
Logger.error("VSS client setup error", e = e, context = TAG)
39+
}
40+
}
41+
42+
suspend fun putObject(
43+
key: String,
44+
data: ByteArray,
45+
): Result<VssItem> = withContext(bgDispatcher) {
46+
isSetup.await()
47+
Logger.debug("VSS 'putObject' call for '$key'", context = TAG)
48+
runCatching {
49+
vssStore(
50+
key = key,
51+
value = data,
52+
)
53+
}.onSuccess {
54+
Logger.debug("VSS 'putObject' success for '$key' at version: ${it.version}", context = TAG)
55+
}.onFailure { e ->
56+
Logger.error("VSS 'putObject' error for '$key'", e = e, context = TAG)
57+
}
58+
}
59+
60+
suspend fun getObject(key: String): Result<VssItem?> = withContext(bgDispatcher) {
61+
isSetup.await()
62+
Logger.debug("VSS 'getObject' call for '$key'", context = TAG)
63+
runCatching {
64+
vssGet(
65+
key = key,
66+
)
67+
}.onSuccess {
68+
if (it == null) {
69+
Logger.warn("VSS 'getObject' success null for '$key'", context = TAG)
70+
} else {
71+
Logger.debug("VSS 'getObject' success for '$key'", context = TAG)
72+
}
73+
}.onFailure { e ->
74+
Logger.error("VSS 'getObject' error for '$key'", e = e, context = TAG)
75+
}
76+
}
77+
78+
companion object Companion {
79+
private const val TAG = "VssBackupClient"
80+
}
81+
}

app/src/main/java/to/bitkit/data/backup/VssBackupsClient.kt

Lines changed: 0 additions & 267 deletions
This file was deleted.

0 commit comments

Comments
 (0)