🚧 Volume updating

This commit is contained in:
Lucy 2022-04-07 15:21:15 -04:00
parent 57b44a35d5
commit 73d2401ed3
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
3 changed files with 10 additions and 13 deletions

View file

@ -10,7 +10,7 @@ fn get_inputs() -> Vec<DeviceInfo> {
.expect("failed to list input devices")
}
pub fn refresh_default_input(label: &Label) {
pub fn refresh_default_input(label: &Label) -> DeviceInfo {
let default_input = SourceController::create()
.expect("failed to create input controller")
.get_default_device()
@ -19,6 +19,7 @@ pub fn refresh_default_input(label: &Label) {
Some(name) => name.as_str(),
None => "Input Device",
});
default_input
}
pub fn refresh_input_widgets(inputs: &ListBox) {

View file

@ -85,7 +85,6 @@ fn app(application: &Application) {
set_format_value_func: |_, value| {
format!("{:.0}%", value)
},
//set_value: watch! { model.default_output.as_ref().map(|info| (info.volume.avg().0 as f64 / Volume::NORMAL.0 as f64) * 100.).unwrap_or(0.) },
set_value_pos: PositionType::Right,
set_hexpand: true
}
@ -100,12 +99,6 @@ fn app(application: &Application) {
set_format_value_func: |_, value| {
format!("{:.0}%", value)
},
/*set_value: watch! {
model.default_input
.as_ref()
.map(|info| (info.volume.avg().0 as f64 / Volume::NORMAL.0 as f64) * 100.)
.unwrap_or(0.)
},*/
set_value_pos: PositionType::Right,
set_hexpand: true
}
@ -159,17 +152,19 @@ fn app(application: &Application) {
}
refresh_input_rx.attach(
None,
clone!(@weak inputs, @weak current_input => @default-return Continue(true), move |_| {
clone!(@weak inputs, @weak current_input, @weak input_volume => @default-return Continue(true), move |_| {
input::refresh_input_widgets(&inputs);
input::refresh_default_input(&current_input);
let default_input = input::refresh_default_input(&current_input);
volume::update_volume(&default_input, &input_volume);
Continue(true)
}),
);
refresh_output_rx.attach(
None,
clone!(@weak outputs, @weak current_output => @default-return Continue(true), move |_| {
clone!(@weak outputs, @weak current_output, @weak output_volume => @default-return Continue(true), move |_| {
output::refresh_output_widgets(&outputs);
output::refresh_default_input(&current_output);
let default_output = output::refresh_default_output(&current_output);
volume::update_volume(&default_output, &output_volume);
Continue(true)
}),
);

View file

@ -10,7 +10,7 @@ fn get_outputs() -> Vec<DeviceInfo> {
.expect("failed to list output devices")
}
pub fn refresh_default_input(label: &Label) {
pub fn refresh_default_output(label: &Label) -> DeviceInfo {
let default_output = SinkController::create()
.expect("failed to create output controller")
.get_default_device()
@ -19,6 +19,7 @@ pub fn refresh_default_input(label: &Label) {
Some(name) => name.as_str(),
None => "Output Device",
});
default_output
}
pub fn refresh_output_widgets(outputs: &ListBox) {