@@ -26,7 +26,9 @@ use super::{
2626} ;
2727use crate :: {
2828 audio:: AudioPacketFormat ,
29- config:: { AppTheme , AudioFormat , ChannelCount , Config , ConnectionMode , SampleRate } ,
29+ config:: {
30+ AppTheme , AudioFormat , ChannelCount , Config , ConfigCache , ConnectionMode , SampleRate ,
31+ } ,
3032 fl,
3133 streamer:: { self , ConnectOption , StreamConfig , StreamerCommand , StreamerMsg } ,
3234 ui:: view:: { SCROLLABLE_ID , about_window} ,
@@ -115,6 +117,7 @@ pub struct AppState {
115117 core : Core ,
116118 pub streamer : Option < Sender < StreamerCommand > > ,
117119 pub config : ConfigManager < Config > ,
120+ pub config_cache : ConfigCache ,
118121 pub audio_host : Host ,
119122 pub audio_devices : Vec < AudioDevice > ,
120123 pub audio_device : Option < cpal:: Device > ,
@@ -142,13 +145,15 @@ impl AppState {
142145 return Task :: none ( ) ;
143146 }
144147 let ( producer, consumer) = RingBuffer :: < u8 > :: new ( self . get_shared_buf_size ( ) ) ;
148+ let config = self . config . data ( ) . clone ( ) ;
145149
146150 match self . start_audio_stream ( consumer) {
147151 Ok ( audio_config) => {
148152 self . send_command ( StreamerCommand :: ReconfigureStream ( StreamConfig {
149153 buff : producer,
150154 audio_config,
151- denoise : self . config . data ( ) . denoise ,
155+ denoise : config. denoise ,
156+ amplify : config. amplify . then_some ( config. amplify_value ) ,
152157 } ) ) ;
153158 Task :: none ( )
154159 }
@@ -209,7 +214,8 @@ impl AppState {
209214 StreamConfig {
210215 buff : producer,
211216 audio_config,
212- denoise : self . config . data ( ) . denoise ,
217+ denoise : config. denoise ,
218+ amplify : config. amplify . then_some ( config. amplify_value ) ,
213219 } ,
214220 ) ) ;
215221
@@ -294,6 +300,7 @@ impl Application for AppState {
294300 core,
295301 audio_stream : None ,
296302 streamer : None ,
303+ config_cache : ConfigCache :: new ( flags. config . data ( ) ) ,
297304 config : flags. config ,
298305 audio_device,
299306 audio_host,
@@ -455,7 +462,6 @@ impl Application for AppState {
455462 }
456463 ConfigMsg :: DeNoise ( denoise) => {
457464 self . config . update ( |c| c. denoise = denoise) ;
458- info ! ( "set denoise: {denoise}" ) ;
459465 return self . update_audio_stream ( ) ;
460466 }
461467 ConfigMsg :: Theme ( app_theme) => {
@@ -488,6 +494,18 @@ impl Application for AppState {
488494 . chain ( set_window_title) ;
489495 }
490496 } ,
497+ ConfigMsg :: Amplify ( amplify) => {
498+ self . config . update ( |c| c. amplify = amplify) ;
499+ return self . update_audio_stream ( ) ;
500+ }
501+ ConfigMsg :: AmplifyValue ( amplify_value) => {
502+ self . config_cache . amplify_value = amplify_value;
503+
504+ if let Some ( value) = self . config_cache . parse_amplify_value ( ) {
505+ self . config . update ( |c| c. amplify_value = value) ;
506+ return self . update_audio_stream ( ) ;
507+ }
508+ }
491509 } ,
492510 AppMsg :: Shutdown => {
493511 return cosmic:: iced_runtime:: task:: effect ( Action :: Exit ) ;
0 commit comments