mirror of
https://github.com/szymon-jozef/libnotify-rs.git
synced 2026-10-27 19:20:43 +01:00
Compare commits
6 Commits
v0.3.0
...
fix/compil
| Author | SHA1 | Date | |
|---|---|---|---|
| 043b6e93c8 | |||
| 0e2e97bf66 | |||
| 025ab6af68 | |||
| 034a302f3b | |||
|
|
987cd449c5 | ||
| aa12ffe8ff |
108
Cargo.lock
generated
108
Cargo.lock
generated
@@ -11,6 +11,56 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-parse"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
|
||||||
|
dependencies = [
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-query"
|
||||||
|
version = "1.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"once_cell_polyfill",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bindgen"
|
name = "bindgen"
|
||||||
version = "0.73.2"
|
version = "0.73.2"
|
||||||
@@ -72,6 +122,39 @@ dependencies = [
|
|||||||
"libloading",
|
"libloading",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "4.6.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946"
|
||||||
|
dependencies = [
|
||||||
|
"clap_builder",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_builder"
|
||||||
|
version = "4.6.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"clap_lex",
|
||||||
|
"strsim",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "1.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@@ -229,6 +312,12 @@ dependencies = [
|
|||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.190"
|
version = "0.2.190"
|
||||||
@@ -250,6 +339,7 @@ name = "libnotify-rs"
|
|||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
|
"clap",
|
||||||
"glib",
|
"glib",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
"serial_test",
|
"serial_test",
|
||||||
@@ -298,6 +388,12 @@ version = "1.21.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell_polyfill"
|
||||||
|
version = "1.70.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.5"
|
version = "0.12.5"
|
||||||
@@ -483,6 +579,12 @@ version = "1.16.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f9395f0f0eee849a9b707b2f06bb92a6a422090e2123bb2ef8e87a0e61892a8e"
|
checksum = "f9395f0f0eee849a9b707b2f06bb92a6a422090e2123bb2ef8e87a0e61892a8e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "3.0.6"
|
version = "3.0.6"
|
||||||
@@ -558,6 +660,12 @@ version = "1.0.26"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
|
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version-compare"
|
name = "version-compare"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ license = "MIT"
|
|||||||
keywords = [ "bindings", "libnotify" ]
|
keywords = [ "bindings", "libnotify" ]
|
||||||
build = "./build.rs"
|
build = "./build.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = {version = "4.6.7", optional = true}
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
pkg-config = "0.3.34"
|
pkg-config = "0.3.34"
|
||||||
bindgen = "0.73.2"
|
bindgen = "0.73.2"
|
||||||
@@ -18,3 +21,6 @@ bindgen = "0.73.2"
|
|||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
glib = "0.22.10"
|
glib = "0.22.10"
|
||||||
serial_test = "4.0.1"
|
serial_test = "4.0.1"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
clap = [ "dep:clap" ]
|
||||||
|
|||||||
@@ -27,9 +27,11 @@ Available at [github pages](https://szymon-jozef.github.io/libnotify-rs/libnotif
|
|||||||
## Add to project
|
## Add to project
|
||||||
Type in:
|
Type in:
|
||||||
```bash
|
```bash
|
||||||
cargo add --git "https://github.com/szymon-jozef/libnotify-rs"
|
cargo add --git "https://github.com/szymon-jozef/libnotify-rs" --tag <desired version>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Tag argument is optional, but encouraged.
|
||||||
|
|
||||||
### Nix flake
|
### Nix flake
|
||||||
For nix users, there is also a flake inside. If you want to use it add this to your flake:
|
For nix users, there is also a flake inside. If you want to use it add this to your flake:
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::api::errors::LibnotifyError;
|
|||||||
use super::libnotify::*;
|
use super::libnotify::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
|
||||||
/// Notification urgency level. Refer to [libnotify docs](https://gnome.pages.gitlab.gnome.org/libnotify/enum.Urgency.html) for more info
|
/// Notification urgency level. Refer to [libnotify docs](https://gnome.pages.gitlab.gnome.org/libnotify/enum.Urgency.html) for more info
|
||||||
pub enum Urgency {
|
pub enum Urgency {
|
||||||
/// Low urgency. Used for unimportant notifications
|
/// Low urgency. Used for unimportant notifications
|
||||||
|
|||||||
12
src/lib.rs
12
src/lib.rs
@@ -1,17 +1,25 @@
|
|||||||
//! This crate exposes two modules:
|
//! This crate exposes two modules:
|
||||||
//!
|
//!
|
||||||
//! # Api
|
//! # Crate structure
|
||||||
|
//! ## Api
|
||||||
//! This module contains a basic wrapper for libnotify calls. It just translates data types, etc,
|
//! This module contains a basic wrapper for libnotify calls. It just translates data types, etc,
|
||||||
//! so usage is basically the same as libnotify.
|
//! so usage is basically the same as libnotify.
|
||||||
//!
|
//!
|
||||||
//! # Wrappers
|
//! ## Wrappers
|
||||||
//! This module is a higher level abstraction over api. Recommended to use over api.
|
//! This module is a higher level abstraction over api. Recommended to use over api.
|
||||||
//!
|
//!
|
||||||
|
//! # Features
|
||||||
|
//!
|
||||||
|
//! - clap – enables [clap] support for `Urgency`
|
||||||
|
//!
|
||||||
#![allow(non_upper_case_globals)]
|
#![allow(non_upper_case_globals)]
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
compile_error!("Libnotify-rs only supports linux");
|
||||||
|
|
||||||
/// Basic libnotify rust wrapper
|
/// Basic libnotify rust wrapper
|
||||||
pub mod api;
|
pub mod api;
|
||||||
/// Higher level abstraction over api
|
/// Higher level abstraction over api
|
||||||
|
|||||||
@@ -34,42 +34,62 @@ impl<'a> NotificationBuilder<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets app name for this specific notification.
|
/// Sets app name for this specific notification.
|
||||||
pub fn set_app_name(mut self, app_name: &str) -> Result<Self, LibnotifyError> {
|
pub fn set_app_name<T: Into<Option<&'a str>>>(
|
||||||
self.notification.set_app_name(app_name)?;
|
mut self,
|
||||||
|
app_name: T,
|
||||||
|
) -> Result<Self, LibnotifyError> {
|
||||||
|
if let Some(app_name) = app_name.into() {
|
||||||
|
self.notification.set_app_name(app_name)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets app icon fot this specific notification.
|
/// Sets app icon fot this specific notification.
|
||||||
pub fn set_app_icon(mut self, app_icon: &str) -> Result<Self, LibnotifyError> {
|
pub fn set_app_icon<T: Into<Option<&'a str>>>(
|
||||||
self.notification.set_app_icon(app_icon)?;
|
mut self,
|
||||||
|
app_icon: T,
|
||||||
|
) -> Result<Self, LibnotifyError> {
|
||||||
|
if let Some(app_icon) = app_icon.into() {
|
||||||
|
self.notification.set_app_icon(app_icon)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets category for this specific notification
|
/// Sets category for this specific notification
|
||||||
pub fn set_category(mut self, category: &str) -> Result<Self, LibnotifyError> {
|
pub fn set_category<T: Into<Option<&'a str>>>(
|
||||||
self.notification.set_category(category)?;
|
mut self,
|
||||||
|
category: T,
|
||||||
|
) -> Result<Self, LibnotifyError> {
|
||||||
|
if let Some(category) = category.into() {
|
||||||
|
self.notification.set_category(category)?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set hint for this specific notification
|
/// Set hint for this specific notification
|
||||||
pub fn set_hint(
|
pub fn set_hint(mut self, key: &str, value: HintValue) -> Result<Self, LibnotifyError> {
|
||||||
mut self,
|
|
||||||
key: &str,
|
|
||||||
value: HintValue,
|
|
||||||
) -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
self.notification.set_hint(key, value)?;
|
self.notification.set_hint(key, value)?;
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set timeout until close
|
/// Set timeout until close
|
||||||
pub fn set_timeout(mut self, timeout: Timeout) -> Self {
|
pub fn set_timeout<T: Into<Option<Timeout>>>(mut self, timeout: T) -> Self {
|
||||||
self.notification.set_timeout(timeout);
|
if let Some(timeout) = timeout.into() {
|
||||||
|
self.notification.set_timeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set notification urgency level
|
/// Set notification urgency level
|
||||||
pub fn set_urgency(mut self, urgency: Urgency) -> Self {
|
pub fn set_urgency<T: Into<Option<Urgency>>>(mut self, urgency: T) -> Self {
|
||||||
self.notification.set_urgency(urgency);
|
if let Some(urgency) = urgency.into() {
|
||||||
|
self.notification.set_urgency(urgency);
|
||||||
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user