Files
CrossSound-Swift/Apps/iOS/CrossSoundWidget/AmbienceControlWidget.swift
RedLintu16andClaude Opus 5.5 64ec524ba0 CrossSound for Apple platforms
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-10-14 13:28:34 -07:00

41 lines
1.6 KiB
Swift
Executable File

// Control Center toggle for the rain layer (iOS 18+).
//
// ControlWidgetToggle renders its state from `isOn` and drives an
// AppIntent — here AmbienceControlIntent, which writes the App Group flag and
// posts a Darwin notification. The value it SHOWS comes from the same flag,
// so the control is correct even when the app is not running.
//
// What it cannot do: start audio in a cold app. An extension process has no
// audio session, so the intent records intent and a live app acts on it —
// which, since CrossSound is alive whenever anything is playing, covers the
// case you actually reach for this in.
#if canImport(ControlCenter) || true
import AppIntents
import CrossSoundBridge
import RedWhiteUI
import SwiftUI
import WidgetKit
@available(iOS 18.0, *)
struct AmbienceControlWidget: ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: "fi.RedLintu16.CrossSound.ambience") {
ControlWidgetToggle(
"CrossSound: Rain",
isOn: CrossSoundWidgetBridge.defaults?.bool(forKey: CrossSoundWidgetBridge.ambienceOnKey)
?? false,
action: AmbienceControlIntent()
) { isOn in
Label(isOn ? "Rain On" : "Rain Off", image: "custom.cloud")
}
// A control has no view tree to hang .rwTheme on, so the brand red
// comes straight from the palette token rather than a system colour.
.tint(RwPalette.light.red.color)
}
.displayName("CrossSound Rain")
.description("Play CrossSound's rain layer.")
}
}
#endif