pino-rs
Rust notification daemon.
git clone https://git.pi66.xyz/pino-rs
About | Files | Commits | Refs | License
V1.1.2 | add Unix-Socket
Author: pixel
Date: 2025-04-30 16:56
commit: 8153b0b9
Stat
| M | Cargo.toml | 2 | +1 | -1 |
| M | src/colors.rs | 19 | +11 | -8 |
| M | src/config.rs | 22 | +10 | -12 |
| M | src/main.rs | 153 | +76 | -77 |
| M | src/screen.rs | 2 | +1 | -1 |
| M | src/ui.rs | 121 | +77 | -44 |
| D | src/utils.rs | 18 | +0 | -18 |
Diff
diff --git a/Cargo.toml b/Cargo.toml
index 66a737a..9c9158e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pino"
-version = "1.1.1"
+version = "1.1.2"
edition = "2024"
[dependencies]
diff --git a/src/colors.rs b/src/colors.rs
index 97f8df4..6d1aa8b 100644
--- a/src/colors.rs
+++ b/src/colors.rs
@@ -12,7 +12,7 @@ pub fn get_config_dir() -> PathBuf {
panic!("Could not determine config directory");
}
...
Show all
Show less
diff --git a/Cargo.toml b/Cargo.toml
index 66a737a..9c9158e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pino"
-version = "1.1.1"
+version = "1.1.2"
edition = "2024"
[dependencies]
diff --git a/src/colors.rs b/src/colors.rs
index 97f8df4..6d1aa8b 100644
--- a/src/colors.rs
+++ b/src/colors.rs
@@ -12,7 +12,7 @@ pub fn get_config_dir() -> PathBuf {
panic!("Could not determine config directory");
}
...
diff --git a/Cargo.toml b/Cargo.toml
index 66a737a..9c9158e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "pino"
-version = "1.1.1"
+version = "1.1.2"
edition = "2024"
[dependencies]
diff --git a/src/colors.rs b/src/colors.rs
index 97f8df4..6d1aa8b 100644
--- a/src/colors.rs
+++ b/src/colors.rs
@@ -12,7 +12,7 @@ pub fn get_config_dir() -> PathBuf {
panic!("Could not determine config directory");
}
-fn create_template(app:&str) {
+fn create_template(app: &str) {
let config = get_config_dir()
.join(app)
.join("templates")
@@ -105,27 +105,30 @@ pub fn pywal(
border_color: String,
title_color: String,
message_color: String,
-) ->(String,String,String,String) {
+) -> (String, String, String, String) {
let home = env::var("HOME").expect("Can't Find Home Dir");
- if !get_config_dir().join("wal/templates/colors-pino.toml").exists(){
+ if !get_config_dir()
+ .join("wal/templates/colors-pino.toml")
+ .exists()
+ {
create_template("wal");
}
-
-
- if !get_config_dir().join("walrs/templates/colors-pino.toml").exists(){
+ if !get_config_dir()
+ .join("walrs/templates/colors-pino.toml")
+ .exists()
+ {
create_template("walrs");
}
-
let cache_colors = PathBuf::from(home)
.join(".cache")
.join("wal")
.join("colors-pino.toml");
let content = fs::read_to_string(&cache_colors).expect("Can't Read Colors File!!!");
let colors: Pywal = toml::from_str(&content).expect("Invalid TOML Format!!!");
- (
+ (
get_color(&colors, background_color.as_str()).to_string(),
get_color(&colors, border_color.as_str()).to_string(),
get_color(&colors, title_color.as_str()).to_string(),
diff --git a/src/config.rs b/src/config.rs
index d78ba8c..8f26304 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,13 +1,13 @@
-use std::{path::PathBuf,fs::{create_dir_all,OpenOptions},io::Write};
+use std::{
+ fs::{OpenOptions, create_dir_all},
+ io::Write,
+ path::PathBuf,
+};
+pub fn generate_config(config_path: PathBuf) {
+ let config = config_path.join("pino").join("config.toml");
-pub fn generate_config(config_path: PathBuf){
- let config = config_path
- .join("pino")
- .join("config.toml");
-
- create_dir_all(config.parent().unwrap())
- .expect("Failed to create directories for template");
+ create_dir_all(config.parent().unwrap()).expect("Failed to create directories for template");
println!("Creating config file at: {}", config.display());
let mut template = OpenOptions::new()
.write(true)
@@ -65,9 +65,7 @@ border_color = "color1"
title_color = "fg"
message_color = "color8"
-")
+",
+ )
.expect("Can't Create Template File !!!");
}
-
-
-
diff --git a/src/main.rs b/src/main.rs
index 73d5f1d..2dc5782 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,51 +1,53 @@
-use serde::Deserialize;
-use std::{fs::{self, File}, io::Write};
use argh::FromArgs;
-use utils::is_running;
-
+use serde::Deserialize;
+use std::{fs, io::Write, os::unix::net::UnixStream, path::Path};
-mod utils;
mod colors;
mod config;
mod screen;
mod ui;
-
-// Get Args
#[derive(FromArgs)]
-
-#[argh(description = "This tool lets you display notification with customizable options. you can also use a configuration file to set theme
-and everything easily (conf path = ~/.config/pino)")]
+#[argh(
+ description = "This tool lets you display notification with customizable options. you can also use a configuration file to set theme
+and everything easily (conf path = ~/.config/pino)"
+)]
struct Arg {
-
- #[argh(option,short = 't', description = "set the notification title content")]
- title:Option<String> ,
-
- #[argh(option,short = 'm', description = "set the notification message content")]
- message:Option<String>,
-
-
- #[argh(option,short = 'd', description = "set the delay before program closes with secends")]
- delay:Option<i32> ,
-
- #[argh(switch,short = 'f', description = "print all the fonts that you can use it")]
- font:bool ,
-
- #[argh(option,short = 'c', description = "set a custom configuration file")]
- config:Option<String> ,
-
-
- #[argh(switch,short = 'v', description = "set a custom configuration file")]
- version:bool ,
+ #[argh(
+ option,
+ short = 't',
+ description = "set the notification title content"
+ )]
+ title: Option<String>,
+
+ #[argh(
+ option,
+ short = 'm',
+ description = "set the notification message content"
+ )]
+ message: Option<String>,
+
+ #[argh(
+ option,
+ short = 'd',
+ description = "set the delay before program closes with secends"
+ )]
+ delay: Option<u64>,
+
+ #[argh(
+ switch,
+ short = 'f',
+ description = "print all the fonts that you can use it"
+ )]
+ font: bool,
+
+ #[argh(option, short = 'c', description = "set a custom configuration file")]
+ config: Option<String>,
+
+ #[argh(switch, short = 'v', description = "set a custom configuration file")]
+ version: bool,
}
-
-
-
-
-
-
-// Read the Config File
#[derive(Debug, Deserialize)]
struct Config {
screen: Screen,
@@ -65,7 +67,7 @@ struct Screen {
y: i32,
width: i32,
height: i32,
- delay: i32,
+ delay: u64,
}
#[derive(Debug, Deserialize)]
struct Frame {
@@ -101,53 +103,58 @@ struct Pywal {
message_color: String,
}
-
-
fn main() {
let config_folder = colors::get_config_dir();
- let args:Arg = argh::from_env();
+ let args: Arg = argh::from_env();
if args.version {
- println!("v1.1.1");
- return ;
+ println!("v1.1.2");
+ return;
}
- if args.font{
+ if args.font {
ui::print_fonts();
- return ;
+ return;
}
-
let config_file = match args.config {
Some(path) => path,
None => {
if !config_folder.join("pino").exists() {
config::generate_config(config_folder.clone());
}
- config_folder.join("pino").join("config.toml").to_string_lossy().into_owned()
+ config_folder
+ .join("pino")
+ .join("config.toml")
+ .to_string_lossy()
+ .into_owned()
}
};
let config_content = fs::read_to_string(config_file).expect("Faild ");
let config: Config = toml::from_str(&config_content).expect("Faild");
-
-
- let mut pino_check = File::create("/tmp/pino-check").unwrap();
-
- writeln!(pino_check ,"{}",args.title.unwrap_or("Title".to_string())).unwrap();
- writeln!(pino_check ,"{}",args.message.unwrap_or("you didn't set the title or message".to_string())).unwrap();
- writeln!(pino_check ,"{}",args.delay.unwrap_or(config.screen.delay)).unwrap();
-
-
- if !is_running("pino"){
-
+ if Path::new("/tmp/pino-check.sock").exists() {
+ let mut stream = UnixStream::connect("/tmp/pino-check.sock").unwrap();
+ stream
+ .write_all(
+ format!(
+ "{}|+|{}|+|{}",
+ args.title.unwrap_or("Title".to_string()),
+ args.message
+ .unwrap_or("you didn't set the title or message".to_string()),
+ args.delay.unwrap_or(config.screen.delay)
+ )
+ .as_bytes(),
+ )
+ .unwrap()
+ } else {
let colors = match config.pywal.pywal {
true => colors::pywal(
config.pywal.background_color.to_string(),
config.pywal.border_color.to_string(),
config.pywal.title_color.to_string(),
- config.pywal.message_color.to_string()
+ config.pywal.message_color.to_string(),
),
false => (
config.frame.fg_color,
@@ -155,10 +162,8 @@ fn main() {
config.title.color,
config.message.color,
),
-
};
- // Get Screen Placment
let screen = screen::get_size(
config.screen.monitor,
config.screen.vertical.as_str(),
@@ -169,25 +174,19 @@ fn main() {
config.screen.height,
);
- //UI
ui::ui(
- screen,config.frame.font_family,
- (
- config.border.weight,
- config.border.radius,
- ),
+ screen,
+ config.frame.font_family,
+ (config.border.weight, config.border.radius),
+ (config.title.x, config.title.y, config.title.font_size),
+ (config.message.x, config.message.y, config.message.font_size),
+ colors,
(
- config.title.x,
- config.title.y,
- config.title.font_size,
+ args.title.unwrap_or("Title".to_string()),
+ args.message
+ .unwrap_or("you didn't set the title or message".to_string()),
+ args.delay.unwrap_or(config.screen.delay),
),
- (
- config.message.x,
- config.message.y,
- config.message.font_size,
- ),colors
);
}
}
-
-
diff --git a/src/screen.rs b/src/screen.rs
index 524e512..c47efcb 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -17,7 +17,7 @@ pub fn get_size(
if h.to_lowercase() == "left" {
if v.to_lowercase() == "top" {
- return (screens[monitor].0 + ax, ay + screens[monitor].1 , aw , ah);
+ return (screens[monitor].0 + ax, ay + screens[monitor].1, aw, ah);
} else if v.to_lowercase() == "bottom" {
return (
screens[monitor].0 + ax,
diff --git a/src/ui.rs b/src/ui.rs
index d11c590..025ab1d 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -1,5 +1,5 @@
use fltk::{
- app::{self,get_font_names},
+ app::{self, get_font_names},
draw,
enums::{Align, Color, Event, Font},
frame::Frame,
@@ -7,10 +7,14 @@ use fltk::{
window::Window,
};
use std::{
- fs::{self, metadata}, sync::mpsc, thread, time::{Duration, Instant}
+ io::Read,
+ os::unix::net::UnixListener,
+ path::Path,
+ sync::mpsc,
+ thread,
+ time::{Duration, Instant},
};
-
pub fn print_fonts() {
for font in get_font_names() {
println!("{font}");
@@ -21,9 +25,10 @@ pub fn ui(
screen_info: (i32, i32, i32, i32),
font_family: String,
border: (i32, i32),
- title: (i32,i32,i32),
- message: (i32,i32,i32),
+ title: (i32, i32, i32),
+ message: (i32, i32, i32),
colors: (String, String, String, String),
+ data: (String, String, u64),
) {
let app = app::App::default().load_system_fonts();
@@ -34,7 +39,6 @@ pub fn ui(
screen_info.3,
"Pino",
);
-
wind1.set_color(Color::from_hex_str(colors.1.as_str()).unwrap());
let mut wind2 = Window::new(
@@ -46,25 +50,40 @@ pub fn ui(
);
wind2.set_color(Color::from_hex_str(colors.0.as_str()).unwrap());
- let mut title_frame = Frame::new(5 + title.0, 20 + title.1, wind2.w() - 10, wind2.h()-10, "");
- let mut message_frame = Frame::new(5 + message.0, 20 + message.1, wind2.w() - 10, wind2.h()-10, "");
+ let mut title_frame = Frame::new(
+ 5 + title.0,
+ 20 + title.1,
+ wind2.w() - 10,
+ wind2.h() - 10,
+ "",
+ );
+ let mut message_frame = Frame::new(
+ 5 + message.0,
+ 20 + message.1,
+ wind2.w() - 10,
+ wind2.h() - 10,
+ "",
+ );
title_frame.set_align(Align::Top | Align::Left);
title_frame.set_label_color(Color::from_hex_str(colors.2.as_str()).unwrap());
title_frame.set_label_font(Font::by_name(font_family.as_str()));
title_frame.set_label_size(title.2);
-
message_frame.set_align(Align::Top | Align::Left);
message_frame.set_label_color(Color::from_hex_str(colors.3.as_str()).unwrap());
message_frame.set_label_font(Font::by_name(font_family.as_str()));
message_frame.set_label_size(message.2);
-
-
wind1.draw(move |f| {
draw::set_draw_color(Color::from_hex_str(colors.0.as_str()).unwrap());
- draw::draw_rounded_rectf(border.0 - 1, border.0 -1 , f.w() - border.0 *2 +2, f.h() - border.0 * 2 +2, border.1);
+ draw::draw_rounded_rectf(
+ border.0 - 1,
+ border.0 - 1,
+ f.w() - border.0 * 2 + 2,
+ f.h() - border.0 * 2 + 2,
+ border.1,
+ );
});
wind1.handle(|_, event| {
@@ -76,40 +95,53 @@ pub fn ui(
}
});
- let (tx, rx) = mpsc::channel::<(String, String, Option<u64>)>();
+ let (tx, rx) = mpsc::channel::<(String, String, u64)>();
+ tx.send((data.0, data.1, data.2))
+ .unwrap();
+ let socket_path = "/tmp/pino-check.sock";
+
+ if Path::new(socket_path).exists() {
+ std::fs::remove_file(socket_path).unwrap();
+ }
+
thread::spawn(move || {
- let filename = "/tmp/pino-check";
-
- let (mut current_title,mut current_message,mut current_delay) = (String::new(),String::new(),None);
- let mut modified = metadata(filename).unwrap().modified().unwrap();
- let mut batata = true;
-
- loop {
- if modified != metadata(filename).unwrap().modified().unwrap() || batata{
- batata = false;
- modified = metadata(filename).unwrap().modified().unwrap();
-
- let content = fs::read_to_string(filename).unwrap();
- let lines: Vec<&str> = content.lines().collect();
- let new_title = lines.first().unwrap_or(&"").to_string();
- let new_message = lines.get(1).unwrap_or(&"").to_string();
- let new_delay = lines.get(2).and_then(|s| s.parse::<u64>().ok());
- if new_title != current_title || new_message != current_message || new_delay != current_delay {
- tx.send((new_title.clone(), new_message.clone(), new_delay)).unwrap();
- current_title = new_title;
- current_message = new_message;
- current_delay = new_delay;
+ let listener = UnixListener::bind(socket_path).unwrap();
+
+ for stream in listener.incoming() {
+ match stream {
+ Ok(mut stream) => {
+ let mut buffer = [0; 1024];
+ let n = stream.read(&mut buffer).unwrap();
+ let received = String::from_utf8_lossy(&buffer[..n]).to_string();
+
+ let parts: Vec<String> = received
+ .split("|+|")
+ .map(|item| item.replace('\n', ""))
+ .collect();
+ if parts.len() >= 3 {
+ let title = parts[0].to_string();
+ let message = parts[1].to_string();
+ let delay = parts[2].parse::<u64>().unwrap_or_else(|_| {
+ eprintln!("Invalid delay value, using 3s");
+ 3
+ });
+ tx.send((title, message, delay)).unwrap();
+ }
+ }
+ Err(e) => {
+ eprintln!("Error accepting connection: {}", e);
+ break;
}
- };
- thread::sleep(Duration::from_millis(600));
+ }
}
});
- let mut close_timer: Option<Instant> = None;
- let mut current_delay_secs: Option<u64> = None;
-
wind1.set_override();
wind1.show();
+ wind2.show();
+
+ let mut close_timer: Option<Instant> = None;
+ let mut current_delay_secs: Option<u64> = None;
while app.wait() {
if let Ok((title, message, delay)) = rx.try_recv() {
@@ -121,9 +153,9 @@ pub fn ui(
}
wind2.redraw();
- if delay != current_delay_secs {
- current_delay_secs = delay;
- close_timer = delay.map(|secs| Instant::now() + Duration::from_secs(secs));
+ if current_delay_secs.map(|d| d != delay).unwrap_or(true) {
+ current_delay_secs = Some(delay);
+ close_timer = Some(Instant::now() + Duration::from_secs(delay));
}
}
@@ -134,6 +166,7 @@ pub fn ui(
}
}
}
+ if Path::new(socket_path).exists() {
+ std::fs::remove_file(socket_path).unwrap();
+ }
}
-
-
diff --git a/src/utils.rs b/src/utils.rs
deleted file mode 100644
index 85796b4..0000000
--- a/src/utils.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-use std::process::{Command, Stdio};
-
-pub fn is_running(name: &str) -> bool {
- let output = Command::new("pgrep")
- .arg("-x")
- .arg(name)
- .stdout(Stdio::piped())
- .stderr(Stdio::null())
- .output();
-
- match output {
- Ok(output) if output.status.success() => {
- let pids = String::from_utf8_lossy(&output.stdout);
- pids.lines().count() == 2
- },
- _ => false
- }
-}