Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/vibepanel/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
//! - **sleep_watcher**: Shared resume-from-sleep notifications via logind
//! - **weather**: Open-Meteo-backed weather and forecast data

mod wayland;
pub use wayland::{activation, background_effect};

pub mod audio;
pub mod background_effect;
pub mod bar_manager;
pub mod battery;
pub mod battery_alert;
Expand Down
40 changes: 39 additions & 1 deletion crates/vibepanel/src/services/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const NOTIFICATIONS_XML: &str = r#"
<arg name="id" type="u"/>
<arg name="action_key" type="s"/>
</signal>
<signal name="ActivationToken">
<arg name="id" type="u"/>
<arg name="activation_token" type="s"/>
</signal>
</interface>
<interface name="io.github.vibepanel.Notifications1">
<method name="GetUnreadCount">
Expand Down Expand Up @@ -249,6 +253,9 @@ impl NotificationService {
ready: Cell::new(false),
});

// Initialize the xdg-activation token service used by the
// notifications ActivationToken D-Bus signal.
super::activation::ActivationService::init_global();
Self::init_dbus(&service);
service
}
Expand Down Expand Up @@ -465,6 +472,10 @@ impl NotificationService {
return;
}

if let Some(token) = Self::create_activation_token() {
self.emit_activation_token(id, &token);
}

self.emit_action_invoked(id, action_key);

// Close the notification after action is invoked (common behavior)
Expand Down Expand Up @@ -880,7 +891,7 @@ impl NotificationService {
"vibepanel", // name
"vibepanel", // vendor
"1.0", // version
"1.2", // spec version
"1.2", // Desktop Notifications spec version
)
.to_variant(),
));
Expand Down Expand Up @@ -946,6 +957,26 @@ impl NotificationService {
}
}

fn create_activation_token() -> Option<String> {
super::activation::ActivationService::global()?.create_token()
}

fn emit_activation_token(&self, id: u32, token: &str) {
let Some(ref bus) = *self.bus.borrow() else {
return;
};

if let Err(e) = bus.emit_signal(
None::<&str>,
NOTIFICATIONS_PATH,
NOTIFICATIONS_NAME,
"ActivationToken",
Some(&(id, token).to_variant()),
) {
error!("NotificationService: failed to emit ActivationToken: {}", e);
}
}

fn emit_action_invoked(&self, id: u32, action_key: &str) {
debug!(
"NotificationService: emitting ActionInvoked signal for id={}, action_key={}",
Expand Down Expand Up @@ -1122,6 +1153,13 @@ mod tests {
assert!(interface.lookup_method(UNREAD_METHOD).is_some());
}

#[test]
fn activation_token_signal_is_exposed() {
let node_info = gio::DBusNodeInfo::for_xml(NOTIFICATIONS_XML).unwrap();
let interface = node_info.lookup_interface(NOTIFICATIONS_NAME).unwrap();
assert!(interface.lookup_signal("ActivationToken").is_some());
}

/// Mirror of the post-insert tail in handle_notify, which we can't call
/// directly because it consumes D-Bus types.
fn simulate_handle_notify(svc: &NotificationService, n: Notification) {
Expand Down
Loading
Loading