fix(instructions): RemoveSinkInput switches selection sometimes

This commit is contained in:
2024-10-06 04:16:19 +02:00
parent c9f4341587
commit 696ab0a089

View File

@@ -243,57 +243,31 @@ impl Mixer {
} }
} }
} }
PulseInstruction::RemoveSinkInput(sink_index) => { PulseInstruction::RemoveSinkInput(sink_index) => 'remove_sink: {
let selected_index_lock = self.selected_index.lock().unwrap(); let selected_index_lock = self.selected_index.lock().unwrap();
match *selected_index_lock { let Some(selected_index) = *selected_index_lock else {
Some(current_index) => { break 'remove_sink;
drop(selected_index_lock); };
if let Some(removed_sink_input_index) = drop(selected_index_lock);
self.sink_inputs.keys().position(|k| *k == sink_index)
{
let current_key =
*self.sink_inputs.keys().nth(current_index).unwrap();
if self.sink_inputs.remove(&sink_index).is_some() { let Some(removed_sink_input_index) =
if sink_index == current_key self.sink_inputs.keys().position(|k| *k == sink_index)
|| removed_sink_input_index > current_index else {
{ break 'remove_sink;
self.select_previous(); };
}
} let current_key = *self.sink_inputs.keys().nth(selected_index).unwrap();
}
if self.sink_inputs.remove(&sink_index).is_some() {
if sink_index == current_key
|| removed_sink_input_index <= selected_index
{
self.select_previous();
} }
None => (),
} }
} }
PulseInstruction::UpdateSinkInput(sink_index) => {
match self.sink_inputs.get_mut(&sink_index) {
Some(sink_input_mixer_data) => {
let new_sink_input: Arc<Mutex<Option<SinkInputMixerData>>> =
Arc::new(Mutex::new(None));
let callback_new_sink_input = new_sink_input.clone();
let operation = self
.context
.borrow_mut()
.introspect()
.borrow_mut()
.get_sink_input_info(sink_index, move |r| {
let ListResult::Item(sink_input) = r else {
return;
};
*callback_new_sink_input.lock().unwrap() =
Some(SinkInputMixerData {
name: get_sink_input_name(&sink_input).unwrap(),
volume: sink_input.volume.avg().0,
channels: sink_input.volume.len(),
muted: sink_input.mute,
});
});
PulseInstruction::UpdateSinkInput(sink_index) => 'update_sink: { PulseInstruction::UpdateSinkInput(sink_index) => 'update_sink: {
let Some(sink_input_mixer_data) = self.sink_inputs.get_mut(&sink_index) let Some(sink_input_mixer_data) = self.sink_inputs.get_mut(&sink_index)
else { else {