Skip to content

Commit

Permalink
Merge pull request #193 from FPST-08/main
Browse files Browse the repository at this point in the history
Added colorScheme to default signal payload
  • Loading branch information
Jeehut authored Nov 29, 2024
2 parents 1d9ac49 + 1e94211 commit 85311a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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"
#endif
}

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

0 comments on commit 85311a7

Please sign in to comment.