@@ -467,12 +467,22 @@ impl UiController for UiControlServiceClient {
467467 } ;
468468 subscribe_ui_events (
469469 self . conn . clone ( ) ,
470- sender,
470+ sender. clone ( ) ,
471471 session_handle. clone ( ) ,
472- from_ui_tx,
472+ from_ui_tx. clone ( ) ,
473473 )
474474 . await ?;
475475
476+ // We want to know when this specific peer disconnects
477+ let peer = zbus:: proxy:: Builder :: < zbus:: Proxy > :: new ( & self . conn )
478+ . destination ( sender) ?
479+ . path ( backend_proxy. as_ref ( ) . path ( ) ) ?
480+ . interface ( backend_proxy. as_ref ( ) . interface ( ) ) ?
481+ . build ( )
482+ . await ?;
483+ let owner_changes = peer. receive_owner_changed ( ) . await ?;
484+ watch_ui_exit ( owner_changes, session_handle. clone ( ) , from_ui_tx) ;
485+
476486 backend_proxy
477487 . create_session (
478488 session_handle. as_ref ( ) ,
@@ -494,6 +504,28 @@ impl UiController for UiControlServiceClient {
494504 }
495505}
496506
507+ fn watch_ui_exit (
508+ owner_changes : proxy:: OwnerChangedStream < ' static > ,
509+ session_handle : OwnedObjectPath ,
510+ tx : mpsc:: Sender < UserInteractedEvent > ,
511+ ) {
512+ tokio:: spawn ( async move {
513+ let mut owner_changes = Box :: pin ( owner_changes) ;
514+ while let Some ( owner) = tokio:: select! {
515+ // Nothing is listening for ceremony events any more
516+ _ = tx. closed( ) => None ,
517+ owner = owner_changes. next( ) => owner,
518+ } {
519+ // A well-known name yields `None` once it is released.
520+ if owner. is_none ( ) {
521+ tracing:: debug!( session_handle = %session_handle, "UI left the bus, cancelling request" ) ;
522+ _ = tx. send ( UserInteractedEvent :: RequestCancelled ) . await ;
523+ return ;
524+ }
525+ }
526+ } ) ;
527+ }
528+
497529async fn subscribe_ui_events (
498530 connection : Connection ,
499531 sender : OwnedUniqueName ,
0 commit comments