Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>

This commit is contained in:
Matt Bruce 2025-09-08 16:34:50 -05:00
parent b59fe7fe26
commit 6fd0562a41
4 changed files with 11 additions and 4 deletions

View File

@ -6,7 +6,8 @@ import PackageDescription
let package = Package( let package = Package(
name: "AudioPlaybackKit", name: "AudioPlaybackKit",
platforms: [ platforms: [
.iOS(.v17) .iOS(.v17),
.tvOS(.v17)
], ],
products: [ products: [
// Products define the executables and libraries a package produces, making them visible to other packages. // Products define the executables and libraries a package produces, making them visible to other packages.

View File

@ -9,7 +9,7 @@ import AVFoundation
import Observation import Observation
/// Audio playback service for white noise and ambient sounds /// Audio playback service for white noise and ambient sounds
@available(iOS 17.0, *) @available(iOS 17.0, tvOS 17.0, *)
@Observable @Observable
public class NoisePlayer { public class NoisePlayer {

View File

@ -5,11 +5,13 @@
// Created by Matt Bruce on 9/8/25. // Created by Matt Bruce on 9/8/25.
// //
#if canImport(UIKit)
import UIKit import UIKit
#endif
import Observation import Observation
/// Service to manage screen wake lock and prevent device from sleeping /// Service to manage screen wake lock and prevent device from sleeping
@available(iOS 17.0, *) @available(iOS 17.0, tvOS 17.0, *)
@Observable @Observable
public class WakeLockService { public class WakeLockService {
@ -33,6 +35,7 @@ public class WakeLockService {
public func enableWakeLock() { public func enableWakeLock() {
guard !isWakeLockActive else { return } guard !isWakeLockActive else { return }
#if canImport(UIKit)
// Prevent device from sleeping // Prevent device from sleeping
UIApplication.shared.isIdleTimerDisabled = true UIApplication.shared.isIdleTimerDisabled = true
@ -44,6 +47,7 @@ public class WakeLockService {
UIApplication.shared.isIdleTimerDisabled = true UIApplication.shared.isIdleTimerDisabled = true
} }
} }
#endif
isWakeLockActive = true isWakeLockActive = true
print("🔒 Wake lock enabled - device will not sleep") print("🔒 Wake lock enabled - device will not sleep")
@ -53,8 +57,10 @@ public class WakeLockService {
public func disableWakeLock() { public func disableWakeLock() {
guard isWakeLockActive else { return } guard isWakeLockActive else { return }
#if canImport(UIKit)
// Allow device to sleep normally // Allow device to sleep normally
UIApplication.shared.isIdleTimerDisabled = false UIApplication.shared.isIdleTimerDisabled = false
#endif
// Stop the maintenance timer // Stop the maintenance timer
wakeLockTimer?.invalidate() wakeLockTimer?.invalidate()

View File

@ -9,7 +9,7 @@ import Foundation
import Observation import Observation
/// ViewModel for noise/audio playback /// ViewModel for noise/audio playback
@available(iOS 17.0, *) @available(iOS 17.0, tvOS 17.0, *)
@Observable @Observable
public class NoiseViewModel { public class NoiseViewModel {