refactor(instructions): UpdateSinkInput use channel and reduce nesting
This commit is contained in:
39
src/mixer.rs
39
src/mixer.rs
@@ -294,17 +294,38 @@ impl Mixer {
|
||||
muted: sink_input.mute,
|
||||
});
|
||||
});
|
||||
PulseInstruction::UpdateSinkInput(sink_index) => 'update_sink: {
|
||||
let Some(sink_input_mixer_data) = self.sink_inputs.get_mut(&sink_index)
|
||||
else {
|
||||
break 'update_sink;
|
||||
};
|
||||
|
||||
while operation.get_state() == pulse::operation::State::Running {
|
||||
iterate_mainloop(&mut self.mainloop);
|
||||
}
|
||||
let (new_sink_tx, new_sink_rx) = channel::<Option<SinkInputMixerData>>();
|
||||
let operation = self
|
||||
.context
|
||||
.borrow_mut()
|
||||
.introspect()
|
||||
.borrow_mut()
|
||||
.get_sink_input_info(sink_index, move |r| {
|
||||
let ListResult::Item(sink_input) = r else {
|
||||
let _ = new_sink_tx.send(None);
|
||||
return;
|
||||
};
|
||||
|
||||
let mut sink_input_lock = new_sink_input.lock().unwrap();
|
||||
if let Some(new_sink_input) = sink_input_lock.take() {
|
||||
*sink_input_mixer_data = new_sink_input;
|
||||
}
|
||||
}
|
||||
None => (),
|
||||
let _ = new_sink_tx.send(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,
|
||||
}));
|
||||
});
|
||||
|
||||
while operation.get_state() == pulse::operation::State::Running {
|
||||
iterate_mainloop(&mut self.mainloop);
|
||||
}
|
||||
|
||||
if let Some(new_sink_input) = new_sink_rx.recv().ok().flatten() {
|
||||
*sink_input_mixer_data = new_sink_input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user