Skip to content

Commit

Permalink
DeviceSizeHelper and DeviceInfoHandler: refactor and add helpful log …
Browse files Browse the repository at this point in the history
…message
  • Loading branch information
bartekpacia committed Sep 9, 2024
1 parent ea5e718 commit 55a2ce8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ struct DeviceInfoHandler: HTTPHandler {

func handleRequest(_ request: HTTPRequest) async throws -> HTTPResponse {
do {
let springboardBundleId = "com.apple.springboard"
let springboardApp = XCUIApplication(bundleIdentifier: springboardBundleId)
let screenSize = springboardApp.frame.size
let (width, height, orientation) = try ScreenSizeHelper.actualScreenSize()
logger.info("Device orientation is \(String(orientation.rawValue))")

let (width, height) = try ScreenSizeHelper.actualScreenSize()
let deviceInfo = DeviceInfoResponse(
widthPoints: Int(width),
heightPoints: Int(height),
Expand All @@ -31,12 +29,4 @@ struct DeviceInfoHandler: HTTPHandler {
return AppError(message: "Getting device info call failed. Error \(error.localizedDescription)").httpResponse
}
}

private func handleError(message: String) -> Data {
logger.error("Failed - \(message)")
let jsonString = """
{ "errorMessage" : \(message) }
"""
return Data(jsonString.utf8)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct ScreenSizeHelper {
}

/// Takes device orientation into account.
static func actualScreenSize() throws -> (Float, Float) {
static func actualScreenSize() throws -> (Float, Float, UIDeviceOrientation) {
let orientation = actualOrientation()

let (width, height) = physicalScreenSize()
Expand All @@ -31,7 +31,7 @@ struct ScreenSizeHelper {
@unknown default: throw AppError(message: "Unsupported orientation: \(orientation)")
}

return (actualWidth, actualHeight)
return (actualWidth, actualHeight, orientation)
}

static func orientationAwarePoint(width: Float, height: Float, point: CGPoint) -> CGPoint {
Expand Down

0 comments on commit 55a2ce8

Please sign in to comment.