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

This commit is contained in:
Matt Bruce 2026-01-31 11:23:02 -06:00
parent 3307ba5433
commit 74ece5a71a
10 changed files with 63 additions and 97 deletions

1
PRD.md
View File

@ -391,7 +391,6 @@ TheNoiseClock/
│ │ │ └── SoundCategory.swift # Shared sound category definitions │ │ │ └── SoundCategory.swift # Shared sound category definitions
│ │ └── Utilities/ │ │ └── Utilities/
│ │ ├── ColorUtils.swift # Color manipulation utilities │ │ ├── ColorUtils.swift # Color manipulation utilities
│ │ ├── DebugLogger.swift # Debug logging helper
│ │ └── NotificationUtils.swift # Notification helper functions │ │ └── NotificationUtils.swift # Notification helper functions
│ ├── Features/ │ ├── Features/
│ │ ├── Clock/ │ │ ├── Clock/

View File

@ -7,6 +7,7 @@
import Foundation import Foundation
import AudioPlaybackKit import AudioPlaybackKit
import Bedrock
/// Extension service for alarm-specific sound functionality /// Extension service for alarm-specific sound functionality
class AlarmSoundService { class AlarmSoundService {
@ -42,7 +43,7 @@ class AlarmSoundService {
/// Load audio settings from SoundsSettings.json /// Load audio settings from SoundsSettings.json
private func loadAudioSettings() -> AudioSettings { private func loadAudioSettings() -> AudioSettings {
guard let url = Bundle.main.url(forResource: "SoundsSettings", withExtension: "json") else { guard let url = Bundle.main.url(forResource: "SoundsSettings", withExtension: "json") else {
DebugLogger.log("Warning: SoundsSettings.json not found, using default alarm settings", category: .general) Design.debugLog("[general] Warning: SoundsSettings.json not found, using default alarm settings")
return AudioSettings( return AudioSettings(
defaultVolume: 1.0, defaultVolume: 1.0,
defaultLoopCount: -1, defaultLoopCount: -1,
@ -57,10 +58,10 @@ class AlarmSoundService {
do { do {
let data = try Data(contentsOf: url) let data = try Data(contentsOf: url)
let settings = try JSONDecoder().decode(AudioSettings.self, from: data) let settings = try JSONDecoder().decode(AudioSettings.self, from: data)
DebugLogger.log("Loaded audio settings for alarms from SoundsSettings.json", category: .settings) Design.debugLog("[settings] Loaded audio settings for alarms from SoundsSettings.json")
return settings return settings
} catch { } catch {
DebugLogger.log("Warning: Error loading audio settings for alarms, using defaults: \(error)", category: .general) Design.debugLog("[general] Warning: Error loading audio settings for alarms, using defaults: \(error)")
return AudioSettings( return AudioSettings(
defaultVolume: 1.0, defaultVolume: 1.0,
defaultLoopCount: -1, defaultLoopCount: -1,

View File

@ -9,6 +9,7 @@ import Foundation
import Observation import Observation
import UIKit import UIKit
import UserNotifications import UserNotifications
import Bedrock
/// Service to align notifications with Focus mode behavior /// Service to align notifications with Focus mode behavior
@Observable @Observable
@ -55,7 +56,7 @@ class FocusModeService {
return granted return granted
} catch { } catch {
DebugLogger.log("Error requesting notification permissions: \(error)", category: .general) Design.debugLog("[general] Error requesting notification permissions: \(error)")
return false return false
} }
} }
@ -84,7 +85,7 @@ class FocusModeService {
// Register the category // Register the category
UNUserNotificationCenter.current().setNotificationCategories([alarmCategory]) UNUserNotificationCenter.current().setNotificationCategories([alarmCategory])
DebugLogger.log("Notification settings configured for Focus mode compatibility", category: .settings) Design.debugLog("[settings] Notification settings configured for Focus mode compatibility")
} }
/// Schedule alarm notification with Focus mode awareness /// Schedule alarm notification with Focus mode awareness
@ -103,11 +104,11 @@ class FocusModeService {
// Use the sound name directly since sounds.json now references CAF files // Use the sound name directly since sounds.json now references CAF files
if soundName == "default" { if soundName == "default" {
content.sound = UNNotificationSound.default content.sound = UNNotificationSound.default
DebugLogger.log("Using default notification sound", category: .settings) Design.debugLog("[settings] Using default notification sound")
} else { } else {
content.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: soundName)) content.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: soundName))
DebugLogger.log("Using custom alarm sound: \(soundName)", category: .settings) Design.debugLog("[settings] Using custom alarm sound: \(soundName)")
DebugLogger.log("Sound file should be in main bundle: \(soundName)", category: .settings) Design.debugLog("[settings] Sound file should be in main bundle: \(soundName)")
} }
content.categoryIdentifier = "ALARM_CATEGORY" content.categoryIdentifier = "ALARM_CATEGORY"
@ -143,9 +144,9 @@ class FocusModeService {
// Schedule notification // Schedule notification
UNUserNotificationCenter.current().add(request) { error in UNUserNotificationCenter.current().add(request) { error in
if let error = error { if let error = error {
DebugLogger.log("Error scheduling alarm notification: \(error)", category: .general) Design.debugLog("[general] Error scheduling alarm notification: \(error)")
} else { } else {
DebugLogger.log("Alarm notification scheduled for \(date)", category: .settings) Design.debugLog("[settings] Alarm notification scheduled for \(date)")
} }
} }
} }
@ -153,13 +154,13 @@ class FocusModeService {
/// Cancel alarm notification /// Cancel alarm notification
func cancelAlarmNotification(identifier: String) { func cancelAlarmNotification(identifier: String) {
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [identifier]) UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [identifier])
DebugLogger.log("Cancelled alarm notification: \(identifier)", category: .settings) Design.debugLog("[settings] Cancelled alarm notification: \(identifier)")
} }
/// Cancel all alarm notifications /// Cancel all alarm notifications
func cancelAllAlarmNotifications() { func cancelAllAlarmNotifications() {
UNUserNotificationCenter.current().removeAllPendingNotificationRequests() UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
DebugLogger.log("Cancelled all alarm notifications", category: .settings) Design.debugLog("[settings] Cancelled all alarm notifications")
} }
// MARK: - Private Methods // MARK: - Private Methods
@ -193,10 +194,7 @@ class FocusModeService {
timeSensitiveSetting = settings.timeSensitiveSetting timeSensitiveSetting = settings.timeSensitiveSetting
scheduledDeliverySetting = settings.scheduledDeliverySetting scheduledDeliverySetting = settings.scheduledDeliverySetting
DebugLogger.log( Design.debugLog("[settings] Notification settings updated: auth=\(settings.authorizationStatus), timeSensitive=\(settings.timeSensitiveSetting), scheduledDelivery=\(settings.scheduledDeliverySetting)")
"Notification settings updated: auth=\(settings.authorizationStatus), timeSensitive=\(settings.timeSensitiveSetting), scheduledDelivery=\(settings.scheduledDeliverySetting)",
category: .settings
)
} }
/// Get notification authorization status /// Get notification authorization status
@ -222,7 +220,7 @@ extension FocusModeService {
await configureNotificationSettings() await configureNotificationSettings()
} }
DebugLogger.log("App configured for Focus mode compatibility", category: .settings) Design.debugLog("[settings] App configured for Focus mode compatibility")
} }
/// Provide user guidance for Focus mode settings /// Provide user guidance for Focus mode settings

View File

@ -7,6 +7,7 @@
import UserNotifications import UserNotifications
import Foundation import Foundation
import Bedrock
/// Delegate to handle notification actions (snooze, stop, etc.) /// Delegate to handle notification actions (snooze, stop, etc.)
class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate { class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
@ -26,7 +27,7 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
// MARK: - Setup // MARK: - Setup
private func setupNotificationCenter() { private func setupNotificationCenter() {
UNUserNotificationCenter.current().delegate = self UNUserNotificationCenter.current().delegate = self
DebugLogger.log("Notification delegate configured", category: .settings) Design.debugLog("[settings] Notification delegate configured")
} }
/// Set the alarm service instance (called from AlarmViewModel) /// Set the alarm service instance (called from AlarmViewModel)
@ -46,7 +47,7 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
let notification = response.notification let notification = response.notification
let userInfo = notification.request.content.userInfo let userInfo = notification.request.content.userInfo
DebugLogger.log("Notification action received: \(actionIdentifier)", category: .settings) Design.debugLog("[settings] Notification action received: \(actionIdentifier)")
switch actionIdentifier { switch actionIdentifier {
case "SNOOZE_ACTION": case "SNOOZE_ACTION":
@ -57,7 +58,7 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
// User tapped the notification itself // User tapped the notification itself
handleNotificationTap(userInfo: userInfo) handleNotificationTap(userInfo: userInfo)
default: default:
DebugLogger.log("Unknown action: \(actionIdentifier)", category: .settings) Design.debugLog("[settings] Unknown action: \(actionIdentifier)")
} }
completionHandler() completionHandler()
@ -80,16 +81,16 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
let alarmId = UUID(uuidString: alarmIdString), let alarmId = UUID(uuidString: alarmIdString),
let alarmService = self.alarmService, let alarmService = self.alarmService,
let alarm = alarmService.getAlarm(id: alarmId) else { let alarm = alarmService.getAlarm(id: alarmId) else {
DebugLogger.log("Could not find alarm for snooze action", category: .general) Design.debugLog("[general] Could not find alarm for snooze action")
return return
} }
DebugLogger.log("Snoozing alarm: \(alarm.label) for \(alarm.snoozeDuration) minutes", category: .settings) Design.debugLog("[settings] Snoozing alarm: \(alarm.label) for \(alarm.snoozeDuration) minutes")
// Calculate snooze time (current time + snooze duration) // Calculate snooze time (current time + snooze duration)
let snoozeTime = Date().addingTimeInterval(TimeInterval(alarm.snoozeDuration * 60)) let snoozeTime = Date().addingTimeInterval(TimeInterval(alarm.snoozeDuration * 60))
DebugLogger.log("Snooze time: \(snoozeTime)", category: .settings) Design.debugLog("[settings] Snooze time: \(snoozeTime)")
DebugLogger.log("Current time: \(Date())", category: .settings) Design.debugLog("[settings] Current time: \(Date())")
// Create a temporary alarm for the snooze // Create a temporary alarm for the snooze
let snoozeAlarm = Alarm( let snoozeAlarm = Alarm(
@ -114,11 +115,11 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
private func handleStopAction(userInfo: [AnyHashable: Any]) { private func handleStopAction(userInfo: [AnyHashable: Any]) {
guard let alarmIdString = userInfo["alarmId"] as? String, guard let alarmIdString = userInfo["alarmId"] as? String,
let alarmId = UUID(uuidString: alarmIdString) else { let alarmId = UUID(uuidString: alarmIdString) else {
DebugLogger.log("Could not find alarm ID for stop action", category: .general) Design.debugLog("[general] Could not find alarm ID for stop action")
return return
} }
DebugLogger.log("Stopping alarm: \(alarmId)", category: .settings) Design.debugLog("[settings] Stopping alarm: \(alarmId)")
// Cancel any pending notifications for this alarm // Cancel any pending notifications for this alarm
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [alarmIdString]) UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [alarmIdString])
@ -130,11 +131,11 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
private func handleNotificationTap(userInfo: [AnyHashable: Any]) { private func handleNotificationTap(userInfo: [AnyHashable: Any]) {
guard let alarmIdString = userInfo["alarmId"] as? String, guard let alarmIdString = userInfo["alarmId"] as? String,
let alarmId = UUID(uuidString: alarmIdString) else { let alarmId = UUID(uuidString: alarmIdString) else {
DebugLogger.log("Could not find alarm ID for notification tap", category: .general) Design.debugLog("[general] Could not find alarm ID for notification tap")
return return
} }
DebugLogger.log("Notification tapped for alarm: \(alarmId)", category: .settings) Design.debugLog("[settings] Notification tapped for alarm: \(alarmId)")
// For now, just log the tap. In the future, this could open the alarm details // For now, just log the tap. In the future, this could open the alarm details
// or perform some other action when the user taps the notification // or perform some other action when the user taps the notification
@ -171,9 +172,9 @@ class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
// Schedule notification // Schedule notification
do { do {
try await UNUserNotificationCenter.current().add(request) try await UNUserNotificationCenter.current().add(request)
DebugLogger.log("Snooze notification scheduled for \(snoozeAlarm.time)", category: .settings) Design.debugLog("[settings] Snooze notification scheduled for \(snoozeAlarm.time)")
} catch { } catch {
DebugLogger.log("Error scheduling snooze notification: \(error)", category: .general) Design.debugLog("[general] Error scheduling snooze notification: \(error)")
} }
} }
} }

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
import UserNotifications import UserNotifications
import Observation import Observation
import Bedrock
/// Service for managing system notifications /// Service for managing system notifications
@Observable @Observable
@ -30,7 +31,7 @@ class NotificationService {
isAuthorized = granted isAuthorized = granted
return granted return granted
} catch { } catch {
DebugLogger.log("Error requesting notification permissions: \(error)", category: .general) Design.debugLog("[general] Error requesting notification permissions: \(error)")
isAuthorized = false isAuthorized = false
return false return false
} }
@ -54,7 +55,7 @@ class NotificationService {
date: Date date: Date
) async -> Bool { ) async -> Bool {
guard isAuthorized else { guard isAuthorized else {
DebugLogger.log("Notifications not authorized", category: .settings) Design.debugLog("[settings] Notifications not authorized")
return false return false
} }

View File

@ -7,6 +7,7 @@
import SwiftUI import SwiftUI
import Observation import Observation
import Bedrock
/// Clock customization settings and data model /// Clock customization settings and data model
@Observable @Observable
@ -341,19 +342,19 @@ class ClockStyle: Codable, Equatable {
/// Get the effective brightness considering color theme and night mode /// Get the effective brightness considering color theme and night mode
var effectiveBrightness: Double { var effectiveBrightness: Double {
if !autoBrightness { if !autoBrightness {
DebugLogger.log("effectiveBrightness: Auto-brightness disabled, returning 1.0", category: .brightness) Design.debugLog("[brightness] effectiveBrightness: Auto-brightness disabled, returning 1.0")
return 1.0 // Full brightness when auto-brightness is disabled return 1.0 // Full brightness when auto-brightness is disabled
} }
if isNightModeActive { if isNightModeActive {
DebugLogger.log("effectiveBrightness: Night mode active, returning 0.3", category: .brightness) Design.debugLog("[brightness] effectiveBrightness: Night mode active, returning 0.3")
// Dim the display to 30% brightness in night mode // Dim the display to 30% brightness in night mode
return 0.3 return 0.3
} }
// Color-aware brightness adaptation // Color-aware brightness adaptation
let colorAwareBrightness = getColorAwareBrightness() let colorAwareBrightness = getColorAwareBrightness()
DebugLogger.log("effectiveBrightness: Color-aware brightness = \(String(format: "%.2f", colorAwareBrightness))", category: .brightness) Design.debugLog("[brightness] effectiveBrightness: Color-aware brightness = \(String(format: \"%.2f\", colorAwareBrightness))")
return colorAwareBrightness return colorAwareBrightness
} }

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
import UIKit import UIKit
import Observation import Observation
import Bedrock
/// Service for monitoring ambient light and managing brightness /// Service for monitoring ambient light and managing brightness
@Observable @Observable
@ -59,16 +60,16 @@ class AmbientLightService {
let clampedBrightness = max(0.0, min(1.0, brightness)) let clampedBrightness = max(0.0, min(1.0, brightness))
let previousBrightness = UIScreen.main.brightness let previousBrightness = UIScreen.main.brightness
DebugLogger.log("AmbientLightService.setBrightness:", category: .ambient) Design.debugLog("[ambient] AmbientLightService.setBrightness:")
DebugLogger.log(" - Requested brightness: \(String(format: "%.2f", brightness))", category: .ambient) Design.debugLog("[ambient] - Requested brightness: \(String(format: \"%.2f\", brightness))")
DebugLogger.log(" - Clamped brightness: \(String(format: "%.2f", clampedBrightness))", category: .ambient) Design.debugLog("[ambient] - Clamped brightness: \(String(format: \"%.2f\", clampedBrightness))")
DebugLogger.log(" - Previous screen brightness: \(String(format: "%.2f", previousBrightness))", category: .ambient) Design.debugLog("[ambient] - Previous screen brightness: \(String(format: \"%.2f\", previousBrightness))")
UIScreen.main.brightness = clampedBrightness UIScreen.main.brightness = clampedBrightness
currentBrightness = clampedBrightness currentBrightness = clampedBrightness
DebugLogger.log(" - New screen brightness: \(String(format: "%.2f", UIScreen.main.brightness))", category: .ambient) Design.debugLog("[ambient] - New screen brightness: \(String(format: \"%.2f\", UIScreen.main.brightness))")
DebugLogger.log(" - Service currentBrightness: \(String(format: "%.2f", currentBrightness))", category: .ambient) Design.debugLog("[ambient] - Service currentBrightness: \(String(format: \"%.2f\", currentBrightness))")
} }
/// Get current screen brightness /// Get current screen brightness
@ -89,7 +90,7 @@ class AmbientLightService {
let previousBrightness = currentBrightness let previousBrightness = currentBrightness
currentBrightness = newBrightness currentBrightness = newBrightness
DebugLogger.log("AmbientLightService: Brightness changed from \(String(format: "%.2f", previousBrightness)) to \(String(format: "%.2f", newBrightness))", category: .ambient) Design.debugLog("[ambient] AmbientLightService: Brightness changed from \(String(format: \"%.2f\", previousBrightness)) to \(String(format: \"%.2f\", newBrightness))")
// Notify that brightness changed // Notify that brightness changed
onBrightnessChange?() onBrightnessChange?()

View File

@ -202,7 +202,7 @@ class ClockViewModel {
// Set up callback to respond to brightness changes // Set up callback to respond to brightness changes
ambientLightService.onBrightnessChange = { [weak self] in ambientLightService.onBrightnessChange = { [weak self] in
DebugLogger.log("ClockViewModel: Received brightness change notification", category: .brightness) Design.debugLog("[brightness] ClockViewModel: Received brightness change notification")
self?.updateBrightness() self?.updateBrightness()
} }
} }
@ -219,21 +219,21 @@ class ClockViewModel {
let currentScreenBrightness = UIScreen.main.brightness let currentScreenBrightness = UIScreen.main.brightness
let isNightMode = style.isNightModeActive let isNightMode = style.isNightModeActive
DebugLogger.log("Auto Brightness Debug:", category: .brightness) Design.debugLog("[brightness] Auto Brightness Debug:")
DebugLogger.log(" - Auto brightness enabled: \(style.autoBrightness)", category: .brightness) Design.debugLog("[brightness] - Auto brightness enabled: \(style.autoBrightness)")
DebugLogger.log(" - Current screen brightness: \(String(format: "%.2f", currentScreenBrightness))", category: .brightness) Design.debugLog("[brightness] - Current screen brightness: \(String(format: \"%.2f\", currentScreenBrightness))")
DebugLogger.log(" - Target brightness: \(String(format: "%.2f", targetBrightness))", category: .brightness) Design.debugLog("[brightness] - Target brightness: \(String(format: \"%.2f\", targetBrightness))")
DebugLogger.log(" - Night mode active: \(isNightMode)", category: .brightness) Design.debugLog("[brightness] - Night mode active: \(isNightMode)")
DebugLogger.log(" - Color theme: \(style.selectedColorTheme)", category: .brightness) Design.debugLog("[brightness] - Color theme: \(style.selectedColorTheme)")
DebugLogger.log(" - Ambient light threshold: \(String(format: "%.2f", style.ambientLightThreshold))", category: .brightness) Design.debugLog("[brightness] - Ambient light threshold: \(String(format: \"%.2f\", style.ambientLightThreshold))")
ambientLightService.setBrightness(targetBrightness) ambientLightService.setBrightness(targetBrightness)
DebugLogger.log(" - Brightness set to: \(String(format: "%.2f", targetBrightness))", category: .brightness) Design.debugLog("[brightness] - Brightness set to: \(String(format: \"%.2f\", targetBrightness))")
DebugLogger.log(" - Actual screen brightness now: \(String(format: "%.2f", UIScreen.main.brightness))", category: .brightness) Design.debugLog("[brightness] - Actual screen brightness now: \(String(format: \"%.2f\", UIScreen.main.brightness))")
DebugLogger.log("---", category: .brightness) Design.debugLog("[brightness] ---")
} else { } else {
DebugLogger.log("Auto Brightness: DISABLED", category: .brightness) Design.debugLog("[brightness] Auto Brightness: DISABLED")
} }
} }
} }

