watch fixes

Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
Matt Bruce 2026-02-18 12:32:29 -06:00
parent 5f404873a1
commit 11d8514f17
5 changed files with 49 additions and 14 deletions

View File

@ -9,7 +9,7 @@ import AVFoundation
import Foundation import Foundation
import SwiftUI import SwiftUI
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
@_implementationOnly import UIKit @_implementationOnly import UIKit
#endif #endif
@ -105,7 +105,7 @@ public final class SoundManager {
private var audioPlayers: [String: AVAudioPlayer] = [:] private var audioPlayers: [String: AVAudioPlayer] = [:]
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
private let impactLight = UIImpactFeedbackGenerator(style: .light) private let impactLight = UIImpactFeedbackGenerator(style: .light)
private let impactMedium = UIImpactFeedbackGenerator(style: .medium) private let impactMedium = UIImpactFeedbackGenerator(style: .medium)
private let impactHeavy = UIImpactFeedbackGenerator(style: .heavy) private let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
@ -174,7 +174,9 @@ public final class SoundManager {
// Fall back to system sound if available // Fall back to system sound if available
if let systemSoundID = sound.fallbackSystemSoundID { if let systemSoundID = sound.fallbackSystemSoundID {
#if !os(watchOS)
AudioServicesPlaySystemSound(systemSoundID) AudioServicesPlaySystemSound(systemSoundID)
#endif
} }
} }
@ -182,7 +184,9 @@ public final class SoundManager {
/// - Parameter soundID: The system sound ID to play. /// - Parameter soundID: The system sound ID to play.
public func playSystemSound(_ soundID: UInt32) { public func playSystemSound(_ soundID: UInt32) {
guard isSoundEnabled else { return } guard isSoundEnabled else { return }
#if !os(watchOS)
AudioServicesPlaySystemSound(soundID) AudioServicesPlaySystemSound(soundID)
#endif
} }
/// Preloads sounds for faster playback later. /// Preloads sounds for faster playback later.
@ -213,7 +217,7 @@ public final class SoundManager {
/// Plays haptic feedback. /// Plays haptic feedback.
/// - Parameter type: The type of haptic feedback to play. /// - Parameter type: The type of haptic feedback to play.
public func playHaptic(_ type: HapticType) { public func playHaptic(_ type: HapticType) {
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
guard isHapticEnabled else { return } guard isHapticEnabled else { return }
switch type { switch type {
@ -244,7 +248,7 @@ public final class SoundManager {
/// - style: The impact style. /// - style: The impact style.
/// - intensity: The intensity (0.0 to 1.0). /// - intensity: The intensity (0.0 to 1.0).
public func playHaptic(style: HapticType, intensity: CGFloat) { public func playHaptic(style: HapticType, intensity: CGFloat) {
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
guard isHapticEnabled else { return } guard isHapticEnabled else { return }
let generator: UIImpactFeedbackGenerator let generator: UIImpactFeedbackGenerator
@ -269,7 +273,7 @@ public final class SoundManager {
/// Prepares haptic generators for immediate feedback. /// Prepares haptic generators for immediate feedback.
public func prepareHaptics() { public func prepareHaptics() {
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
impactLight.prepare() impactLight.prepare()
impactMedium.prepare() impactMedium.prepare()
impactHeavy.prepare() impactHeavy.prepare()

View File

@ -153,7 +153,7 @@ public struct IconGeneratorView: View {
@MainActor @MainActor
private func generateIcon() async { private func generateIcon() async {
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
isGenerating = true isGenerating = true
generatedIcon = nil generatedIcon = nil
status = "Generating icon..." status = "Generating icon..."

View File

@ -8,7 +8,11 @@
import Foundation import Foundation
import SwiftUI import SwiftUI
#if canImport(UIKit) #if canImport(AppKit)
import AppKit
#endif
#if canImport(UIKit) && !os(watchOS)
@_implementationOnly import UIKit @_implementationOnly import UIKit
#endif #endif
@ -17,7 +21,7 @@ public enum DeviceInfo {
// MARK: - Device Type // MARK: - Device Type
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
/// Whether the current device is an iPad. /// Whether the current device is an iPad.
public static var isPad: Bool { public static var isPad: Bool {
UIDevice.current.userInterfaceIdiom == .pad UIDevice.current.userInterfaceIdiom == .pad
@ -56,7 +60,7 @@ public enum DeviceInfo {
// MARK: - Screen Info // MARK: - Screen Info
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
/// Returns the current screen bounds. /// Returns the current screen bounds.
public static var screenBounds: CGRect { public static var screenBounds: CGRect {
currentScreen?.bounds ?? .zero currentScreen?.bounds ?? .zero
@ -75,7 +79,7 @@ public enum DeviceInfo {
.first? .first?
.screen .screen
} }
#else #elseif os(macOS)
/// Returns the current screen bounds (main screen on macOS). /// Returns the current screen bounds (main screen on macOS).
public static var screenBounds: CGRect { public static var screenBounds: CGRect {
NSScreen.main?.frame ?? .zero NSScreen.main?.frame ?? .zero
@ -85,6 +89,12 @@ public enum DeviceInfo {
public static var screenScale: CGFloat { public static var screenScale: CGFloat {
NSScreen.main?.backingScaleFactor ?? 1.0 NSScreen.main?.backingScaleFactor ?? 1.0
} }
#else
/// Returns the current screen bounds on unsupported platforms.
public static var screenBounds: CGRect { .zero }
/// Returns the current screen scale on unsupported platforms.
public static var screenScale: CGFloat { 1.0 }
#endif #endif
// MARK: - Layout Helpers // MARK: - Layout Helpers
@ -112,7 +122,7 @@ public enum DeviceInfo {
// MARK: - System Info // MARK: - System Info
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
/// The current iOS version string. /// The current iOS version string.
public static var systemVersion: String { public static var systemVersion: String {
UIDevice.current.systemVersion UIDevice.current.systemVersion
@ -122,7 +132,7 @@ public enum DeviceInfo {
public static var deviceName: String { public static var deviceName: String {
UIDevice.current.name UIDevice.current.name
} }
#else #elseif os(macOS)
/// The current macOS version string. /// The current macOS version string.
public static var systemVersion: String { public static var systemVersion: String {
ProcessInfo.processInfo.operatingSystemVersionString ProcessInfo.processInfo.operatingSystemVersionString
@ -132,12 +142,22 @@ public enum DeviceInfo {
public static var deviceName: String { public static var deviceName: String {
Host.current().localizedName ?? "Mac" Host.current().localizedName ?? "Mac"
} }
#else
/// The current OS version string on unsupported platforms.
public static var systemVersion: String {
ProcessInfo.processInfo.operatingSystemVersionString
}
/// The device name on unsupported platforms.
public static var deviceName: String {
"Unknown Device"
}
#endif #endif
} }
// MARK: - UIScreen Extension // MARK: - UIScreen Extension
#if canImport(UIKit) #if canImport(UIKit) && !os(watchOS)
extension UIScreen { extension UIScreen {
/// Returns the current active screen (the one displaying the key window). /// Returns the current active screen (the one displaying the key window).
/// This is the recommended replacement for the deprecated `UIScreen.main`. /// This is the recommended replacement for the deprecated `UIScreen.main`.

View File

@ -6,8 +6,10 @@
// //
import SwiftUI import SwiftUI
#if canImport(CoreImage)
import CoreImage import CoreImage
import CoreImage.CIFilterBuiltins import CoreImage.CIFilterBuiltins
#endif
/// Generates QR codes from string data. /// Generates QR codes from string data.
/// ///
@ -23,7 +25,9 @@ import CoreImage.CIFilterBuiltins
public enum QRCodeGenerator { public enum QRCodeGenerator {
/// The CIContext used for rendering. /// The CIContext used for rendering.
#if canImport(CoreImage)
private static let context = CIContext() private static let context = CIContext()
#endif
/// Error correction levels for QR codes. /// Error correction levels for QR codes.
public enum CorrectionLevel: String, Sendable { public enum CorrectionLevel: String, Sendable {
@ -48,6 +52,7 @@ public enum QRCodeGenerator {
correctionLevel: CorrectionLevel = .medium, correctionLevel: CorrectionLevel = .medium,
scale: CGFloat = 10 scale: CGFloat = 10
) -> CGImage? { ) -> CGImage? {
#if canImport(CoreImage)
let data = Data(payload.utf8) let data = Data(payload.utf8)
let filter = CIFilter.qrCodeGenerator() let filter = CIFilter.qrCodeGenerator()
filter.setValue(data, forKey: "inputMessage") filter.setValue(data, forKey: "inputMessage")
@ -60,6 +65,12 @@ public enum QRCodeGenerator {
) )
return context.createCGImage(scaledImage, from: scaledImage.extent) return context.createCGImage(scaledImage, from: scaledImage.extent)
#else
_ = payload
_ = correctionLevel
_ = scale
return nil
#endif
} }
} }

View File

@ -75,7 +75,7 @@ public struct SettingsRow<Accessory: View>: View {
} }
.padding(.vertical, Design.Spacing.medium) .padding(.vertical, Design.Spacing.medium)
.padding(.horizontal, Design.Spacing.medium) .padding(.horizontal, Design.Spacing.medium)
.background(Color(.secondarySystemGroupedBackground)) .background(Color.Surface.groupedFill)
.clipShape(.rect(cornerRadius: Design.CornerRadius.small)) .clipShape(.rect(cornerRadius: Design.CornerRadius.small))
} }
.padding(.vertical, Design.Spacing.small) .padding(.vertical, Design.Spacing.small)