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(
name: "AudioPlaybackKit",
platforms: [
.iOS(.v17)
.iOS(.v17),
.tvOS(.v17)
],
products: [
// 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
/// Audio playback service for white noise and ambient sounds
@available(iOS 17.0, *)
@available(iOS 17.0, tvOS 17.0, *)
@Observable
public class NoisePlayer {

View File

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

View File

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