Skip to content

Commit

Permalink
Add default accessibility parameters to send alongside each request
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Dec 1, 2024
1 parent 85311a7 commit 5ac6765
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,27 @@ TelemetryDeck.signal("Database.updated", parameters: ["numberOfDatabaseEntries":

TelemetryDeck will automatically send base parameters, such as:

- TelemetryDeck.Accessibility.isBoldTextEnabled
- TelemetryDeck.Accessibility.isDarkerSystemColorsEnabled
- TelemetryDeck.Accessibility.isInvertColorsEnabled
- TelemetryDeck.Accessibility.isReduceMotionEnabled
- TelemetryDeck.Accessibility.isReduceTransparencyEnabled
- TelemetryDeck.Accessibility.isSwitchControlEnabled
- TelemetryDeck.Accessibility.isVoiceOverEnabled
- TelemetryDeck.Accessibility.preferredContentSizeCategory
- TelemetryDeck.Accessibility.shouldDifferentiateWithoutColor
- TelemetryDeck.Accessibility.userInterfaceLayoutDirection
- TelemetryDeck.AppInfo.buildNumber
- TelemetryDeck.AppInfo.version
- TelemetryDeck.Device.architecture
- TelemetryDeck.Device.modelName
- TelemetryDeck.Device.operatingSystem
- TelemetryDeck.Device.platform
- TelemetryDeck.Device.orientation
- TelemetryDeck.Device.platform
- TelemetryDeck.Device.screenResolutionHeight
- TelemetryDeck.Device.screenResolutionWidth
- TelemetryDeck.Device.systemMajorVersion
- TelemetryDeck.Device.systemMajorMinorVersion
- TelemetryDeck.Device.systemMajorVersion
- TelemetryDeck.Device.systemVersion
- TelemetryDeck.Device.timeZone
- TelemetryDeck.RunContext.isAppStore
Expand All @@ -94,9 +104,9 @@ TelemetryDeck will automatically send base parameters, such as:
- TelemetryDeck.RunContext.language
- TelemetryDeck.RunContext.targetEnvironment
- TelemetryDeck.SDK.version
- TelemetryDeck.UserPreference.region
- TelemetryDeck.UserPreference.language
- TelemetryDeck.UserPreference.colorScheme
- TelemetryDeck.UserPreference.language
- TelemetryDeck.UserPreference.region

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

Expand Down
31 changes: 31 additions & 0 deletions Sources/TelemetryDeck/Signals/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public struct DefaultSignalPayload: Encodable {
"TelemetryDeck.UserPreference.colorScheme": Self.colorScheme
]

parameters.merge(self.accessibilityParameters, uniquingKeysWith: { $1 })

if let extensionIdentifier = Self.extensionIdentifier {
// deprecated name
parameters["extensionIdentifier"] = extensionIdentifier
Expand All @@ -114,6 +116,35 @@ public struct DefaultSignalPayload: Encodable {
// MARK: - Helpers

extension DefaultSignalPayload {
@MainActor
static var accessibilityParameters: [String: String] {
var a11yParams: [String: String] = [:]

#if os(iOS) || os(tvOS)
a11yParams["TelemetryDeck.Accessibility.isVoiceOverEnabled"] = "\(UIAccessibility.isVoiceOverRunning)"
a11yParams["TelemetryDeck.Accessibility.isReduceMotionEnabled"] = "\(UIAccessibility.isReduceMotionEnabled)"
a11yParams["TelemetryDeck.Accessibility.isBoldTextEnabled"] = "\(UIAccessibility.isBoldTextEnabled)"
a11yParams["TelemetryDeck.Accessibility.isInvertColorsEnabled"] = "\(UIAccessibility.isInvertColorsEnabled)"
a11yParams["TelemetryDeck.Accessibility.isDarkerSystemColorsEnabled"] = "\(UIAccessibility.isDarkerSystemColorsEnabled)"
a11yParams["TelemetryDeck.Accessibility.isReduceTransparencyEnabled"] = "\(UIAccessibility.isReduceTransparencyEnabled)"
if #available(iOS 13.0, *) {
a11yParams["TelemetryDeck.Accessibility.shouldDifferentiateWithoutColor"] = "\(UIAccessibility.shouldDifferentiateWithoutColor)"
}
a11yParams["TelemetryDeck.Accessibility.preferredContentSizeCategory"] = UIApplication.shared.preferredContentSizeCategory.rawValue
a11yParams["TelemetryDeck.Accessibility.preferredContentSizeCategory"] = UIApplication.shared.preferredContentSizeCategory.rawValue
a11yParams["TelemetryDeck.Accessibility.userInterfaceLayoutDirection"] = UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft"
a11yParams["TelemetryDeck.Accessibility.isSwitchControlEnabled"] = "\(UIAccessibility.isSwitchControlRunning)"
#elseif os(macOS)
a11yParams["TelemetryDeck.Accessibility.isVoiceOverEnabled"] = "\(NSWorkspace.shared.isVoiceOverEnabled)"
if let systemPrefs = UserDefaults.standard.persistentDomain(forName: "com.apple.universalaccess") {
a11yParams["TelemetryDeck.Accessibility.isReduceMotionEnabled"] = "\(systemPrefs["reduceMotion"] as? Bool ?? false)"
a11yParams["TelemetryDeck.Accessibility.isInvertColorsEnabled"] = "\(systemPrefs["InvertColors"] as? Bool ?? false)"
}
#endif

return a11yParams
}

static var isSimulatorOrTestFlight: Bool {
isSimulator || isTestFlight
}
Expand Down

0 comments on commit 5ac6765

Please sign in to comment.