feat: new command 'status_notify'

added a new command that sends the current stats using a notification
This commit is contained in:
Vladimir Rubin 2025-04-23 22:49:48 +03:00
parent ecd67419b8
commit 65433f3560
Signed by: vavakado
GPG key ID: CAB744727F36B524
4 changed files with 957 additions and 42 deletions

967
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,4 +5,11 @@ edition = "2021"
[dependencies]
chrono = "0.4.40"
tokio = { version = "1", features = ["full"] }
notify-rust = "4.11.7"
tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync", "time","io-util","net" ] }
[profile.release]
strip = true
lto = true
codegen-units = 1
opt-level = "s"

View file

@ -5,6 +5,7 @@ a little daemon to control screen temperature and gamma using hyprsunset
has a unix socket (`/tmp/hinoirisetr.sock`) that accepts four commands
- status - prints the current status
- status_notify - sends the current status via a notification
- enable - toggles the filter on
- disable - toggles the filter off
- toggle - toggles the filter

View file

@ -1,5 +1,6 @@
use chrono::Local;
use hinoirisetr::{apply_settings, compute_settings};
use notify_rust::Notification;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
@ -13,7 +14,7 @@ use tokio::{
};
const SOCKET_PATH: &str = "/tmp/hinoirisetr.sock";
const NOTIFICATION_TIMEOUT: u32 = 5000;
async fn socket_server(disabled: Arc<AtomicBool>, notify: Arc<Notify>) {
let _ = std::fs::remove_file(SOCKET_PATH);
@ -54,6 +55,23 @@ async fn socket_server(disabled: Arc<AtomicBool>, notify: Arc<Notify>) {
cur_gamma
);
}
"status_notify" => {
let now = Local::now();
let (cur_temp, cur_gamma) = compute_settings(now);
match Notification::new()
.summary("Sunsetting")
.body(format!("temp: {}K, gamma: {}%", cur_temp, cur_gamma).as_str())
.timeout(notify_rust::Timeout::Milliseconds(NOTIFICATION_TIMEOUT))
.show_async()
.await
{
Ok(_) => {}
Err(err) => {
eprintln!("Erorr occured while sending a notification: {}", err)
}
}
}
_ => eprintln!("unknown command: {}", line.trim()),
}
}
@ -65,6 +83,8 @@ async fn main() {
let disabled = Arc::new(AtomicBool::new(false));
let notify = Arc::new(Notify::new());
println!("dimming is enabled");
// Spawn control socket server
{
let disabled = Arc::clone(&disabled);