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

This commit is contained in:
Matt Bruce 2026-02-02 13:20:19 -06:00
parent 5e45be0a2a
commit f3c98cedb9
2 changed files with 34 additions and 60 deletions

View File

@ -5,6 +5,7 @@
// Created by Matt Bruce on 2/2/26. // Created by Matt Bruce on 2/2/26.
// //
import ActivityKit
import AlarmKit import AlarmKit
import Bedrock import Bedrock
import Foundation import Foundation
@ -81,30 +82,20 @@ final class AlarmKitService {
} }
} }
// Create the sound for the alarm // Create the stop button for the alarm
let alarmSound = createAlarmSound(for: alarm)
Design.debugLog("[alarmkit] Created alarm sound: \(alarmSound)")
// Create the alert presentation with stop button and sound
let stopButton = AlarmButton( let stopButton = AlarmButton(
text: "Stop", text: "Stop",
textColor: .red, textColor: .red,
systemImageName: "stop.fill" systemImageName: "stop.fill"
) )
Design.debugLog("[alarmkit] Created stop button")
let snoozeButton = AlarmButton( // Create the alert presentation (sound is in AlarmConfiguration, not here)
text: "Snooze",
textColor: .blue,
systemImageName: "zzz"
)
let alert = AlarmPresentation.Alert( let alert = AlarmPresentation.Alert(
title: LocalizedStringResource(stringLiteral: alarm.label), title: LocalizedStringResource(stringLiteral: alarm.label),
sound: alarmSound, stopButton: stopButton
stopButton: stopButton,
snoozeButton: snoozeButton
) )
Design.debugLog("[alarmkit] Created alert with sound and buttons") Design.debugLog("[alarmkit] Created alert presentation")
// Create metadata for the alarm // Create metadata for the alarm
let metadata = NoiseClockAlarmMetadata( let metadata = NoiseClockAlarmMetadata(
@ -114,7 +105,7 @@ final class AlarmKitService {
label: alarm.label, label: alarm.label,
volume: alarm.volume volume: alarm.volume
) )
Design.debugLog("[alarmkit] Created metadata: \(metadata)") Design.debugLog("[alarmkit] Created metadata: alarmId=\(metadata.alarmId), sound=\(metadata.soundName)")
// Create alarm attributes // Create alarm attributes
let attributes = AlarmAttributes<NoiseClockAlarmMetadata>( let attributes = AlarmAttributes<NoiseClockAlarmMetadata>(
@ -124,9 +115,9 @@ final class AlarmKitService {
) )
Design.debugLog("[alarmkit] Created attributes with tint color") Design.debugLog("[alarmkit] Created attributes with tint color")
// Create the schedule // Create the schedule - use fixed date for one-time alarms
let schedule = createSchedule(for: alarm) let schedule = createSchedule(for: alarm)
Design.debugLog("[alarmkit] Created schedule: \(schedule)") Design.debugLog("[alarmkit] Created schedule")
// Create countdown duration (5 min before alarm, 1 min after) // Create countdown duration (5 min before alarm, 1 min after)
let countdownDuration = AlarmKit.Alarm.CountdownDuration( let countdownDuration = AlarmKit.Alarm.CountdownDuration(
@ -135,13 +126,19 @@ final class AlarmKitService {
) )
Design.debugLog("[alarmkit] Countdown duration: preAlert=300s, postAlert=60s") Design.debugLog("[alarmkit] Countdown duration: preAlert=300s, postAlert=60s")
// Create the alarm configuration // Create the sound
let soundName = getSoundNameForAlarmKit(alarm.soundName)
let alarmSound = AlertConfiguration.AlertSound.named(soundName)
Design.debugLog("[alarmkit] Created sound: \(soundName)")
// Create the alarm configuration with sound
let configuration = AlarmManager.AlarmConfiguration<NoiseClockAlarmMetadata>( let configuration = AlarmManager.AlarmConfiguration<NoiseClockAlarmMetadata>(
countdownDuration: countdownDuration, countdownDuration: countdownDuration,
schedule: schedule, schedule: schedule,
attributes: attributes attributes: attributes,
sound: alarmSound
) )
Design.debugLog("[alarmkit] Created configuration") Design.debugLog("[alarmkit] Created configuration with sound")
// Schedule the alarm // Schedule the alarm
do { do {
@ -160,22 +157,12 @@ final class AlarmKitService {
// MARK: - Sound Configuration // MARK: - Sound Configuration
/// Create an AlarmKit sound from the alarm's sound name. /// Get the sound name for AlarmKit (without extension)
private func createAlarmSound(for alarm: Alarm) -> AlarmKit.AlertSound { private func getSoundNameForAlarmKit(_ soundName: String) -> String {
let soundName = alarm.soundName // AlarmKit expects the sound name without extension
Design.debugLog("[alarmkit] Creating sound for: \(soundName)") let nameWithoutExtension = (soundName as NSString).deletingPathExtension
Design.debugLog("[alarmkit] Sound name for AlarmKit: \(nameWithoutExtension) (from: \(soundName))")
// Check if it's a bundled sound file (has extension) return nameWithoutExtension
if soundName.contains(".") {
// Extract filename without extension for named sound
let soundFileName = soundName
Design.debugLog("[alarmkit] Using named sound file: \(soundFileName)")
return .named(soundFileName)
} else {
// Assume it's a named sound resource
Design.debugLog("[alarmkit] Using named sound: \(soundName)")
return .named(soundName)
}
} }
/// Cancel a scheduled alarm. /// Cancel a scheduled alarm.
@ -240,30 +227,17 @@ final class AlarmKitService {
/// Create an AlarmKit schedule from an Alarm model. /// Create an AlarmKit schedule from an Alarm model.
private func createSchedule(for alarm: Alarm) -> AlarmKit.Alarm.Schedule { private func createSchedule(for alarm: Alarm) -> AlarmKit.Alarm.Schedule {
// Extract time components // Calculate the next trigger time
let calendar = Calendar.current let triggerDate = alarm.nextTriggerTime()
let components = calendar.dateComponents([.hour, .minute], from: alarm.time)
let hour = components.hour ?? 0 Design.debugLog("[alarmkit] Creating schedule for: \(triggerDate)")
let minute = components.minute ?? 0 Design.debugLog("[alarmkit] Current time: \(Date.now)")
Design.debugLog("[alarmkit] Time until alarm: \(triggerDate.timeIntervalSinceNow) seconds")
Design.debugLog("[alarmkit] Creating schedule for \(hour):\(String(format: "%02d", minute))") // Use fixed schedule for one-time alarms
let schedule = AlarmKit.Alarm.Schedule.fixed(triggerDate)
let time = AlarmKit.Alarm.Schedule.Relative.Time( Design.debugLog("[alarmkit] Schedule created: fixed at \(triggerDate)")
hour: hour,
minute: minute
)
// For now, create a one-time alarm (non-repeating)
// Future: Support weekly repeating alarms based on alarm.repeatDays
let schedule = AlarmKit.Alarm.Schedule.relative(
AlarmKit.Alarm.Schedule.Relative(
time: time,
repeats: .never
)
)
Design.debugLog("[alarmkit] Schedule created: relative, repeats=never")
return schedule return schedule
} }
} }

View File

@ -14,9 +14,9 @@ import Bedrock
class ClockStyle: Codable, Equatable { class ClockStyle: Codable, Equatable {
// MARK: - Time Format Settings // MARK: - Time Format Settings
var use24Hour: Bool = true var use24Hour: Bool = false
var showSeconds: Bool = false var showSeconds: Bool = false
var showAmPm: Bool = true var showAmPm: Bool = false
var forceHorizontalMode: Bool = false // Force horizontal layout even in portrait var forceHorizontalMode: Bool = false // Force horizontal layout even in portrait
// MARK: - Visual Settings // MARK: - Visual Settings