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

Added colorScheme to default signal payload #193

Merged
merged 2 commits into from
Nov 29, 2024
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ TelemetryDeck will automatically send base parameters, such as:
- TelemetryDeck.SDK.version
- TelemetryDeck.UserPreference.region
- TelemetryDeck.UserPreference.language
- TelemetryDeck.UserPreference.colorScheme

See our [Grand Renaming article](https://telemetrydeck.com/docs/articles/grand-rename/?source=github) for a full list.

Expand Down
30 changes: 30 additions & 0 deletions Sources/TelemetryDeck/Signals/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public struct DefaultSignalPayload: Encodable {

"TelemetryDeck.UserPreference.language": Self.preferredLanguage,
"TelemetryDeck.UserPreference.region": Self.region,
"TelemetryDeck.UserPreference.colorScheme": Self.colorScheme
]

if let extensionIdentifier = Self.extensionIdentifier {
Expand Down Expand Up @@ -338,6 +339,35 @@ extension DefaultSignalPayload {
return preferredLocaleIdentifier.components(separatedBy: .init(charactersIn: "-_"))[0]
}

/// The color scheme set by the user. Returns `N/A` on unsupported platforms
static var colorScheme: String {
#if os(iOS) || os(tvOS)
switch UIScreen.main.traitCollection.userInterfaceStyle {
case .dark:
return "Dark"
case .light:
return "Light"
default:
return "N/A"
}
#elseif os(macOS)
if #available(macOS 10.14, *) {
switch NSAppearance.current.name {
case .aqua:
return "Light"
case .darkAqua:
return "Dark"
default:
return "N/A"
}
} else {
return "Light"
}
#else
return "N/A"
Jeehut marked this conversation as resolved.
Show resolved Hide resolved
#endif
}

/// The current devices screen resolution width in points.
@MainActor
static var screenResolutionWidth: String {
Expand Down