From 9b1d4aabbd747fc0b7619fa0d342fa86ab15cc90 Mon Sep 17 00:00:00 2001 From: Steven Roebert Date: Fri, 12 Aug 2022 15:01:42 +0200 Subject: [PATCH] Fixes for previews in SwiftUI --- Sources/MQTTNIO/Handlers/MQTTErrorHandler.swift | 3 ++- Sources/MQTTNIO/MQTTConfiguration.swift | 3 ++- Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/MQTTNIO/Handlers/MQTTErrorHandler.swift b/Sources/MQTTNIO/Handlers/MQTTErrorHandler.swift index 88d6a76..6447869 100644 --- a/Sources/MQTTNIO/Handlers/MQTTErrorHandler.swift +++ b/Sources/MQTTNIO/Handlers/MQTTErrorHandler.swift @@ -20,7 +20,8 @@ final class MQTTErrorHandler: ChannelInboundHandler { } func errorCaught(context: ChannelHandlerContext, error: Error) { - #if canImport(NIOSSL) + // This should use `canImport(NIOSSL)`, will change when it works with SwiftUI previews. + #if os(macOS) || os(Linux) // We ignore unclean shutdowns, which could be caused by servers not sending `close_notify` if let sslError = error as? NIOSSLError, case .uncleanShutdown = sslError { return diff --git a/Sources/MQTTNIO/MQTTConfiguration.swift b/Sources/MQTTNIO/MQTTConfiguration.swift index 2ec7911..1c469d2 100644 --- a/Sources/MQTTNIO/MQTTConfiguration.swift +++ b/Sources/MQTTNIO/MQTTConfiguration.swift @@ -541,7 +541,8 @@ extension MQTTConfiguration { } } -#if canImport(NIOSSL) +// This should use `canImport(NIOSSL)`, will change when it works with SwiftUI previews. +#if os(macOS) || os(Linux) extension MQTTConfiguration { /// Creates an `MQTTConfiguration`. /// - Parameters: diff --git a/Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift b/Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift index d178f5b..ec2d6f5 100644 --- a/Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift +++ b/Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift @@ -117,7 +117,8 @@ class MQTTNIOTestCase: XCTestCase { ), eventLoopGroupProvider: .shared(tlsGroup)) } - #if canImport(NIOSSL) + // This should use `canImport(NIOSSL)`, will change when it works with SwiftUI previews. + #if os(macOS) || os(Linux) var nioSSLTLSClient: MQTTClient { get throws { let rootDir = URL(fileURLWithPath: #file)