Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark global navigation as @MainActor to avoid data-race safety issues #173

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# EditorConfig is awesome: https://editorconfig.org
root = true

[*]

indent_style = space
tab_width = 8
indent_size = 4

end_of_line = lf
insert_final_newline = true

max_line_length = 160
trim_trailing_whitespace = true
9 changes: 6 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ let package = Package(
.target(
name: "TelemetryDeck",
dependencies: ["TelemetryClient"],
resources: [.copy("PrivacyInfo.xcprivacy")]
resources: [.copy("PrivacyInfo.xcprivacy")],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
),
.target(
name: "TelemetryClient",
resources: [.copy("PrivacyInfo.xcprivacy")]
resources: [.copy("PrivacyInfo.xcprivacy")],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
),
.testTarget(
name: "TelemetryClientTests",
dependencies: ["TelemetryClient"]
dependencies: ["TelemetryClient"],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
)
]
)
1 change: 1 addition & 0 deletions Sources/TelemetryClient/Presets/NavigationStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation

/// This internal singleton keeps track of the last used navigation path so
/// that the ``TelemetryDeck.navigationPathChanged(to:customUserID:)`` function has a `from` source to work off of.
@MainActor
class NavigationStatus {
static let shared = NavigationStatus()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension TelemetryDeck {
/// - from: The navigation path at the beginning of the navigation event, identifying the view the user is leaving
/// - to: The navigation path at the end of the navigation event, identifying the view the user is arriving at
/// - customUserID: An optional string specifying a custom user identifier. If provided, it will override the default user identifier from the configuration. Default is `nil`.
@MainActor
public static func navigationPathChanged(from source: String, to destination: String, customUserID: String? = nil) {
NavigationStatus.shared.previousNavigationPath = destination

Expand Down Expand Up @@ -57,17 +58,20 @@ extension TelemetryDeck {
/// - Parameters:
/// - to: The navigation path representing the view the user is arriving at.
/// - customUserID: An optional string specifying a custom user identifier. If provided, it will override the default user identifier from the configuration. Default is `nil`.
@MainActor
public static func navigationPathChanged(to destination: String, customUserID: String? = nil) {
let source = NavigationStatus.shared.previousNavigationPath ?? ""

Self.navigationPathChanged(from: source, to: destination, customUserID: customUserID)
}

@MainActor
@available(*, unavailable, renamed: "navigationPathChanged(from:to:customUserID:)")
public static func navigate(from source: String, to destination: String, customUserID: String? = nil) {
self.navigationPathChanged(from: source, to: destination, customUserID: customUserID)
}

@MainActor
@available(*, unavailable, renamed: "navigationPathChanged(to:customUserID:)")
public static func navigate(to destination: String, customUserID: String? = nil) {
self.navigationPathChanged(to: destination, customUserID: customUserID)
Expand Down