From 4439e7cb47f390218f426feb0b865d246f503ee5 Mon Sep 17 00:00:00 2001 From: Yash Karandikar Date: Wed, 11 May 2022 11:28:01 -0500 Subject: [PATCH] Make backend --- .gitignore | 1 + Cargo.toml | 4 ++++ src/lib.rs | 27 ++++++++++++++++++++------- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 4fffb2f..7c6d3b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /Cargo.lock +/venv diff --git a/Cargo.toml b/Cargo.toml index a928c36..6c1aaa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/lib.rs b/src/lib.rs index 1b4a90c..0e49744 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(()) }