Skip to content

Commit b8eaad2

Browse files
authored
feat: add dbus_connection() method to app::Application trait
1 parent 38dde24 commit b8eaad2

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

src/app/action.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub enum Action {
2222
Close,
2323
/// Closes or shows the context drawer.
2424
ContextDrawer(bool),
25+
#[cfg(feature = "single-instance")]
26+
DbusConnection(zbus::Connection),
2527
/// Requests to drag the window.
2628
Drag,
2729
/// Window focus changed

src/app/cosmic.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,11 @@ impl<T: Application> Cosmic<T> {
761761
}
762762
}
763763

764+
#[cfg(feature = "single-instance")]
765+
Action::DbusConnection(conn) => {
766+
return self.app.dbus_connection(conn);
767+
}
768+
764769
#[cfg(feature = "xdg-portal")]
765770
Action::DesktopSettings(crate::theme::portal::Desktop::ColorScheme(s)) => {
766771
use ashpd::desktop::settings::ColorScheme;

src/app/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,14 @@ where
437437
fn dbus_activation(&mut self, msg: crate::dbus_activation::Message) -> Task<Self::Message> {
438438
Task::none()
439439
}
440+
441+
/// Invoked on connect to dbus session socket used for dbus activation
442+
///
443+
/// Can be used to expose custom interfaces on the same owned name.
444+
#[cfg(feature = "single-instance")]
445+
fn dbus_connection(&mut self, conn: zbus::Connection) -> Task<Self::Message> {
446+
Task::none()
447+
}
440448
}
441449

442450
/// Methods automatically derived for all types implementing [`Application`].

src/dbus_activation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ pub fn subscription<App: ApplicationExt>() -> Subscription<crate::Action<App::Me
4444
std::process::exit(1);
4545
}
4646

47+
output
48+
.send(crate::Action::Cosmic(crate::app::Action::DbusConnection(
49+
conn.clone(),
50+
)))
51+
.await;
52+
4753
#[cfg(feature = "smol")]
4854
let handle = {
4955
std::thread::spawn(move || {

0 commit comments

Comments
 (0)