From 8359a4ea22df64726ca465abac945679614d8d31 Mon Sep 17 00:00:00 2001 From: bjovanovic84 Date: Wed, 24 Jan 2024 17:33:05 -0500 Subject: [PATCH 1/5] visionos patches --- Package.swift | 9 +++++---- Source/Device.generated.swift | 33 ++++++++++++++++++++++++++++----- Source/Device.swift.gyb | 6 +++--- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Package.swift b/Package.swift index 5f4edd3..c18a866 100644 --- a/Package.swift +++ b/Package.swift @@ -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 @@ -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. diff --git a/Source/Device.generated.swift b/Source/Device.generated.swift index d1b796e..5f672a7 100644 --- a/Source/Device.generated.swift +++ b/Source/Device.generated.swift @@ -472,6 +472,8 @@ public enum Device { /// /// ![Image]() case appleWatchUltra2 + #elseif os(visionOS) + case visionPro #endif /// Device is [Simulator](https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/iOS_Simulator_Guide/Introduction/Introduction.html) @@ -628,6 +630,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: add proper visionOS support + return .visionPro #endif } @@ -877,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) #endif } @@ -982,7 +987,7 @@ public enum Device { public var isZoomed: Bool? { guard isCurrent else { return nil } - #if os(xrOS) + #if os(visionOS) return nil #else if Int(UIScreen.main.scale.rounded()) == 3 { @@ -1158,6 +1163,8 @@ public enum Device { return allTVs #elseif os(watchOS) return allWatches + #elseif os(visionOS) + return [.visionPro] #endif } @@ -1383,7 +1390,7 @@ public enum Device { case .simulator(let model): return model.ppi case .unknown: return nil } - #elseif os(tvOS) + #else return nil #endif } @@ -1403,7 +1410,7 @@ public enum Device { /// The brightness level of the screen. public var screenBrightness: Int { - #if os(iOS) && !os(xrOS) + #if os(iOS) && !os(visionOS) return Int(UIScreen.main.brightness * 100) #else return 100 @@ -1536,6 +1543,12 @@ extension Device: CustomStringConvertible { case .simulator(let model): return "Simulator (\(model.description))" case .unknown(let identifier): return identifier } + #elseif os(visionOS) + switch self { + case .visionPro: return "Vision Pro" + case .simulator(let model): return "Simulator (\(model.description))" + case .unknown(let identifier): return identifier + } #endif } @@ -1664,6 +1677,12 @@ extension Device: CustomStringConvertible { case .simulator(let model): return "Simulator (\(model.safeDescription))" case .unknown(let identifier): return identifier } + #elseif os(visionOS) + switch self { + case .visionPro: return "Apple Vision Pro" + case .simulator(let model): return "Simulator (\(model.safeDescription))" + case .unknown(let identifier): return identifier + } #endif } @@ -1814,7 +1833,7 @@ extension Device.BatteryState: Comparable { } #endif -#if os(iOS) && !os(xrOS) +#if os(iOS) && !os(visionOS) extension Device { // MARK: Orientation /** @@ -2298,6 +2317,8 @@ extension Device { case .simulator(let model): return model.cpu case .unknown: return .unknown } + #else + return .unknown #endif } } @@ -2347,6 +2368,8 @@ extension Device.CPU: CustomStringConvertible { case .s9: return "S9" case .unknown: return "unknown" } + #else + return "unknown" #endif } } diff --git a/Source/Device.swift.gyb b/Source/Device.swift.gyb index 67cbb89..898e659 100644 --- a/Source/Device.swift.gyb +++ b/Source/Device.swift.gyb @@ -585,7 +585,7 @@ public enum Device { public var isZoomed: Bool? { guard isCurrent else { return nil } - #if os(xrOS) + #if os(visionOS) return nil #else if Int(UIScreen.main.scale.rounded()) == 3 { @@ -911,7 +911,7 @@ public enum Device { /// The brightness level of the screen. public var screenBrightness: Int { - #if os(iOS) && !os(xrOS) + #if os(iOS) && !os(visionOS) return Int(UIScreen.main.brightness * 100) #else return 100 @@ -1130,7 +1130,7 @@ extension Device.BatteryState: Comparable { } #endif -#if os(iOS) && !os(xrOS) +#if os(iOS) && !os(visionOS) extension Device { // MARK: Orientation /** From 1906dc504096237b2b352069a2bb98af30145670 Mon Sep 17 00:00:00 2001 From: Nick McCardel Date: Mon, 30 Sep 2024 10:00:11 -0600 Subject: [PATCH 2/5] update --- Source/Device.generated.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Device.generated.swift b/Source/Device.generated.swift index 6244b15..af76122 100644 --- a/Source/Device.generated.swift +++ b/Source/Device.generated.swift @@ -1070,6 +1070,7 @@ public enum Device { } else { return UIScreen.main.nativeScale > UIScreen.main.scale } + #endif } /// All Touch ID Capable Devices From 1e5cd30eb9a9e01ac909a4b4bc6359b5dde86f44 Mon Sep 17 00:00:00 2001 From: Nick McCardel Date: Mon, 30 Sep 2024 10:07:40 -0600 Subject: [PATCH 3/5] once more --- Source/Device.generated.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Device.generated.swift b/Source/Device.generated.swift index af76122..4d6025d 100644 --- a/Source/Device.generated.swift +++ b/Source/Device.generated.swift @@ -1486,8 +1486,6 @@ public enum Device { case .simulator(let model): return model.ppi case .unknown: return nil } - #else - return nil #elseif os(visionOS) // TODO: Replace with proper implementation for visionOS. return nil From f1a068237a25adffdede97db5a848c2d17686273 Mon Sep 17 00:00:00 2001 From: Nick McCardel Date: Mon, 30 Sep 2024 10:13:43 -0600 Subject: [PATCH 4/5] this workflow isnt great --- Source/Device.generated.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Device.generated.swift b/Source/Device.generated.swift index 4d6025d..c6c6988 100644 --- a/Source/Device.generated.swift +++ b/Source/Device.generated.swift @@ -1804,6 +1804,7 @@ extension Device: CustomStringConvertible { #elseif os(visionOS) switch self { case .visionPro: return "Apple Vision Pro" + } #else switch self { case .simulator(let model): return "Simulator (\(model.safeDescription))" From 66e62cfd22daedda258f28aee3797eccdd2b34bf Mon Sep 17 00:00:00 2001 From: Nick McCardel Date: Sat, 23 Nov 2024 15:21:37 -0700 Subject: [PATCH 5/5] visionos sim patch --- Source/Device.generated.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Device.generated.swift b/Source/Device.generated.swift index c6c6988..82d81cf 100644 --- a/Source/Device.generated.swift +++ b/Source/Device.generated.swift @@ -1804,6 +1804,8 @@ extension Device: CustomStringConvertible { #elseif os(visionOS) 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 {