Skip to content

Commit f5d96be

Browse files
authored
Merge pull request #243 from michaelbeaumont/fix/cancel-on-ui-exit
daemon: Cancel ceremony if UI disappears
2 parents 57dd042 + a1c44ca commit f5d96be

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Improvements
44

5+
- daemon: Cancel ceremony if UI disappears (Thank you, @michaelbeaumont!)
56
- daemon: Fix UI service failing to launch when started manually instead of via D-Bus activation.
67
- daemon: Allow Firefox to contact daemon on more distros with different app IDs (Thank you, @michaelbeaumont!)
78
- daemon: Fix all subsequent requests being rejected after the UI failed to launch.

‎credentialsd/src/dbus/ui_control.rs‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
497529
async fn subscribe_ui_events(
498530
connection: Connection,
499531
sender: OwnedUniqueName,

0 commit comments

Comments
 (0)