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,
|
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 {
|
let (new_sink_tx, new_sink_rx) = channel::<Option<SinkInputMixerData>>();
|
||||||
iterate_mainloop(&mut self.mainloop);
|
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();
|
let _ = new_sink_tx.send(Some(SinkInputMixerData {
|
||||||
if let Some(new_sink_input) = sink_input_lock.take() {
|
name: get_sink_input_name(&sink_input).unwrap(),
|
||||||
*sink_input_mixer_data = new_sink_input;
|
volume: sink_input.volume.avg().0,
|
||||||
}
|
channels: sink_input.volume.len(),
|
||||||
}
|
muted: sink_input.mute,
|
||||||
None => (),
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
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