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

Add screen scale factor on iOS, macOS, and tvOS for proper pixels #213

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
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 @@ -340,6 +341,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 @@ -379,7 +381,7 @@ extension DefaultSignalPayload {
if let screen = NSScreen.main {
return "\(screen.frame.width)"
}
return "Unknown"
return "N/A"
#else
return "N/A"
#endif
Expand All @@ -396,9 +398,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