Skip to content

Commit bd1199b

Browse files
authored
Updating user agent formatting (#95)
* Updating user agent formatting. * Added watchOS tracking. * Added `CurrentVersion.swift` that tracks a libraryVersion variable. * Sourcing os version for watchOS/tvOs from UIDevice. Dropping operatingSystemVersionString which is localised. * Moved watchOS to AppKit. * Added changelog entry.
1 parent 85eae34 commit bd1199b

5 files changed

Lines changed: 35 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.9.0 (unreleased)
44

5+
* Fixed user agent strings not following expected format.
56
* Added Alpha `PowerSyncGRDB` product which supports sharing GRDB `DatabasePool`s with PowerSync and application logic.
67
* Add `appMetadata` parameter to `PowerSyncDatabase.connect()` (via `ConnectOptions`) to include application metadata in sync requests. This metadata is merged into sync requests and displayed in PowerSync service logs.
78

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// The current version of the PowerSync Swift SDK. This should be updated to the latest version in `CHANGELOG.md` when a new version is released.
2+
let libraryVersion = "1.9.0"
3+

Sources/PowerSync/Kotlin/KotlinPowerSyncDatabaseImpl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class KotlinPowerSyncDatabaseImpl: PowerSyncDatabaseProtocol,
6060
params: resolvedOptions.params.mapValues { $0.toKotlinMap() },
6161
options: createSyncOptions(
6262
newClient: resolvedOptions.newClientImplementation,
63-
userAgent: "PowerSync Swift SDK",
63+
userAgent: userAgent(),
6464
loggingConfig: resolvedOptions.clientConfiguration?.requestLogger?.toKotlinConfig()
6565
),
6666
appMetadata: resolvedOptions.appMetadata
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
3+
#if os(iOS) || os(tvOS)
4+
import UIKit
5+
#endif
6+
7+
func userAgent() -> String {
8+
#if os(macOS)
9+
let osName = "macOS"
10+
let version = ProcessInfo.processInfo.operatingSystemVersion
11+
let osVersion = "\(version.majorVersion).\(version.minorVersion)"
12+
#elseif os(watchOS)
13+
let osName = "watchOS"
14+
let version = ProcessInfo.processInfo.operatingSystemVersion
15+
let osVersion = "\(version.majorVersion).\(version.minorVersion)"
16+
#elseif os(iOS)
17+
let osName = "iOS"
18+
let osVersion = UIDevice.current.systemVersion
19+
#elseif os(tvOS)
20+
let osName = "tvOS"
21+
let osVersion = UIDevice.current.systemVersion
22+
#else
23+
let osName = "unknown"
24+
let version = ProcessInfo.processInfo.operatingSystemVersion
25+
let osVersion = "\(version.majorVersion).\(version.minorVersion)"
26+
#endif
27+
28+
return "powersync-swift/\(libraryVersion) \(osName)/\(osVersion)"
29+
}

docs/Release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Confirm every PR you want in the release has been merged into `main`.
66
* Update `CHANGELOG.md` with the changes.
7+
+ Update `libraryVersion` variable in `Sources/PowerSync/CurrentVersion.swift` with the latest version in `CHANGELOG.md` (if a new version is being specified).
78
* In GitHub actions on GitHub manually run the `Release PowerSync` action. You will be required to update the version and add release notes.
89
The version string should have the form `1.0.0`, there should not be a `v` prefix on the tag name.
910
* If the release notes are complicated and don't fit on a single line it is easier to rather update those after the release is completed by updating the release notes in the new release.

0 commit comments

Comments
 (0)