aboutsummaryrefslogtreecommitdiff
path: root/pulse/src/runnable/mod.rs
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2021-11-28 23:08:50 +0100
committerAndreas Grois <andi@grois.info>2021-11-28 23:09:09 +0100
commita0457a3d4dcbf1060dbad850a915a3466575f665 (patch)
tree644b1d789f85a6976812ef04ca71f4819ec6fbfb /pulse/src/runnable/mod.rs
parentccfe9a7893c54c65246963ee27be31a13d3c2e92 (diff)
Implement working binning and sorting for pulse audio.
Diffstat (limited to 'pulse/src/runnable/mod.rs')
-rw-r--r--pulse/src/runnable/mod.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/pulse/src/runnable/mod.rs b/pulse/src/runnable/mod.rs
index 352a10a..bb2456b 100644
--- a/pulse/src/runnable/mod.rs
+++ b/pulse/src/runnable/mod.rs
@@ -31,12 +31,20 @@ impl<'p : 's, 's> PulseVolumeRunnable<'p> {
self.to_main.send_update(Err(PluginError::PrintToStdErr(err.to_string()))).expect("Tried to tell main thread that an error occured. Main thread isn't listening any more.");
}
- fn send_updated_volume_to_main(&self, volume : &pulse::Volume) -> Result<(),PluginCommunicationError> {
- self.to_main.send_update(Ok(self.format_volume(volume)))
- }
-
- fn format_volume(&self, volume : &pulse::Volume) -> String {
- format!("{}",volume.volume)
+ fn format_and_send_updated_volume_to_main(&self, volume : &pulse::Volume) -> Result<(),PluginCommunicationError> {
+ let formatted_volume = self.config.format_volume(volume.volume, volume.balance, volume.muted);
+ match formatted_volume {
+ Ok(msg) => { self.to_main.send_update(Ok(msg)) }
+ Err(e) => {
+ let full_message = e.to_string();
+ match e {
+ FormattingError::EmptyMap{ numeric_fallback } => {
+ self.to_main.send_update(Err(PluginError::ShowInsteadOfText(numeric_fallback)))?;
+ self.to_main.send_update(Err(PluginError::PrintToStdErr(full_message)))
+ }
+ }
+ }
+ }
}
}
@@ -140,7 +148,7 @@ impl<'p> SwayStatusModuleRunnable for PulseVolumeRunnable<'p> {
}
if volume.is_some() && volume != curr_volume {
curr_volume = volume;
- self.send_updated_volume_to_main(curr_volume.as_ref().unwrap()).expect("Tried to inform main thread about volume update. Main thread isn't listening.");
+ self.format_and_send_updated_volume_to_main(curr_volume.as_ref().unwrap()).expect("Tried to inform main thread about volume update. Main thread isn't listening.");
}
match self.from_main.try_recv() {
Ok(x) => match x {