feat(media): include airplay for apple music on lock screen widget

This commit is contained in:
Amir Zarrinkafsh 2026-03-22 21:26:27 +11:00
commit 5e1e8f613b
No known key found for this signature in database
GPG key ID: ECDB8EF9E77E4EBF
3 changed files with 115 additions and 5 deletions

View file

@ -47,6 +47,8 @@ struct AirPlayDevice: Identifiable, Equatable {
@MainActor
final class AppleMusicAirPlayManager: ObservableObject {
static let shared = AppleMusicAirPlayManager()
@Published private(set) var devices: [AirPlayDevice] = []
@Published private(set) var isLoading = false
@ -136,6 +138,14 @@ final class AppleMusicAirPlayManager: ObservableObject {
// MARK: - Volume control
/// Returns the most recent volume the user set for a device, whether it's
/// still pending, already committed, or (as fallback) the last fetched value.
func currentVolume(for deviceID: String) -> Int {
if let pending = userSetVolume[deviceID] { return pending }
if let committed = lastCommittedVolume[deviceID] { return committed }
return devices.first { $0.id == deviceID }?.volume ?? 0
}
/// Called by the slider on every drag value change.
/// Does NOT mutate any @Published property — this is critical to prevent
/// SwiftUI from recreating the slider view and resetting its @State.