feat: remind about dimming after timeout
This commit is contained in:
parent
aeeb17abd0
commit
f28707e446
2 changed files with 41 additions and 3 deletions
11
src/lib.rs
11
src/lib.rs
|
@ -14,6 +14,9 @@ pub mod log;
|
|||
pub mod notify;
|
||||
pub mod time;
|
||||
|
||||
static LAST_TEMP: AtomicU16 = AtomicU16::new(0);
|
||||
static LAST_GAMMA: AtomicU16 = AtomicU16::new(0);
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Config {
|
||||
pub temp_day: u16,
|
||||
|
@ -28,13 +31,11 @@ pub struct Config {
|
|||
pub sunrise_end: u8,
|
||||
|
||||
pub notification_timeout: u32,
|
||||
pub disable_timeout: u32,
|
||||
pub gamma_backend: GammaBackend,
|
||||
pub temp_backend: TempBackend,
|
||||
}
|
||||
|
||||
static LAST_TEMP: AtomicU16 = AtomicU16::new(0);
|
||||
static LAST_GAMMA: AtomicU16 = AtomicU16::new(0);
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum GammaBackend {
|
||||
Hyprctl,
|
||||
|
@ -65,6 +66,7 @@ impl Default for Config {
|
|||
sunset_end: 22,
|
||||
sunrise_start: 4,
|
||||
sunrise_end: 7,
|
||||
disable_timeout: 300,
|
||||
notification_timeout: 5000,
|
||||
gamma_backend: GammaBackend::Hyprctl,
|
||||
temp_backend: TempBackend::Hyprctl,
|
||||
|
@ -135,6 +137,9 @@ impl Config {
|
|||
"notification_timeout" => {
|
||||
config.notification_timeout = value.parse::<u32>()?;
|
||||
}
|
||||
"disable_timeout" => {
|
||||
config.disable_timeout = value.parse::<u32>()?;
|
||||
}
|
||||
"gamma_backend" => match value.to_lowercase().as_str() {
|
||||
"hyprctl" => config.gamma_backend = GammaBackend::Hyprctl,
|
||||
"ddcutil" => config.gamma_backend = GammaBackend::Ddcutil,
|
||||
|
|
33
src/main.rs
33
src/main.rs
|
@ -87,9 +87,42 @@ async fn socket_server(disabled: Arc<AtomicBool>, notify: Arc<Notify>) {
|
|||
match line.trim() {
|
||||
"disable" => {
|
||||
trace!("disable dispatched");
|
||||
let config = *config_guard().await;
|
||||
let disabled_clone = Arc::clone(&disabled);
|
||||
let notify_state = match hinoirisetr::notify::InitializedNotificationSystem::new(
|
||||
"hinoirisetr",
|
||||
) {
|
||||
Ok(not) => NotifyState::Enabled(not),
|
||||
Err(_) => NotifyState::Disabled,
|
||||
};
|
||||
|
||||
disabled.store(true, Ordering::SeqCst);
|
||||
notify.notify_one();
|
||||
debug!("dimming is disabled");
|
||||
|
||||
// Spawn a background task to remind after timeout
|
||||
println!("{}", config.disable_timeout);
|
||||
if config.disable_timeout != 0 {
|
||||
debug!("Spawning dimming timeout task");
|
||||
tokio::spawn(async move {
|
||||
let timeout_secs = config.disable_timeout;
|
||||
tokio::time::sleep(Duration::from_secs(timeout_secs.into())).await;
|
||||
|
||||
if disabled_clone.load(Ordering::SeqCst) {
|
||||
warn!("You've had dimming disabled for too long!");
|
||||
|
||||
// Show notification
|
||||
if let NotifyState::Enabled(ref not) = notify_state {
|
||||
let _ = not.show_notification(
|
||||
"Dimming Reminder",
|
||||
"You have dimming disabled!",
|
||||
"notification-icon",
|
||||
(config.notification_timeout as i32) * 5,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
"enable" => {
|
||||
trace!("enable dispatched");
|
||||
|
|
Loading…
Reference in a new issue