From 4f3f8f0c00c1d9a82ef76b564d642bf20a2cd7fe Mon Sep 17 00:00:00 2001 From: Christiaan Landman Date: Tue, 2 Dec 2025 09:39:57 +0200 Subject: [PATCH] Updating user agent formatting. --- .../Kotlin/KotlinPowerSyncDatabaseImpl.swift | 2 +- Sources/PowerSync/Kotlin/sync/UserAgent.swift | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 Sources/PowerSync/Kotlin/sync/UserAgent.swift diff --git a/Sources/PowerSync/Kotlin/KotlinPowerSyncDatabaseImpl.swift b/Sources/PowerSync/Kotlin/KotlinPowerSyncDatabaseImpl.swift index aa81d1d..5097007 100644 --- a/Sources/PowerSync/Kotlin/KotlinPowerSyncDatabaseImpl.swift +++ b/Sources/PowerSync/Kotlin/KotlinPowerSyncDatabaseImpl.swift @@ -62,7 +62,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol, params: resolvedOptions.params.mapValues { $0.toKotlinMap() }, options: createSyncOptions( newClient: resolvedOptions.newClientImplementation, - userAgent: "PowerSync Swift SDK", + userAgent: userAgent(), loggingConfig: resolvedOptions.clientConfiguration?.requestLogger?.toKotlinConfig() ) ) diff --git a/Sources/PowerSync/Kotlin/sync/UserAgent.swift b/Sources/PowerSync/Kotlin/sync/UserAgent.swift new file mode 100644 index 0000000..f56792b --- /dev/null +++ b/Sources/PowerSync/Kotlin/sync/UserAgent.swift @@ -0,0 +1,25 @@ +import Foundation + +#if os(iOS) +import UIKit +#elseif os(macOS) +import AppKit +#endif + +func userAgent() -> String { + let libraryVersion = "1.0.0" // TODO: Replace with actual library version + + #if os(iOS) + let osName = "iOS" + let osVersion = UIDevice.current.systemVersion + #elseif os(macOS) + let osName = "macOS" + let version = ProcessInfo.processInfo.operatingSystemVersion + let osVersion = "\(version.majorVersion).\(version.minorVersion)" + #else + let osName = "unknown" + let osVersion = ProcessInfo.processInfo.operatingSystemVersionString + #endif + + return "powersync-swift/\(libraryVersion) \(osName)/\(osVersion)" +} \ No newline at end of file