Skip to content

Commit

Permalink
chore: tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Aug 10, 2024
1 parent d9750ab commit cd82f0d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use iced_layershell::actions::{
LayershellCustomActionsWithIdAndInfo, LayershellCustomActionsWithInfo,
};
use launcher::{LaunchMessage, Launcher};
use notification_iced::{start_server, NotifyMessage, NotifyUnit};
use notification_iced::{start_server, NotifyMessage, NotifyUnit, VersionInfo};
use zbus_mpirs::ServiceInfo;

use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings};
Expand Down Expand Up @@ -632,7 +632,26 @@ impl MultiApplication for LalaMusicBar {
iced::time::every(std::time::Duration::from_secs(5)).map(|_| Message::UpdateBalance),
iced::event::listen()
.map(|event| Message::LauncherInfo(LaunchMessage::IcedEvent(event))),
iced::subscription::channel(std::any::TypeId::of::<()>(), 100, start_server),
iced::subscription::channel(std::any::TypeId::of::<()>(), 100, |sender| async {
start_server(
sender,
vec![
"body".to_owned(),
"body-markup".to_owned(),
"actions".to_owned(),
"icon-static".to_owned(),
"x-canonical-private-synchronous".to_owned(),
"x-dunst-stack-tag".to_owned(),
],
VersionInfo {
name: "LaLaMako".to_owned(),
vendor: "waycrate".to_owned(),
version: env!("CARGO_PKG_VERSION").to_owned(),
spec_version: env!("CARGO_PKG_VERSION_PATCH").to_owned(),
},
)
.await
}),
])
}

Expand Down
58 changes: 41 additions & 17 deletions notification_iced/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,20 @@ pub struct NotifyUnit {
pub timeout: i32,
}

#[derive(Debug, Clone)]
pub struct VersionInfo {
pub name: String,
pub vendor: String,
pub version: String,
pub spec_version: String,
}

#[derive(Debug)]
pub struct LaLaMako<T: From<NotifyMessage> + Send>(Sender<T>);
pub struct LaLaMako<T: From<NotifyMessage> + Send> {
capablities: Vec<String>,
sender: Sender<T>,
version: VersionInfo,
}

#[interface(name = "org.freedesktop.Notifications")]
impl<T: From<NotifyMessage> + Send + 'static> LaLaMako<T> {
Expand All @@ -66,29 +78,30 @@ impl<T: From<NotifyMessage> + Send + 'static> LaLaMako<T> {
self.notification_closed(&ctx, id, NOTIFICATION_DELETED_BY_USER)
.await
.ok();
self.0.try_send(NotifyMessage::UnitRemove(id).into()).ok();
self.sender
.try_send(NotifyMessage::UnitRemove(id).into())
.ok();
Ok(())
}

/// GetCapabilities method
fn get_capabilities(&self) -> Vec<String> {
vec![
"body".to_owned(),
"body-markup".to_owned(),
"actions".to_owned(),
"icon-static".to_owned(),
"x-canonical-private-synchronous".to_owned(),
"x-dunst-stack-tag".to_owned(),
]
self.capablities.clone()
}

/// GetServerInformation method
fn get_server_information(&self) -> (String, String, String, String) {
let VersionInfo {
name,
vendor,
version,
spec_version,
} = &self.version;
(
"LaLaMako".to_owned(),
"waycrate".to_owned(),
env!("CARGO_PKG_VERSION").to_owned(),
env!("CARGO_PKG_VERSION_PATCH").to_owned(),
name.clone(),
vendor.clone(),
version.clone(),
spec_version.clone(),
)
}

Expand All @@ -105,7 +118,7 @@ impl<T: From<NotifyMessage> + Send + 'static> LaLaMako<T> {
_hints: std::collections::HashMap<&str, OwnedValue>,
timeout: i32,
) -> zbus::fdo::Result<u32> {
self.0
self.sender
.try_send(
NotifyMessage::UnitAdd(NotifyUnit {
app_name: app_name.to_string(),
Expand Down Expand Up @@ -140,11 +153,22 @@ impl<T: From<NotifyMessage> + Send + 'static> LaLaMako<T> {
) -> zbus::Result<()>;
}

pub async fn start_server<T: From<NotifyMessage> + Send + 'static>(sender: Sender<T>) -> Never {
pub async fn start_server<T: From<NotifyMessage> + Send + 'static>(
sender: Sender<T>,
capablities: Vec<String>,
version: VersionInfo,
) -> Never {
let _conn = async {
ConnectionBuilder::session()?
.name("org.freedesktop.Notifications")?
.serve_at("/org/freedesktop/Notifications", LaLaMako(sender))?
.serve_at(
"/org/freedesktop/Notifications",
LaLaMako {
sender,
capablities,
version,
},
)?
.build()
.await
}
Expand Down

0 comments on commit cd82f0d

Please sign in to comment.