Skip to content

Commit

Permalink
Merge pull request #213 from TelemetryDeck/feature/scale-factor
Browse files Browse the repository at this point in the history
Add screen scale factor on iOS, macOS, and tvOS for proper pixels
  • Loading branch information
Jeehut authored Dec 2, 2024
2 parents e1818e7 + c66caa5 commit f6630c6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Sources/TelemetryDeck/Signals/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public struct DefaultSignalPayload: Encodable {
"TelemetryDeck.Device.platform": Self.platform,
"TelemetryDeck.Device.screenResolutionHeight": Self.screenResolutionHeight,
"TelemetryDeck.Device.screenResolutionWidth": Self.screenResolutionWidth,
"TelemetryDeck.Device.screenScaleFactor": Self.screenScaleFactor,
"TelemetryDeck.Device.systemMajorMinorVersion": Self.majorMinorSystemVersion,
"TelemetryDeck.Device.systemMajorVersion": Self.majorSystemVersion,
"TelemetryDeck.Device.systemVersion": Self.systemVersion,
Expand Down Expand Up @@ -371,6 +372,7 @@ extension DefaultSignalPayload {
}

/// The color scheme set by the user. Returns `N/A` on unsupported platforms
@MainActor
static var colorScheme: String {
#if os(iOS) || os(tvOS)
switch UIScreen.main.traitCollection.userInterfaceStyle {
Expand Down Expand Up @@ -422,7 +424,7 @@ extension DefaultSignalPayload {
if let screen = NSScreen.main {
return "\(screen.frame.width)"
}
return "Unknown"
return "N/A"
#else
return "N/A"
#endif
Expand All @@ -439,9 +441,23 @@ extension DefaultSignalPayload {
if let screen = NSScreen.main {
return "\(screen.frame.height)"
}
return "Unknown"
#else
return "N/A"
#else
return "N/A"
#endif
}

@MainActor
static var screenScaleFactor: String {
#if os(iOS) || os(tvOS)
return "\(UIScreen.main.scale)"
#elseif os(macOS)
if let screen = NSScreen.main {
return "\(screen.backingScaleFactor)"
}
return "N/A"
#else
return "N/A"
#endif
}

Expand Down

0 comments on commit f6630c6

Please sign in to comment.