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