feat: new command 'status_notify'
added a new command that sends the current stats using a notification
This commit is contained in:
parent
ecd67419b8
commit
65433f3560
4 changed files with 957 additions and 42 deletions
967
Cargo.lock
generated
967
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue