@@ -466,7 +466,9 @@ impl Model {
466466 } ) ;
467467 }
468468
469- pipewire:: Event :: ActiveRoute ( _id, _index, _route) => { }
469+ pipewire:: Event :: ActiveRoute ( id, index, route) => {
470+ self . update_device_route ( & route, id) ;
471+ }
470472
471473 pipewire:: Event :: AddProfile ( id, profile) => {
472474 let profiles = self . device_profiles . entry ( id) . or_default ( ) ;
@@ -481,44 +483,7 @@ impl Model {
481483 }
482484
483485 pipewire:: Event :: AddRoute ( id, index, route) => {
484- match route. direction {
485- pipewire:: Direction :: Output => {
486- for ( pos, & node) in self . sink_node_ids . iter ( ) . enumerate ( ) {
487- let Some ( & device) = self . device_ids . get ( node) else {
488- continue ;
489- } ;
490-
491- if device != id {
492- continue ;
493- }
494-
495- if let Some ( node_name) = self . route_plug_check ( node, device, & route) {
496- self . sinks [ pos] = node_name;
497- }
498-
499- break ;
500- }
501- }
502-
503- pipewire:: Direction :: Input => {
504- for ( pos, & node) in self . source_node_ids . iter ( ) . enumerate ( ) {
505- let Some ( & device) = self . device_ids . get ( node) else {
506- continue ;
507- } ;
508-
509- if device != id {
510- continue ;
511- }
512-
513- if let Some ( node_name) = self . route_plug_check ( node, device, & route) {
514- self . sources [ pos] = node_name;
515- }
516-
517- break ;
518- }
519- }
520- }
521-
486+ self . update_device_route ( & route, id) ;
522487 let routes = self . device_routes . entry ( id) . or_default ( ) ;
523488 if routes. len ( ) < index as usize + 1 {
524489 let additional = ( index as usize + 1 ) - routes. capacity ( ) ;
@@ -679,6 +644,46 @@ impl Model {
679644 Some ( [ & port_name, " - " , device_name] . concat ( ) )
680645 }
681646
647+ fn update_device_route ( & mut self , route : & pipewire:: Route , id : DeviceId ) {
648+ match route. direction {
649+ pipewire:: Direction :: Output => {
650+ for ( pos, & node) in self . sink_node_ids . iter ( ) . enumerate ( ) {
651+ let Some ( & device) = self . device_ids . get ( node) else {
652+ continue ;
653+ } ;
654+
655+ if device != id {
656+ continue ;
657+ }
658+
659+ if let Some ( node_name) = self . route_plug_check ( node, device, & route) {
660+ self . sinks [ pos] = node_name;
661+ }
662+
663+ break ;
664+ }
665+ }
666+
667+ pipewire:: Direction :: Input => {
668+ for ( pos, & node) in self . source_node_ids . iter ( ) . enumerate ( ) {
669+ let Some ( & device) = self . device_ids . get ( node) else {
670+ continue ;
671+ } ;
672+
673+ if device != id {
674+ continue ;
675+ }
676+
677+ if let Some ( node_name) = self . route_plug_check ( node, device, & route) {
678+ self . sources [ pos] = node_name;
679+ }
680+
681+ break ;
682+ }
683+ }
684+ }
685+ }
686+
682687 fn translate_device_name ( & self , input : & str ) -> String {
683688 input
684689 . replace ( " Controller" , "" )
0 commit comments