View File

@ -1,37 +0,0 @@
//
// DebugLogger.swift
// TheNoiseClock
//
// Created by Matt Bruce on 9/10/25.
//
import Foundation
/// Debug logging utility that can be toggled with build settings
struct DebugLogger {
// MARK: - Log Categories
enum Category: String, CaseIterable {
case brightness = "BRIGHTNESS"
case ambient = "AMBIENT"
case nightMode = "NIGHTMODE"
case timer = "TIMER"
case settings = "SETTINGS"
case general = "DEBUG"
}
// MARK: - Build Configuration
#if DEBUG
private static let isDebugEnabled = true
#else
private static let isDebugEnabled = false
#endif
// MARK: - Logging Methods
/// Log debug messages (only in DEBUG builds)
static func log(_ message: String, category: Category = .general) {
guard isDebugEnabled else { return }
print("🔍 [\(category.rawValue)] \(message)")
}
}

View File

@ -7,6 +7,7 @@
import UserNotifications import UserNotifications
import Foundation import Foundation
import Bedrock
/// Notification helper functions /// Notification helper functions
enum NotificationUtils { enum NotificationUtils {
@ -20,7 +21,7 @@ enum NotificationUtils {
) )
return granted return granted
} catch { } catch {
DebugLogger.log("Error requesting notification permissions: \(error)", category: .general) Design.debugLog("[general] Error requesting notification permissions: \(error)")
return false return false
} }
} }
@ -38,12 +39,12 @@ enum NotificationUtils {
if soundName == "default" { if soundName == "default" {
content.sound = UNNotificationSound.default content.sound = UNNotificationSound.default
DebugLogger.log("Using default notification sound", category: .settings) Design.debugLog("[settings] Using default notification sound")
} else { } else {
// Use the sound name directly since sounds.json now references CAF files // Use the sound name directly since sounds.json now references CAF files
content.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: soundName)) content.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: soundName))
DebugLogger.log("Using custom alarm sound: \(soundName)", category: .settings) Design.debugLog("[settings] Using custom alarm sound: \(soundName)")
DebugLogger.log("Sound file should be in main bundle: \(soundName)", category: .settings) Design.debugLog("[settings] Sound file should be in main bundle: \(soundName)")
} }
return content return content
@ -74,7 +75,7 @@ enum NotificationUtils {
try await UNUserNotificationCenter.current().add(request) try await UNUserNotificationCenter.current().add(request)
return true return true
} catch { } catch {
DebugLogger.log("Error scheduling notification: \(error)", category: .general) Design.debugLog("[general] Error scheduling notification: \(error)")
return false return false
} }
} }