@@ -657,6 +657,37 @@ impl WidgetMachine {
657657 ) )
658658 }
659659
660+ /// Processes a response from the [`crate::widget::MatrixDriver`] saying
661+ /// that the widget is approved to acquire some capabilities. This will
662+ /// store those capabilities in the state machine and then notify the
663+ /// widget.
664+ fn process_acquired_capabilities (
665+ & mut self ,
666+ approved : Result < Capabilities , Error > ,
667+ requested : Capabilities ,
668+ ) -> Vec < Action > {
669+ let approved = approved. unwrap_or_else ( |e| {
670+ error ! ( "Acquiring capabilities failed: {e}" ) ;
671+ Capabilities :: default ( )
672+ } ) ;
673+
674+ let mut actions = Vec :: new ( ) ;
675+ if !approved. read . is_empty ( ) {
676+ actions. push ( Action :: Subscribe ) ;
677+ }
678+
679+ self . capabilities = CapabilitiesState :: Negotiated ( approved. clone ( ) ) ;
680+
681+ if let Some ( action) = self
682+ . send_to_widget_request ( NotifyCapabilitiesChanged { approved, requested } )
683+ . map ( |( _request, action) | action)
684+ {
685+ actions. push ( action) ;
686+ }
687+
688+ actions
689+ }
690+
660691 fn negotiate_capabilities ( & mut self ) -> Vec < Action > {
661692 let mut actions = Vec :: new ( ) ;
662693
@@ -682,33 +713,8 @@ impl WidgetMachine {
682713 } ;
683714
684715 request. add_response_handler ( |result, machine| {
685- let approved_capabilities = result. unwrap_or_else ( |e| {
686- error ! ( "Acquiring capabilities failed: {e}" ) ;
687- Capabilities :: default ( )
688- } ) ;
689-
690- let mut actions = Vec :: new ( ) ;
691- if !approved_capabilities. read . is_empty ( ) {
692- actions. push ( Action :: Subscribe ) ;
693- }
694-
695- machine. capabilities = CapabilitiesState :: Negotiated ( approved_capabilities. clone ( ) ) ;
696-
697- let notify_caps_changed = NotifyCapabilitiesChanged {
698- approved : approved_capabilities,
699- requested : requested_capabilities,
700- } ;
701-
702- if let Some ( action) = machine
703- . send_to_widget_request ( notify_caps_changed)
704- . map ( |( _request, action) | action)
705- {
706- actions. push ( action) ;
707- }
708-
709- actions
716+ machine. process_acquired_capabilities ( result, requested_capabilities)
710717 } ) ;
711-
712718 vec ! [ action]
713719 } ) ;
714720
0 commit comments