watch fixes
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
5f404873a1
commit
11d8514f17
@ -9,7 +9,7 @@ import AVFoundation
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
@_implementationOnly import UIKit
|
||||
#endif
|
||||
|
||||
@ -105,7 +105,7 @@ public final class SoundManager {
|
||||
|
||||
private var audioPlayers: [String: AVAudioPlayer] = [:]
|
||||
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
private let impactLight = UIImpactFeedbackGenerator(style: .light)
|
||||
private let impactMedium = UIImpactFeedbackGenerator(style: .medium)
|
||||
private let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
|
||||
@ -174,7 +174,9 @@ public final class SoundManager {
|
||||
|
||||
// Fall back to system sound if available
|
||||
if let systemSoundID = sound.fallbackSystemSoundID {
|
||||
#if !os(watchOS)
|
||||
AudioServicesPlaySystemSound(systemSoundID)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +184,9 @@ public final class SoundManager {
|
||||
/// - Parameter soundID: The system sound ID to play.
|
||||
public func playSystemSound(_ soundID: UInt32) {
|
||||
guard isSoundEnabled else { return }
|
||||
#if !os(watchOS)
|
||||
AudioServicesPlaySystemSound(soundID)
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Preloads sounds for faster playback later.
|
||||
@ -213,7 +217,7 @@ public final class SoundManager {
|
||||
/// Plays haptic feedback.
|
||||
/// - Parameter type: The type of haptic feedback to play.
|
||||
public func playHaptic(_ type: HapticType) {
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
guard isHapticEnabled else { return }
|
||||
|
||||
switch type {
|
||||
@ -244,7 +248,7 @@ public final class SoundManager {
|
||||
/// - style: The impact style.
|
||||
/// - intensity: The intensity (0.0 to 1.0).
|
||||
public func playHaptic(style: HapticType, intensity: CGFloat) {
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
guard isHapticEnabled else { return }
|
||||
|
||||
let generator: UIImpactFeedbackGenerator
|
||||
@ -269,7 +273,7 @@ public final class SoundManager {
|
||||
|
||||
/// Prepares haptic generators for immediate feedback.
|
||||
public func prepareHaptics() {
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
impactLight.prepare()
|
||||
impactMedium.prepare()
|
||||
impactHeavy.prepare()
|
||||
|
||||
@ -153,7 +153,7 @@ public struct IconGeneratorView: View {
|
||||
|
||||
@MainActor
|
||||
private func generateIcon() async {
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
isGenerating = true
|
||||
generatedIcon = nil
|
||||
status = "Generating icon..."
|
||||
|
||||
@ -8,7 +8,11 @@
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
#if canImport(UIKit)
|
||||
#if canImport(AppKit)
|
||||
import AppKit
|
||||
#endif
|
||||
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
@_implementationOnly import UIKit
|
||||
#endif
|
||||
|
||||
@ -17,7 +21,7 @@ public enum DeviceInfo {
|
||||
|
||||
// MARK: - Device Type
|
||||
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
/// Whether the current device is an iPad.
|
||||
public static var isPad: Bool {
|
||||
UIDevice.current.userInterfaceIdiom == .pad
|
||||
@ -56,7 +60,7 @@ public enum DeviceInfo {
|
||||
|
||||
// MARK: - Screen Info
|
||||
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
/// Returns the current screen bounds.
|
||||
public static var screenBounds: CGRect {
|
||||
currentScreen?.bounds ?? .zero
|
||||
@ -75,7 +79,7 @@ public enum DeviceInfo {
|
||||
.first?
|
||||
.screen
|
||||
}
|
||||
#else
|
||||
#elseif os(macOS)
|
||||
/// Returns the current screen bounds (main screen on macOS).
|
||||
public static var screenBounds: CGRect {
|
||||
NSScreen.main?.frame ?? .zero
|
||||
@ -85,6 +89,12 @@ public enum DeviceInfo {
|
||||
public static var screenScale: CGFloat {
|
||||
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
|
||||
|
||||
// MARK: - Layout Helpers
|
||||
@ -112,7 +122,7 @@ public enum DeviceInfo {
|
||||
|
||||
// MARK: - System Info
|
||||
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
/// The current iOS version string.
|
||||
public static var systemVersion: String {
|
||||
UIDevice.current.systemVersion
|
||||
@ -122,7 +132,7 @@ public enum DeviceInfo {
|
||||
public static var deviceName: String {
|
||||
UIDevice.current.name
|
||||
}
|
||||
#else
|
||||
#elseif os(macOS)
|
||||
/// The current macOS version string.
|
||||
public static var systemVersion: String {
|
||||
ProcessInfo.processInfo.operatingSystemVersionString
|
||||
@ -132,12 +142,22 @@ public enum DeviceInfo {
|
||||
public static var deviceName: String {
|
||||
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
|
||||
}
|
||||
|
||||
// MARK: - UIScreen Extension
|
||||
|
||||
#if canImport(UIKit)
|
||||
#if canImport(UIKit) && !os(watchOS)
|
||||
extension UIScreen {
|
||||
/// Returns the current active screen (the one displaying the key window).
|
||||
/// This is the recommended replacement for the deprecated `UIScreen.main`.
|
||||
|
||||
@ -6,8 +6,10 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
#if canImport(CoreImage)
|
||||
import CoreImage
|
||||
import CoreImage.CIFilterBuiltins
|
||||
#endif
|
||||
|
||||
/// Generates QR codes from string data.
|
||||
///
|
||||
@ -23,7 +25,9 @@ import CoreImage.CIFilterBuiltins
|
||||
public enum QRCodeGenerator {
|
||||
|
||||
/// The CIContext used for rendering.
|
||||
#if canImport(CoreImage)
|
||||
private static let context = CIContext()
|
||||
#endif
|
||||
|
||||
/// Error correction levels for QR codes.
|
||||
public enum CorrectionLevel: String, Sendable {
|
||||
@ -48,6 +52,7 @@ public enum QRCodeGenerator {
|
||||
correctionLevel: CorrectionLevel = .medium,
|
||||
scale: CGFloat = 10
|
||||
) -> CGImage? {
|
||||
#if canImport(CoreImage)
|
||||
let data = Data(payload.utf8)
|
||||
let filter = CIFilter.qrCodeGenerator()
|
||||
filter.setValue(data, forKey: "inputMessage")
|
||||
@ -60,6 +65,12 @@ public enum QRCodeGenerator {
|
||||
)
|
||||
|
||||
return context.createCGImage(scaledImage, from: scaledImage.extent)
|
||||
#else
|
||||
_ = payload
|
||||
_ = correctionLevel
|
||||
_ = scale
|
||||
return nil
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -75,7 +75,7 @@ public struct SettingsRow<Accessory: View>: View {
|
||||
}
|
||||
.padding(.vertical, Design.Spacing.medium)
|
||||
.padding(.horizontal, Design.Spacing.medium)
|
||||
.background(Color(.secondarySystemGroupedBackground))
|
||||
.background(Color.Surface.groupedFill)
|
||||
.clipShape(.rect(cornerRadius: Design.CornerRadius.small))
|
||||
}
|
||||
.padding(.vertical, Design.Spacing.small)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user