From 5ac67654a46901e81f850dd8a7bfccf2ecd612d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sun, 1 Dec 2024 14:54:02 +0100 Subject: [PATCH 1/3] Add default accessibility parameters to send alongside each request --- README.md | 18 ++++++++++--- Sources/TelemetryDeck/Signals/Signal.swift | 31 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index eb77779..7119e9f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/Sources/TelemetryDeck/Signals/Signal.swift b/Sources/TelemetryDeck/Signals/Signal.swift index 5330840..ad24fb7 100644 --- a/Sources/TelemetryDeck/Signals/Signal.swift +++ b/Sources/TelemetryDeck/Signals/Signal.swift @@ -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 @@ -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 } From 026208ef44b834d8c94ab26068fa896d219240bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sun, 1 Dec 2024 15:55:28 +0100 Subject: [PATCH 2/3] Remove repetitive content size category prefix 'UICTContentSizeCategory' --- Sources/TelemetryDeck/Signals/Signal.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/TelemetryDeck/Signals/Signal.swift b/Sources/TelemetryDeck/Signals/Signal.swift index ad24fb7..6281d1a 100644 --- a/Sources/TelemetryDeck/Signals/Signal.swift +++ b/Sources/TelemetryDeck/Signals/Signal.swift @@ -131,7 +131,7 @@ extension DefaultSignalPayload { a11yParams["TelemetryDeck.Accessibility.shouldDifferentiateWithoutColor"] = "\(UIAccessibility.shouldDifferentiateWithoutColor)" } a11yParams["TelemetryDeck.Accessibility.preferredContentSizeCategory"] = UIApplication.shared.preferredContentSizeCategory.rawValue - a11yParams["TelemetryDeck.Accessibility.preferredContentSizeCategory"] = UIApplication.shared.preferredContentSizeCategory.rawValue + .replacingOccurrences(of: "UICTContentSizeCategory", with: "") // replaces output "UICTContentSizeCategoryL" with "L" a11yParams["TelemetryDeck.Accessibility.userInterfaceLayoutDirection"] = UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft" a11yParams["TelemetryDeck.Accessibility.isSwitchControlEnabled"] = "\(UIAccessibility.isSwitchControlRunning)" #elseif os(macOS) From 6e49fc627cea6ebf5dfd9604b85b5e73237c0ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sun, 1 Dec 2024 17:13:58 +0100 Subject: [PATCH 3/3] Move UI layout direction to user preference parameters --- README.md | 3 ++- Sources/TelemetryDeck/Signals/Signal.swift | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7119e9f..0daf9d3 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ TelemetryDeck will automatically send base parameters, such as: - TelemetryDeck.Accessibility.isVoiceOverEnabled - TelemetryDeck.Accessibility.preferredContentSizeCategory - TelemetryDeck.Accessibility.shouldDifferentiateWithoutColor -- TelemetryDeck.Accessibility.userInterfaceLayoutDirection + - TelemetryDeck.AppInfo.buildNumber - TelemetryDeck.AppInfo.version - TelemetryDeck.Device.architecture @@ -106,6 +106,7 @@ TelemetryDeck will automatically send base parameters, such as: - TelemetryDeck.SDK.version - TelemetryDeck.UserPreference.colorScheme - TelemetryDeck.UserPreference.language +- TelemetryDeck.UserPreference.layoutDirection - TelemetryDeck.UserPreference.region See our [Grand Renaming article](https://telemetrydeck.com/docs/articles/grand-rename/?source=github) for a full list. diff --git a/Sources/TelemetryDeck/Signals/Signal.swift b/Sources/TelemetryDeck/Signals/Signal.swift index 6281d1a..5a65ef4 100644 --- a/Sources/TelemetryDeck/Signals/Signal.swift +++ b/Sources/TelemetryDeck/Signals/Signal.swift @@ -94,9 +94,10 @@ public struct DefaultSignalPayload: Encodable { "TelemetryDeck.SDK.nameAndVersion": "SwiftSDK \(sdkVersion)", "TelemetryDeck.SDK.version": sdkVersion, + "TelemetryDeck.UserPreference.colorScheme": Self.colorScheme, "TelemetryDeck.UserPreference.language": Self.preferredLanguage, + "TelemetryDeck.UserPreference.layoutDirection": Self.layoutDirection, "TelemetryDeck.UserPreference.region": Self.region, - "TelemetryDeck.UserPreference.colorScheme": Self.colorScheme ] parameters.merge(self.accessibilityParameters, uniquingKeysWith: { $1 }) @@ -132,7 +133,6 @@ extension DefaultSignalPayload { } a11yParams["TelemetryDeck.Accessibility.preferredContentSizeCategory"] = UIApplication.shared.preferredContentSizeCategory.rawValue .replacingOccurrences(of: "UICTContentSizeCategory", with: "") // replaces output "UICTContentSizeCategoryL" with "L" - 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)" @@ -399,6 +399,18 @@ extension DefaultSignalPayload { #endif } + /// The user-preferred layout direction (left-to-right or right-to-left) based on the current language/region settings. + @MainActor + static var layoutDirection: String { + #if os(iOS) || os(tvOS) + return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft" + #elseif os(macOS) + return NSApp.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft" + #else + return "N/A" + #endif + } + /// The current devices screen resolution width in points. @MainActor static var screenResolutionWidth: String {