Remap buttons mutual exclusivity

This commit is contained in:
Hariharan Mudaliar 2025-11-18 02:56:07 +05:30
commit 9d4c99e713
3 changed files with 73 additions and 8 deletions

View file

@ -857,6 +857,8 @@ struct Media: View {
@Default(.showShuffleAndRepeat) private var showShuffleAndRepeat
@Default(.musicAuxLeftControl) private var musicAuxLeftControl
@Default(.musicAuxRightControl) private var musicAuxRightControl
@State private var previousLeftAuxControl: MusicAuxiliaryControl = Defaults[.musicAuxLeftControl]
@State private var previousRightAuxControl: MusicAuxiliaryControl = Defaults[.musicAuxRightControl]
var body: some View {
Form {
@ -969,6 +971,42 @@ struct Media: View {
Defaults[.enableFullscreenMediaDetection] = hideNotchOption != .never
}
}
.onAppear {
ensureAuxControlsUnique()
previousLeftAuxControl = musicAuxLeftControl
previousRightAuxControl = musicAuxRightControl
}
.onChange(of: musicAuxLeftControl) { newValue in
if newValue == musicAuxRightControl {
let fallback = MusicAuxiliaryControl.alternative(
excluding: newValue,
preferring: previousLeftAuxControl
)
if fallback != musicAuxRightControl {
musicAuxRightControl = fallback
}
}
previousLeftAuxControl = newValue
}
.onChange(of: musicAuxRightControl) { newValue in
if newValue == musicAuxLeftControl {
let fallback = MusicAuxiliaryControl.alternative(
excluding: newValue,
preferring: previousRightAuxControl
)
if fallback != musicAuxLeftControl {
musicAuxLeftControl = fallback
}
}
previousRightAuxControl = newValue
}
.onChange(of: showShuffleAndRepeat) { isEnabled in
if isEnabled {
ensureAuxControlsUnique()
}
}
.navigationTitle("Media")
}
@ -980,6 +1018,15 @@ struct Media: View {
return MediaControllerType.allCases
}
}
private func ensureAuxControlsUnique() {
guard showShuffleAndRepeat, musicAuxLeftControl == musicAuxRightControl else { return }
let fallback = MusicAuxiliaryControl.alternative(excluding: musicAuxLeftControl)
if fallback != musicAuxRightControl {
musicAuxRightControl = fallback
}
}
}
struct CalendarSettings: View {