@@ -605,6 +605,37 @@ impl WidgetMachine {
605605 ) )
606606 }
607607
608+ /// Processes a response from the [`crate::widget::MatrixDriver`] saying
609+ /// that the widget is approved to acquire some capabilities. This will
610+ /// store those capabilities in the state machine and then notify the
611+ /// widget.
612+ fn process_acquired_capabilities (
613+ & mut self ,
614+ approved : Result < Capabilities , Error > ,
615+ requested : Capabilities ,
616+ ) -> Vec < Action > {
617+ let approved = approved. unwrap_or_else ( |e| {
618+ error ! ( "Acquiring capabilities failed: {e}" ) ;
619+ Capabilities :: default ( )
620+ } ) ;
621+
622+ let mut actions = Vec :: new ( ) ;
623+ if !approved. read . is_empty ( ) {
624+ actions. push ( Action :: Subscribe ) ;
625+ }
626+
627+ self . capabilities = CapabilitiesState :: Negotiated ( approved. clone ( ) ) ;
628+
629+ if let Some ( action) = self
630+ . send_to_widget_request ( NotifyCapabilitiesChanged { approved, requested } )
631+ . map ( |( _request, action) | action)
632+ {
633+ actions. push ( action) ;
634+ }
635+
636+ actions
637+ }
638+
608639 fn negotiate_capabilities ( & mut self ) -> Vec < Action > {
609640 let mut actions = Vec :: new ( ) ;
610641
@@ -630,33 +661,8 @@ impl WidgetMachine {
630661 } ;
631662
632663 request. then ( |result, machine| {
633- let approved_capabilities = result. unwrap_or_else ( |e| {
634- error ! ( "Acquiring capabilities failed: {e}" ) ;
635- Capabilities :: default ( )
636- } ) ;
637-
638- let mut actions = Vec :: new ( ) ;
639- if !approved_capabilities. read . is_empty ( ) {
640- actions. push ( Action :: Subscribe ) ;
641- }
642-
643- machine. capabilities = CapabilitiesState :: Negotiated ( approved_capabilities. clone ( ) ) ;
644-
645- let notify_caps_changed = NotifyCapabilitiesChanged {
646- approved : approved_capabilities,
647- requested : requested_capabilities,
648- } ;
649-
650- if let Some ( action) = machine
651- . send_to_widget_request ( notify_caps_changed)
652- . map ( |( _request, action) | action)
653- {
654- actions. push ( action) ;
655- }
656-
657- actions
664+ machine. process_acquired_capabilities ( result, requested_capabilities)
658665 } ) ;
659-
660666 vec ! [ action]
661667 } ) ;
662668
0 commit comments