Skip to content

Commit

Permalink
Fix building for visionOS. (#390)
Browse files Browse the repository at this point in the history
* Fix compile errors on visionOS.

# Conflicts:
#	Source/Device.generated.swift
#	Source/Device.swift.gyb

* Remove references to xrOS that are no longer applicable.

* Add TODO comments in code about visionOS proper implementation.

* Update changelog.

---------

Co-authored-by: Chris Vasselli <[email protected]>
  • Loading branch information
Zandor300 and chrisvasselli authored Feb 6, 2024
1 parent 6c01329 commit fe41d18
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ pod 'DeviceKit', '~> 5.2'
### Bugfixes

- Fix building SwiftUI previews on macOS properly. ([#389](https://github.com/devicekit/DeviceKit/pull/389))
- Fix building for visionOS. ([#390](https://github.com/devicekit/DeviceKit/pull/390))

### Contributors

Thanks to all the contributers of this release!
- [honghaoz](https://github.com/honghaoz)
- [chrisvasselli](https://github.com/chrisvasselli)

## Version 5.2.1

Expand Down
8 changes: 6 additions & 2 deletions DeviceKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,12 @@
RUN_CLANG_STATIC_ANALYZER = YES;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator watchos watchsimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
TVOS_DEPLOYMENT_TARGET = 11.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -448,8 +450,10 @@
RUN_CLANG_STATIC_ANALYZER = YES;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator watchos watchsimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TARGETED_DEVICE_FAMILY = "1,2,3,4,7";
TVOS_DEPLOYMENT_TARGET = 11.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
31 changes: 24 additions & 7 deletions Source/Device.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ public enum Device {
case "i386", "x86_64", "arm64": return simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "watchOS"))
default: return unknown(identifier)
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return unknown(identifier)
#else
return unknown(identifier)
#endif
Expand Down Expand Up @@ -879,7 +882,7 @@ public enum Device {
case .simulator(let model): return model.screenRatio
case .unknown: return (width: -1, height: -1)
}
#elseif os(tvOS)
#elseif os(tvOS) || os(visionOS)
return (width: -1, height: -1)
#else
return (width: -1, height: -1)
Expand Down Expand Up @@ -986,16 +989,12 @@ public enum Device {

public var isZoomed: Bool? {
guard isCurrent else { return nil }
#if os(xrOS)
return nil
#else
if Int(UIScreen.main.scale.rounded()) == 3 {
// Plus-sized
return UIScreen.main.nativeScale > 2.7 && UIScreen.main.nativeScale < 3
} else {
return UIScreen.main.nativeScale > UIScreen.main.scale
}
#endif
}

/// All Touch ID Capable Devices
Expand Down Expand Up @@ -1162,6 +1161,9 @@ public enum Device {
return allTVs
#elseif os(watchOS)
return allWatches
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return []
#else
return []
#endif
Expand Down Expand Up @@ -1401,6 +1403,9 @@ public enum Device {
}
#elseif os(tvOS)
return nil
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return nil
#else
return nil
#endif
Expand All @@ -1421,7 +1426,7 @@ public enum Device {

/// The brightness level of the screen.
public var screenBrightness: Int {
#if os(iOS) && !os(xrOS)
#if os(iOS)
return Int(UIScreen.main.brightness * 100)
#else
return 100
Expand Down Expand Up @@ -1554,6 +1559,9 @@ extension Device: CustomStringConvertible {
case .simulator(let model): return "Simulator (\(model.description))"
case .unknown(let identifier): return identifier
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return "Apple Vision Pro"
#else
switch self {
case .simulator(let model): return "Simulator (\(model.description))"
Expand Down Expand Up @@ -1687,6 +1695,9 @@ extension Device: CustomStringConvertible {
case .simulator(let model): return "Simulator (\(model.safeDescription))"
case .unknown(let identifier): return identifier
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return "Apple Vision Pro"
#else
switch self {
case .simulator(let model): return "Simulator (\(model.safeDescription))"
Expand Down Expand Up @@ -1842,7 +1853,7 @@ extension Device.BatteryState: Comparable {
}
#endif

#if os(iOS) && !os(xrOS)
#if os(iOS)
extension Device {
// MARK: Orientation
/**
Expand Down Expand Up @@ -2326,6 +2337,9 @@ extension Device {
case .simulator(let model): return model.cpu
case .unknown: return .unknown
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return .unknown
#else
return .unknown
#endif
Expand Down Expand Up @@ -2377,6 +2391,9 @@ extension Device.CPU: CustomStringConvertible {
case .s9: return "S9"
case .unknown: return "unknown"
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return "unknown"
#else
return "unknown"
#endif
Expand Down
31 changes: 24 additions & 7 deletions Source/Device.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ public enum Device {
case "i386", "x86_64", "arm64": return simulator(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "watchOS"))
default: return unknown(identifier)
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return unknown(identifier)
#else
return unknown(identifier)
#endif
Expand Down Expand Up @@ -482,7 +485,7 @@ public enum Device {
case .simulator(let model): return model.screenRatio
case .unknown: return (width: -1, height: -1)
}
#elseif os(tvOS)
#elseif os(tvOS) || os(visionOS)
return (width: -1, height: -1)
#else
return (width: -1, height: -1)
Expand Down Expand Up @@ -589,16 +592,12 @@ public enum Device {

public var isZoomed: Bool? {
guard isCurrent else { return nil }
#if os(xrOS)
return nil
#else
if Int(UIScreen.main.scale.rounded()) == 3 {
// Plus-sized
return UIScreen.main.nativeScale > 2.7 && UIScreen.main.nativeScale < 3
} else {
return UIScreen.main.nativeScale > UIScreen.main.scale
}
#endif
}

/// All Touch ID Capable Devices
Expand Down Expand Up @@ -765,6 +764,9 @@ public enum Device {
return allTVs
#elseif os(watchOS)
return allWatches
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return []
#else
return []
#endif
Expand Down Expand Up @@ -909,6 +911,9 @@ public enum Device {
}
#elseif os(tvOS)
return nil
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return nil
#else
return nil
#endif
Expand All @@ -929,7 +934,7 @@ public enum Device {

/// The brightness level of the screen.
public var screenBrightness: Int {
#if os(iOS) && !os(xrOS)
#if os(iOS)
return Int(UIScreen.main.brightness * 100)
#else
return 100
Expand Down Expand Up @@ -966,6 +971,9 @@ extension Device: CustomStringConvertible {
case .simulator(let model): return "Simulator (\(model.description))"
case .unknown(let identifier): return identifier
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return "Apple Vision Pro"
#else
switch self {
case .simulator(let model): return "Simulator (\(model.description))"
Expand Down Expand Up @@ -1003,6 +1011,9 @@ extension Device: CustomStringConvertible {
case .simulator(let model): return "Simulator (\(model.safeDescription))"
case .unknown(let identifier): return identifier
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return "Apple Vision Pro"
#else
switch self {
case .simulator(let model): return "Simulator (\(model.safeDescription))"
Expand Down Expand Up @@ -1158,7 +1169,7 @@ extension Device.BatteryState: Comparable {
}
#endif

#if os(iOS) && !os(xrOS)
#if os(iOS)
extension Device {
// MARK: Orientation
/**
Expand Down Expand Up @@ -1496,6 +1507,9 @@ extension Device {
case .simulator(let model): return model.cpu
case .unknown: return .unknown
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return .unknown
#else
return .unknown
#endif
Expand All @@ -1520,6 +1534,9 @@ extension Device.CPU: CustomStringConvertible {
% end
case .unknown: return "unknown"
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return "unknown"
#else
return "unknown"
#endif
Expand Down

0 comments on commit fe41d18

Please sign in to comment.