Files
owlry/crates/owlry-core/src/notify.rs
vikingowl d79c9087fd feat(owlry-core): move backend modules from owlry
Move the following modules from crates/owlry/src/ to crates/owlry-core/src/:
- config/ (configuration loading and types)
- data/ (frecency store)
- filter.rs (provider filtering and prefix parsing)
- notify.rs (desktop notifications)
- paths.rs (XDG path handling)
- plugins/ (plugin system: native loader, manifest, registry, runtime loader, Lua API)
- providers/ (provider trait, manager, application, command, native_provider, lua_provider)

Notable changes from the original:
- providers/mod.rs: ProviderManager constructor changed from with_native_plugins()
  to new(core_providers, native_providers) to decouple from DmenuProvider
  (which stays in owlry as a UI concern)
- plugins/mod.rs: commands module removed (stays in owlry as CLI concern)
- Added thiserror and tempfile dependencies to owlry-core Cargo.toml
2026-03-26 12:06:34 +01:00

92 lines
2.5 KiB
Rust

//! Desktop notification system
//!
//! Provides system notifications for owlry and its plugins.
//! Uses the freedesktop notification specification via notify-rust.
//!
//! Note: Some convenience functions are provided for future use and
//! are currently unused by the core (plugins use the Host API instead).
#![allow(dead_code)]
use notify_rust::{Notification, Urgency};
/// Notification urgency level
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum NotifyUrgency {
/// Low priority notification
Low,
/// Normal priority notification (default)
#[default]
Normal,
/// Critical/urgent notification
Critical,
}
impl From<NotifyUrgency> for Urgency {
fn from(urgency: NotifyUrgency) -> Self {
match urgency {
NotifyUrgency::Low => Urgency::Low,
NotifyUrgency::Normal => Urgency::Normal,
NotifyUrgency::Critical => Urgency::Critical,
}
}
}
/// Send a simple notification
pub fn notify(summary: &str, body: &str) {
notify_with_options(summary, body, None, NotifyUrgency::Normal);
}
/// Send a notification with an icon
pub fn notify_with_icon(summary: &str, body: &str, icon: &str) {
notify_with_options(summary, body, Some(icon), NotifyUrgency::Normal);
}
/// Send a notification with full options
pub fn notify_with_options(summary: &str, body: &str, icon: Option<&str>, urgency: NotifyUrgency) {
let mut notification = Notification::new();
notification
.appname("Owlry")
.summary(summary)
.body(body)
.urgency(urgency.into());
if let Some(icon_name) = icon {
notification.icon(icon_name);
}
if let Err(e) = notification.show() {
log::warn!("Failed to show notification: {}", e);
}
}
/// Send a notification with a timeout
pub fn notify_with_timeout(summary: &str, body: &str, icon: Option<&str>, timeout_ms: i32) {
let mut notification = Notification::new();
notification
.appname("Owlry")
.summary(summary)
.body(body)
.timeout(timeout_ms);
if let Some(icon_name) = icon {
notification.icon(icon_name);
}
if let Err(e) = notification.show() {
log::warn!("Failed to show notification: {}", e);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_urgency_conversion() {
assert_eq!(Urgency::from(NotifyUrgency::Low), Urgency::Low);
assert_eq!(Urgency::from(NotifyUrgency::Normal), Urgency::Normal);
assert_eq!(Urgency::from(NotifyUrgency::Critical), Urgency::Critical);
}
}