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

Fork Sync, visionOS update, iOS 18 fixes #427

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version: 5.9
//===----------------------------------------------------------------------===//
//
// This source file is part of the DeviceKit open source project
Expand All @@ -15,9 +15,10 @@ import PackageDescription
let package = Package(
name: "DeviceKit",
platforms: [
.iOS(.v11),
.tvOS(.v11),
.watchOS(.v4)
.iOS(.v12),
.tvOS(.v12),
.watchOS(.v4),
.visionOS(.v1),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
Expand Down
33 changes: 21 additions & 12 deletions Source/Device.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ public enum Device {
///
/// ![Image]()
case appleWatchSeries10_46mm
#elseif os(visionOS)
case visionPro
#endif

/// Device is [Simulator](https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/iOS_Simulator_Guide/Introduction/Introduction.html)
Expand Down Expand Up @@ -679,8 +681,8 @@ public enum Device {
default: return unknown(identifier)
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return unknown(identifier)
// TODO: add proper visionOS support
return .visionPro
#else
return unknown(identifier)
#endif
Expand Down Expand Up @@ -1059,12 +1061,16 @@ public enum Device {

public var isZoomed: Bool? {
guard isCurrent else { return nil }
#if os(visionOS)
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 @@ -1232,8 +1238,7 @@ public enum Device {
#elseif os(watchOS)
return allWatches
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return []
return [.visionPro]
#else
return []
#endif
Expand Down Expand Up @@ -1481,8 +1486,6 @@ public enum Device {
case .simulator(let model): return model.ppi
case .unknown: return nil
}
#elseif os(tvOS)
return nil
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return nil
Expand All @@ -1506,7 +1509,7 @@ public enum Device {

/// The brightness level of the screen.
public var screenBrightness: Int {
#if os(iOS)
#if os(iOS) && !os(visionOS)
return Int(UIScreen.main.brightness * 100)
#else
return 100
Expand Down Expand Up @@ -1650,8 +1653,11 @@ extension Device: CustomStringConvertible {
case .unknown(let identifier): return identifier
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return "Apple Vision Pro"
switch self {
case .visionPro: return "Vision Pro"
case .simulator(let model): return "Simulator (\(model.description))"
case .unknown(let identifier): return identifier
}
#else
switch self {
case .simulator(let model): return "Simulator (\(model.description))"
Expand Down Expand Up @@ -1796,8 +1802,11 @@ extension Device: CustomStringConvertible {
case .unknown(let identifier): return identifier
}
#elseif os(visionOS)
// TODO: Replace with proper implementation for visionOS.
return "Apple Vision Pro"
switch self {
case .visionPro: return "Apple Vision Pro"
case .simulator(let model): return "Simulator \(model.safeDescription)"
case .unknown(let identifier): return identifier
}
#else
switch self {
case .simulator(let model): return "Simulator (\(model.safeDescription))"
Expand Down Expand Up @@ -1953,7 +1962,7 @@ extension Device.BatteryState: Comparable {
}
#endif

#if os(iOS)
#if os(iOS) && !os(visionOS)
extension Device {
// MARK: Orientation
/**
Expand Down
8 changes: 6 additions & 2 deletions Source/Device.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,16 @@ public enum Device {

public var isZoomed: Bool? {
guard isCurrent else { return nil }
#if os(visionOS)
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 @@ -952,7 +956,7 @@ public enum Device {

/// The brightness level of the screen.
public var screenBrightness: Int {
#if os(iOS)
#if os(iOS) && !os(visionOS)
return Int(UIScreen.main.brightness * 100)
#else
return 100
Expand Down Expand Up @@ -1187,7 +1191,7 @@ extension Device.BatteryState: Comparable {
}
#endif

#if os(iOS)
#if os(iOS) && !os(visionOS)
extension Device {
// MARK: Orientation
/**
Expand Down