From e8598d913c98a3a829a5caa52db377eb8b16c9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Pantale=C3=A3o=20Gon=C3=A7alves?= Date: Thu, 16 Nov 2023 10:01:15 +0100 Subject: [PATCH] Wrap CoreMediaIO inside macCatalyst condition (#2452) Apparently `#if canImport(CoreMediaIO)` is now true even if you are trying to run the App on iOS instead of macOS, so this PR wraps it also under `#if targetEnvironment(macCatalyst)` --- .../HACoreBlahObject.swift | 2 +- .../HACoreBlahProperty.swift | 6 ++---- .../HACoreMediaObjectCamera.swift | 2 +- .../HACoreMediaObjectSystem.swift | 2 +- .../Webhook/Sensors/InputOutputDeviceSensor.swift | 12 ++++++------ 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreBlahObject.swift b/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreBlahObject.swift index e31838eb3..af3ee65f7 100644 --- a/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreBlahObject.swift +++ b/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreBlahObject.swift @@ -56,6 +56,7 @@ class HACoreBlahObject { } } +#if targetEnvironment(macCatalyst) #if canImport(CoreMediaIO) import CoreMediaIO @@ -74,7 +75,6 @@ class HACoreMediaObject: HACoreBlahObject { } #endif -#if targetEnvironment(macCatalyst) import CoreAudio class HACoreAudioObject: HACoreBlahObject { diff --git a/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreBlahProperty.swift b/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreBlahProperty.swift index f45311366..aac2d845e 100644 --- a/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreBlahProperty.swift +++ b/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreBlahProperty.swift @@ -1,9 +1,9 @@ import Foundation +#if targetEnvironment(macCatalyst) #if canImport(CoreMediaIO) import CoreMediaIO #endif -#if targetEnvironment(macCatalyst) import CoreAudio #endif @@ -14,6 +14,7 @@ public protocol HACoreBlahProperty { func getPropertyData(objectID: UInt32, dataSize: UInt32, output: UnsafeMutableRawPointer) -> OSStatus } +#if targetEnvironment(macCatalyst) #if canImport(CoreMediaIO) public struct HACoreMediaProperty: HACoreBlahProperty { public typealias ValueType = Type @@ -49,7 +50,6 @@ public struct HACoreMediaProperty: HACoreBlahProperty { } #endif -#if targetEnvironment(macCatalyst) public struct HACoreAudioProperty: HACoreBlahProperty { public typealias ValueType = Type public let address: AudioObjectPropertyAddress @@ -82,7 +82,6 @@ public struct HACoreAudioProperty: HACoreBlahProperty { } } } -#endif #if canImport(CoreMediaIO) extension HACoreMediaProperty { @@ -151,7 +150,6 @@ extension HACoreMediaProperty { } #endif -#if targetEnvironment(macCatalyst) extension HACoreAudioProperty { static var deviceUID: HACoreAudioProperty> { /* diff --git a/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreMediaObjectCamera.swift b/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreMediaObjectCamera.swift index 9442f7f43..c60c4a36f 100644 --- a/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreMediaObjectCamera.swift +++ b/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreMediaObjectCamera.swift @@ -1,6 +1,6 @@ import Foundation -#if canImport(CoreMediaIO) +#if canImport(CoreMediaIO) && targetEnvironment(macCatalyst) import CoreMediaIO class HACoreMediaObjectCamera: HACoreMediaObject { diff --git a/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreMediaObjectSystem.swift b/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreMediaObjectSystem.swift index d0889b59e..b4a3fb794 100644 --- a/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreMediaObjectSystem.swift +++ b/Sources/Shared/API/Webhook/Sensors/CoreMedia and CoreAudio Helpers/HACoreMediaObjectSystem.swift @@ -1,6 +1,6 @@ import Foundation -#if canImport(CoreMediaIO) +#if canImport(CoreMediaIO) && targetEnvironment(macCatalyst) import CoreMediaIO class HACoreMediaObjectSystem: HACoreMediaObject { diff --git a/Sources/Shared/API/Webhook/Sensors/InputOutputDeviceSensor.swift b/Sources/Shared/API/Webhook/Sensors/InputOutputDeviceSensor.swift index d30799908..4830af489 100644 --- a/Sources/Shared/API/Webhook/Sensors/InputOutputDeviceSensor.swift +++ b/Sources/Shared/API/Webhook/Sensors/InputOutputDeviceSensor.swift @@ -17,20 +17,20 @@ private class InputOutputDeviceUpdateSignaler: SensorProviderUpdateSignaler { #if targetEnvironment(macCatalyst) case coreAudio(AudioObjectID) - #endif #if canImport(CoreMediaIO) case coreMedia(CMIOObjectID) #endif + #endif var id: UInt32 { switch self { case .invalid: return .max #if targetEnvironment(macCatalyst) case let .coreAudio(id): return id - #endif #if canImport(CoreMediaIO) case let .coreMedia(id): return id #endif + #endif } } } @@ -40,11 +40,11 @@ private class InputOutputDeviceUpdateSignaler: SensorProviderUpdateSignaler { required init(signal: @escaping () -> Void) { self.signal = signal + #if targetEnvironment(macCatalyst) #if canImport(CoreMediaIO) addCoreMediaObserver(for: CMIOObjectID(kCMIOObjectSystemObject), property: .allDevices) #endif - #if targetEnvironment(macCatalyst) addCoreAudioObserver(for: AudioObjectID(kAudioObjectSystemObject), property: .allDevices) #endif } @@ -70,7 +70,6 @@ private class InputOutputDeviceUpdateSignaler: SensorProviderUpdateSignaler { ) { addObserver(object: .coreAudio(id), property: property) } - #endif #if canImport(CoreMediaIO) func addCoreMediaObserver( @@ -80,6 +79,7 @@ private class InputOutputDeviceUpdateSignaler: SensorProviderUpdateSignaler { addObserver(object: .coreMedia(id), property: property) } #endif + #endif } public class InputOutputDeviceSensor: SensorProvider { @@ -89,19 +89,19 @@ public class InputOutputDeviceSensor: SensorProvider { public let request: SensorProviderRequest + #if targetEnvironment(macCatalyst) #if canImport(CoreMediaIO) let cameraSystemObject: HACoreMediaObjectSystem #endif - #if targetEnvironment(macCatalyst) let audioSystemObject: HACoreAudioObjectSystem #endif public required init(request: SensorProviderRequest) { self.request = request + #if targetEnvironment(macCatalyst) #if canImport(CoreMediaIO) self.cameraSystemObject = HACoreMediaObjectSystem() #endif - #if targetEnvironment(macCatalyst) self.audioSystemObject = HACoreAudioObjectSystem() #endif }