Make backend

This commit is contained in:
Yash Karandikar 2022-05-11 11:28:01 -05:00
parent 59e9f1ca73
commit 4439e7cb47
3 changed files with 25 additions and 7 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target
/Cargo.lock
/venv

View file

@ -4,5 +4,9 @@ version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "wn_backend"
crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.16.4", features = ["extension-module"] }

View file

@ -1,8 +1,21 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
let result = 2 + 2;
assert_eq!(result, 4);
}
use pyo3::prelude::*;
use std::process::Command;
#[pyfunction]
fn send_notification(icon_path: &str, nick: &str, text: &str) -> PyResult<()> {
Command::new("notify-send")
.arg("-i")
.arg(icon_path)
.arg(format!("{}:", nick))
.arg(text)
.spawn()?;
Ok(())
}
#[pymodule]
fn wn_backend(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(send_notification, m)?)?;
Ok(())
}