Skip to content

Commit

Permalink
Gracefully handle the lack of a session bus
Browse files Browse the repository at this point in the history
  • Loading branch information
DataTriny committed Dec 27, 2023
1 parent bac1e56 commit c8bf388
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions platforms/unix/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl AppContext {
}

pub(crate) struct ActivationContext {
_task: Task<()>,
_task: Option<Task<()>>,
adapters: Vec<(usize, LazyAdapter)>,
}

Expand All @@ -125,14 +125,15 @@ impl ActivationContext {
async fn get_or_init<'a>() -> AsyncMutexGuard<'a, ActivationContext> {
ACTIVATION_CONTEXT
.get_or_init(async {
let session_bus = Connection::session().await.unwrap();
let session_bus_copy = session_bus.clone();
let task = session_bus.executor().spawn(
async move {
listen(session_bus_copy).await.unwrap();
},
"accesskit_task",
);
let task = Connection::session().await.ok().map(|session_bus| {
let session_bus_copy = session_bus.clone();
session_bus.executor().spawn(
async move {
listen(session_bus_copy).await.unwrap();
},
"accesskit_task",
)
});
Arc::new(AsyncMutex::new(ActivationContext {
_task: task,
adapters: Vec::new(),
Expand Down

0 comments on commit c8bf388

Please sign in to comment.