@@ -30,6 +30,19 @@ import {
30
30
Gio . _promisify ( GdkPixbuf . Pixbuf , "new_from_stream_async" , "new_from_stream_finish" ) ;
31
31
Gio . _promisify ( Gio . File . prototype , "query_info_async" , "query_info_finish" ) ;
32
32
33
+ function find_child_by_name ( parent : Clutter . Actor | Clutter . Container , name : string ) {
34
+ if ( Clutter . Container === undefined ) {
35
+ const children = ( parent as Clutter . Actor ) . get_children ( ) ;
36
+ for ( const child of children ) {
37
+ if ( child . get_name ( ) === name ) {
38
+ return child ;
39
+ }
40
+ }
41
+ } else {
42
+ return parent . find_child_by_name ( name ) ;
43
+ }
44
+ }
45
+
33
46
class PanelButton extends PanelMenu . Button {
34
47
private playerProxy : PlayerProxy ;
35
48
private extension : MediaControls ;
@@ -568,7 +581,7 @@ class PanelButton extends PanelMenu.Button {
568
581
tapAction . connect ( "tap" , onClick ) ;
569
582
icon . add_action ( tapAction ) ;
570
583
571
- const oldIcon = this . menuControls . get_child_at_index ( options . menuProps . index ) ;
584
+ const oldIcon = find_child_by_name ( this . menuControls , options . name ) ;
572
585
573
586
if ( oldIcon ?. get_parent ( ) === this . menuControls ) {
574
587
this . menuControls . replace_child ( oldIcon , icon ) ;
@@ -716,7 +729,7 @@ class PanelButton extends PanelMenu.Button {
716
729
717
730
icon . add_action ( tapAction ) ;
718
731
719
- const oldIcon = this . buttonControls . get_child_at_index ( options . panelProps . index ) ;
732
+ const oldIcon = find_child_by_name ( this . buttonControls , options . name ) ;
720
733
721
734
if ( oldIcon != null ) {
722
735
this . buttonControls . replace_child ( oldIcon , icon ) ;
@@ -726,8 +739,7 @@ class PanelButton extends PanelMenu.Button {
726
739
}
727
740
728
741
private removeButtonControlIcon ( options : ControlIconOptions ) {
729
- // @ts -expect-error typing error
730
- const icon = this . buttonControls . get_child_at_index ( options . menuProps . index ) ;
742
+ const icon = find_child_by_name ( this . buttonControls , options . name ) ;
731
743
732
744
if ( icon != null ) {
733
745
this . buttonControls . remove_child ( icon ) ;
0 commit comments