File tree Expand file tree Collapse file tree 8 files changed +54
-11
lines changed
PowerSyncKotlin/src/appleMain/kotlin/com/powersync
androidMain/kotlin/com/powersync/sync
commonMain/kotlin/com/powersync/sync
jvmMain/kotlin/com/powersync/sync
nativeMain/kotlin/com/powersync/sync Expand file tree Collapse file tree 8 files changed +54
-11
lines changed Original file line number Diff line number Diff line change 3
3
package com.powersync
4
4
5
5
import com.powersync.sync.ConnectionMethod
6
+ import com.powersync.sync.SyncOptions
6
7
7
8
/* *
8
9
* Helper class designed to bridge SKIEE methods and allow them to throw
@@ -17,14 +18,23 @@ import com.powersync.sync.ConnectionMethod
17
18
public fun throwPowerSyncException (exception : PowerSyncException ): Unit = throw exception
18
19
19
20
/* *
20
- * Creates a [ConnectionMethod] from a simple boolean , because creating the actual instance with
21
+ * Creates a [ConnectionMethod] based on simple booleans , because creating the actual instance with
21
22
* the default constructor is not possible from Swift due to an optional argument with an internal
22
23
* default value.
23
24
*/
24
25
@OptIn(ExperimentalPowerSyncAPI ::class )
25
- public fun createConnectionMethod (webSocket : Boolean ): ConnectionMethod =
26
- if (webSocket) {
27
- ConnectionMethod .WebSocket ()
28
- } else {
29
- ConnectionMethod .Http
30
- }
26
+ public fun createSyncOptions (
27
+ newClient : Boolean ,
28
+ webSocket : Boolean ,
29
+ userAgent : String ,
30
+ ): SyncOptions =
31
+ SyncOptions (
32
+ newClientImplementation = newClient,
33
+ method =
34
+ if (webSocket) {
35
+ ConnectionMethod .WebSocket ()
36
+ } else {
37
+ ConnectionMethod .Http
38
+ },
39
+ userAgent = userAgent,
40
+ )
Original file line number Diff line number Diff line change
1
+ package com.powersync.sync
2
+
3
+ import android.os.Build
4
+
5
+ internal actual fun userAgent (): String = " PowerSync Kotlin SDK (Android ${Build .VERSION .SDK_INT } )"
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import kotlin.coroutines.CoroutineContext
42
42
*/
43
43
@OptIn(RSocketTransportApi ::class , ExperimentalPowerSyncAPI ::class )
44
44
internal fun HttpClient.rSocketSyncStream (
45
+ userAgent : String ,
45
46
options : ConnectionMethod .WebSocket ,
46
47
req : JsonObject ,
47
48
credentials : PowerSyncCredentials ,
@@ -90,7 +91,14 @@ internal fun HttpClient.rSocketSyncStream(
90
91
setupPayload {
91
92
buildPayload {
92
93
data(" {}" )
93
- metadata(JsonUtil .json.encodeToString(ConnectionSetupMetadata (token = " Bearer ${credentials.token} " )))
94
+ metadata(
95
+ JsonUtil .json.encodeToString(
96
+ ConnectionSetupMetadata (
97
+ token = " Bearer ${credentials.token} " ,
98
+ userAgent = userAgent,
99
+ ),
100
+ ),
101
+ )
94
102
}
95
103
}
96
104
@@ -119,7 +127,7 @@ internal fun HttpClient.rSocketSyncStream(
119
127
private class ConnectionSetupMetadata (
120
128
val token : String ,
121
129
@SerialName(" user_agent" )
122
- val userAgent : String = userAgent() ,
130
+ val userAgent : String ,
123
131
)
124
132
125
133
/* *
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ public class SyncOptions
21
21
public val newClientImplementation: Boolean = false ,
22
22
@property:ExperimentalPowerSyncAPI
23
23
public val method: ConnectionMethod = ConnectionMethod .Http ,
24
+ /* *
25
+ * The user agent to use for requests made to the PowerSync service.
26
+ */
27
+ public val userAgent: String = userAgent(),
24
28
) {
25
29
public companion object {
26
30
/* *
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ internal class SyncStream(
83
83
84
84
install(DefaultRequest ) {
85
85
headers {
86
- append(" User-Agent" , userAgent() )
86
+ append(" User-Agent" , options. userAgent)
87
87
}
88
88
}
89
89
}
@@ -255,6 +255,7 @@ internal class SyncStream(
255
255
256
256
emitAll(
257
257
httpClient.rSocketSyncStream(
258
+ userAgent = this @SyncStream.options.userAgent,
258
259
options = options,
259
260
req = req,
260
261
credentials = credentials,
Original file line number Diff line number Diff line change 1
1
package com.powersync.sync
2
2
3
- internal fun userAgent (): String = " PowerSync Kotlin SDK "
3
+ internal expect fun userAgent (): String
Original file line number Diff line number Diff line change
1
+ package com.powersync.sync
2
+
3
+ internal actual fun userAgent (): String {
4
+ val os = System .getProperty(" os.name" ) ? : " unknown"
5
+ val osVersion = System .getProperty(" os.version" ) ? : " "
6
+ val java = System .getProperty(" java.vendor.version" ) ? : System .getProperty(" java.runtime.version" ) ? : " unknown"
7
+
8
+ return " PowerSync Kotlin SDK (running Java $java on $os $osVersion )"
9
+ }
Original file line number Diff line number Diff line change
1
+ package com.powersync.sync
2
+
3
+ import kotlin.experimental.ExperimentalNativeApi
4
+
5
+ @OptIn(ExperimentalNativeApi ::class )
6
+ internal actual fun userAgent (): String = " PowerSync Kotlin SDK (running on ${Platform .cpuArchitecture.name} ${Platform .osFamily.name} )"
You can’t perform that action at this time.
0 commit comments