From 100c336facb37ccac6f55cfab51066b7193b158c Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 21 Jul 2025 13:33:17 -0700 Subject: [PATCH] Add `dbus_connection()` method to `app::Application` trait This allows an application that wants to expose a DBus protocol to use the same session DBus connection, and provide a protocol on the same owned bus name. Without this, a Cosmic app using `single-instance` that wants to provide a DBus protocol must provide it on a bus name other than `APP_ID`. --- src/app/action.rs | 2 ++ src/app/cosmic.rs | 5 +++++ src/app/mod.rs | 8 ++++++++ src/dbus_activation.rs | 6 ++++++ 4 files changed, 21 insertions(+) diff --git a/src/app/action.rs b/src/app/action.rs index 0f05a6a6..cbdd1a55 100644 --- a/src/app/action.rs +++ b/src/app/action.rs @@ -22,6 +22,8 @@ pub enum Action { Close, /// Closes or shows the context drawer. ContextDrawer(bool), + #[cfg(feature = "single-instance")] + DbusConnection(zbus::Connection), /// Requests to drag the window. Drag, /// Window focus changed diff --git a/src/app/cosmic.rs b/src/app/cosmic.rs index f2de0f5e..cf5185ca 100644 --- a/src/app/cosmic.rs +++ b/src/app/cosmic.rs @@ -755,6 +755,11 @@ impl Cosmic { } } + #[cfg(feature = "single-instance")] + Action::DbusConnection(conn) => { + return self.app.dbus_connection(conn); + } + #[cfg(feature = "xdg-portal")] Action::DesktopSettings(crate::theme::portal::Desktop::ColorScheme(s)) => { use ashpd::desktop::settings::ColorScheme; diff --git a/src/app/mod.rs b/src/app/mod.rs index 890a3429..aaaa11a7 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -437,6 +437,14 @@ where fn dbus_activation(&mut self, msg: crate::dbus_activation::Message) -> Task { Task::none() } + + /// Invoked on connect to dbus session socket used for dbus activation + /// + /// Can be used to expose custom interfaces on the same owned name. + #[cfg(feature = "single-instance")] + fn dbus_connection(&mut self, conn: zbus::Connection) -> Task { + Task::none() + } } /// Methods automatically derived for all types implementing [`Application`]. diff --git a/src/dbus_activation.rs b/src/dbus_activation.rs index 9880a7d0..c8931dd4 100644 --- a/src/dbus_activation.rs +++ b/src/dbus_activation.rs @@ -44,6 +44,12 @@ pub fn subscription() -> Subscription