-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from hoodie/feature/configurable-busname
configurable busname
- Loading branch information
Showing
13 changed files
with
445 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#[cfg(target_os = "macos")] | ||
fn main() { | ||
println!("this is an xdg only feature") | ||
} | ||
|
||
#[cfg(target_os = "windows")] | ||
fn main() { | ||
println!("this is an xdg only feature") | ||
} | ||
|
||
#[cfg(all(unix, not(target_os = "macos",)))] | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
use notify_rust::Notification; | ||
std::env::set_var( | ||
"RUST_LOG", | ||
"simple=trace,zbus=trace,server=trace,notify_rust=trace", | ||
); | ||
color_backtrace::install(); | ||
#[cfg(feature = "env_logger")] | ||
env_logger::init(); | ||
|
||
#[allow(deprecated)] | ||
Notification::at_bus("example") | ||
.summary("Critical Error") | ||
.body("Just <b>kidding</b>, this is just the notification (example).") | ||
.icon("dialog-error") | ||
.show()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::xdg::NOTIFICATION_DEFAULT_BUS; | ||
|
||
fn skip_first_slash(s: &str) -> &str { | ||
if let Some('/') = s.chars().next() { | ||
&s[1..] | ||
} else { | ||
s | ||
} | ||
} | ||
|
||
use std::path::PathBuf; | ||
|
||
type BusNameType = std::borrow::Cow<'static, str>; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct NotificationBus(BusNameType); | ||
|
||
impl Default for NotificationBus { | ||
#[cfg(feature = "zbus")] | ||
fn default() -> Self { | ||
Self( | ||
zbus::names::WellKnownName::from_static_str(NOTIFICATION_DEFAULT_BUS) | ||
.unwrap() | ||
.to_string() | ||
.into(), | ||
) | ||
} | ||
|
||
#[cfg(all(feature = "dbus", not(feature = "zbus")))] | ||
fn default() -> Self { | ||
Self( | ||
dbus::strings::BusName::from_slice(NOTIFICATION_DEFAULT_BUS) | ||
.unwrap() | ||
.to_string() | ||
.into(), | ||
) | ||
} | ||
} | ||
|
||
impl NotificationBus { | ||
fn namespaced_custom(custom_path: &str) -> Option<String> { | ||
// abusing path for semantic join | ||
skip_first_slash( | ||
PathBuf::from("/de/hoodie/Notification") | ||
.join(custom_path) | ||
.to_str()?, | ||
) | ||
.replace('/', ".") | ||
.into() | ||
} | ||
|
||
#[cfg(feature = "zbus")] | ||
pub fn custom(custom_path: &str) -> Option<Self> { | ||
let name = | ||
zbus::names::WellKnownName::try_from(Self::namespaced_custom(custom_path)?).ok()?; | ||
Some(Self(name.to_string().into())) | ||
} | ||
|
||
#[cfg(all(feature = "dbus", not(feature = "zbus")))] | ||
pub fn custom(custom_path: &str) -> Option<Self> { | ||
let name = dbus::strings::BusName::new(Self::namespaced_custom(custom_path)?).ok()?; | ||
Some(Self(name.to_string().into())) | ||
} | ||
|
||
pub fn into_name(self) -> BusNameType { | ||
self.0 | ||
} | ||
} |
Oops, something went wrong.