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