Skip to content

Commit 75257c1

Browse files
fix: UserAgent actor isolation (#110)
1 parent 38d21c5 commit 75257c1

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.11.0 (unreleased)
44

55
* Add support for [sync streams](https://docs.powersync.com/sync/streams/overview).
6+
* Fixed MainActor isolation warning for UserAgent function.
67

78
## 1.10.0
89

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
import Foundation
21

2+
import Foundation
33
#if os(iOS) || os(tvOS)
44
import UIKit
55
#endif
66

7-
func userAgent() -> String {
8-
#if os(macOS)
7+
func userAgent() async -> String {
8+
#if os(macOS)
99
let osName = "macOS"
10-
let version = ProcessInfo.processInfo.operatingSystemVersion
11-
let osVersion = "\(version.majorVersion).\(version.minorVersion)"
12-
#elseif os(watchOS)
10+
#elseif os(watchOS)
1311
let osName = "watchOS"
14-
let version = ProcessInfo.processInfo.operatingSystemVersion
15-
let osVersion = "\(version.majorVersion).\(version.minorVersion)"
16-
#elseif os(iOS)
12+
#elseif os(iOS)
1713
let osName = "iOS"
18-
let osVersion = UIDevice.current.systemVersion
19-
#elseif os(tvOS)
14+
#elseif os(tvOS)
2015
let osName = "tvOS"
21-
let osVersion = UIDevice.current.systemVersion
22-
#else
16+
#else
2317
let osName = "unknown"
24-
let version = ProcessInfo.processInfo.operatingSystemVersion
25-
let osVersion = "\(version.majorVersion).\(version.minorVersion)"
26-
#endif
27-
18+
#endif
19+
let osVersion = await getOSVersion()
2820
return "powersync-swift/\(libraryVersion) \(osName)/\(osVersion)"
2921
}
22+
23+
// Returns the OS version string for the current platform
24+
@MainActor func getOSVersion() async -> String {
25+
#if os(iOS) || os(tvOS)
26+
// UIDevice must be accessed on the main actor
27+
return UIDevice.current.systemVersion
28+
#else
29+
let version = ProcessInfo.processInfo.operatingSystemVersion
30+
return "\(version.majorVersion).\(version.minorVersion)"
31+
#endif
32+
}

0 commit comments

Comments
 (0)