diff --git a/rog-control-center/src/main.rs b/rog-control-center/src/main.rs index f194b840..82ef65d3 100644 --- a/rog-control-center/src/main.rs +++ b/rog-control-center/src/main.rs @@ -33,9 +33,11 @@ fn main() -> Result<(), Box> { let anime_notified = Arc::new(AtomicBool::new(false)); let profiles_notified = Arc::new(AtomicBool::new(false)); let fans_notified = Arc::new(AtomicBool::new(false)); + let notifs_enabled = Arc::new(AtomicBool::new(config.enable_notifications)); // TODO: change this to an error instead of the nested unwraps, then use to // display a bare box app with error message. let states = PageDataStates::new( + notifs_enabled.clone(), charge_notified.clone(), bios_notified.clone(), aura_notified.clone(), @@ -54,6 +56,7 @@ fn main() -> Result<(), Box> { anime_notified, profiles_notified, fans_notified, + notifs_enabled, )?; } diff --git a/rog-control-center/src/notify.rs b/rog-control-center/src/notify.rs index a73a6727..29203908 100644 --- a/rog-control-center/src/notify.rs +++ b/rog-control-center/src/notify.rs @@ -51,12 +51,16 @@ pub fn start_notifications( anime_notified: Arc, profiles_notified: Arc, _fans_notified: Arc, + notifs_enabled: Arc, ) -> Result<(), Box> { let last_notification: SharedHandle = Arc::new(Mutex::new(None)); let executor = Executor::new(); // BIOS notif - let x = last_notification.clone(); + let last_notif = last_notification.clone(); + let notifs_enabled1 = notifs_enabled.clone(); + let bios_notified1 = bios_notified.clone(); + // TODO: make a macro or generic function or something... executor .spawn(async move { let conn = zbus::Connection::system().await.unwrap(); @@ -64,10 +68,12 @@ pub fn start_notifications( if let Ok(p) = proxy.receive_notify_post_boot_sound().await { p.for_each(|e| { if let Ok(out) = e.args() { - if let Ok(ref mut lock) = x.try_lock() { - notify!(do_post_sound_notif, lock, &out.sound()); + if notifs_enabled1.load(Ordering::SeqCst) { + if let Ok(ref mut lock) = last_notif.try_lock() { + notify!(do_post_sound_notif, lock, &out.sound()); + } } - bios_notified.store(true, Ordering::SeqCst); + bios_notified1.store(true, Ordering::SeqCst); } future::ready(()) }) @@ -76,8 +82,23 @@ pub fn start_notifications( }) .detach(); + executor + .spawn(async move { + let conn = zbus::Connection::system().await.unwrap(); + let proxy = RogBiosProxy::new(&conn).await.unwrap(); + if let Ok(p) = proxy.receive_notify_panel_overdrive().await { + p.for_each(|_| { + bios_notified.store(true, Ordering::SeqCst); + future::ready(()) + }) + .await; + }; + }) + .detach(); + // Charge notif - let x = last_notification.clone(); + let last_notif = last_notification.clone(); + let notifs_enabled1 = notifs_enabled.clone(); executor .spawn(async move { let conn = zbus::Connection::system().await.unwrap(); @@ -85,8 +106,10 @@ pub fn start_notifications( if let Ok(p) = proxy.receive_notify_charge().await { p.for_each(|e| { if let Ok(out) = e.args() { - if let Ok(ref mut lock) = x.try_lock() { - notify!(do_charge_notif, lock, &out.limit); + if notifs_enabled1.load(Ordering::SeqCst) { + if let Ok(ref mut lock) = last_notif.try_lock() { + notify!(do_charge_notif, lock, &out.limit); + } } charge_notified.store(true, Ordering::SeqCst); } @@ -98,7 +121,8 @@ pub fn start_notifications( .detach(); // Profile notif - let x = last_notification.clone(); + let last_notif = last_notification.clone(); + let notifs_enabled1 = notifs_enabled.clone(); executor .spawn(async move { let conn = zbus::Connection::system().await.unwrap(); @@ -106,8 +130,10 @@ pub fn start_notifications( if let Ok(p) = proxy.receive_notify_profile().await { p.for_each(|e| { if let Ok(out) = e.args() { - if let Ok(ref mut lock) = x.try_lock() { - notify!(do_thermal_notif, lock, &out.profile); + if notifs_enabled1.load(Ordering::SeqCst) { + if let Ok(ref mut lock) = last_notif.try_lock() { + notify!(do_thermal_notif, lock, &out.profile); + } } profiles_notified.store(true, Ordering::SeqCst); } @@ -119,8 +145,9 @@ pub fn start_notifications( .detach(); // LED notif - let x = last_notification.clone(); - let a = aura_notified.clone(); + let last_notif = last_notification.clone(); + let aura_notif = aura_notified.clone(); + let notifs_enabled1 = notifs_enabled.clone(); executor .spawn(async move { let conn = zbus::Connection::system().await.unwrap(); @@ -128,10 +155,12 @@ pub fn start_notifications( if let Ok(p) = proxy.receive_notify_led().await { p.for_each(|e| { if let Ok(out) = e.args() { - if let Ok(ref mut lock) = x.try_lock() { - notify!(do_led_notif, lock, &out.data); + if notifs_enabled1.load(Ordering::SeqCst) { + if let Ok(ref mut lock) = last_notif.try_lock() { + notify!(do_led_notif, lock, &out.data); + } } - a.store(true, Ordering::SeqCst); + aura_notif.store(true, Ordering::SeqCst); } future::ready(()) }) @@ -145,13 +174,8 @@ pub fn start_notifications( let conn = zbus::Connection::system().await.unwrap(); let proxy = LedProxy::new(&conn).await.unwrap(); if let Ok(p) = proxy.receive_notify_power_states().await { - p.for_each(|e| { - if let Ok(_out) = e.args() { - // if let Ok(ref mut lock) = last_notification.try_lock() { - // notify!(do_led_notif, lock, &out.data); - // } - aura_notified.store(true, Ordering::SeqCst); - } + p.for_each(|_| { + aura_notified.store(true, Ordering::SeqCst); future::ready(()) }) .await; @@ -164,13 +188,8 @@ pub fn start_notifications( let conn = zbus::Connection::system().await.unwrap(); let proxy = AnimeProxy::new(&conn).await.unwrap(); if let Ok(p) = proxy.receive_power_states().await { - p.for_each(|e| { - if let Ok(_out) = e.args() { - // if let Ok(ref mut lock) = last_notification.try_lock() { - // notify!(do_led_notif, lock, &out.data); - // } - anime_notified.store(true, Ordering::SeqCst); - } + p.for_each(|_| { + anime_notified.store(true, Ordering::SeqCst); future::ready(()) }) .await; diff --git a/rog-control-center/src/page_states.rs b/rog-control-center/src/page_states.rs index 4c7e5015..74d4ec11 100644 --- a/rog-control-center/src/page_states.rs +++ b/rog-control-center/src/page_states.rs @@ -218,6 +218,7 @@ impl AnimeState { #[derive(Debug)] pub struct PageDataStates { + pub notifs_enabled: Arc, pub was_notified: Arc, /// Because much of the app state here is the same as `RogBiosSupportedFunctions` /// we can re-use that structure. @@ -232,6 +233,7 @@ pub struct PageDataStates { impl PageDataStates { pub fn new( + notifs_enabled: Arc, charge_notified: Arc, bios_notified: Arc, aura_notified: Arc, @@ -242,6 +244,7 @@ impl PageDataStates { dbus: &RogDbusClientBlocking, ) -> Self { Self { + notifs_enabled, was_notified: charge_notified, charge_limit: dbus.proxies().charge().limit().unwrap(), bios: BiosState::new(bios_notified, supported, dbus), diff --git a/rog-control-center/src/widgets/system_page.rs b/rog-control-center/src/widgets/system_page.rs index 29c645fd..c19c288e 100644 --- a/rog-control-center/src/widgets/system_page.rs +++ b/rog-control-center/src/widgets/system_page.rs @@ -59,6 +59,24 @@ impl<'a> RogApp<'a> { } } + if supported.rog_bios_ctrl.post_sound { + if ui + .add(egui::Checkbox::new( + &mut states.bios.panel_overdrive, + "Panel overdrive", + )) + .changed() + { + dbus.proxies() + .rog_bios() + .set_panel_overdrive(states.bios.panel_overdrive) + .map_err(|err| { + states.error = Some(err.to_string()); + }) + .ok(); + } + } + if supported.rog_bios_ctrl.dedicated_gfx { if ui .add(egui::Checkbox::new( diff --git a/rog-control-center/src/widgets/top_bar.rs b/rog-control-center/src/widgets/top_bar.rs index 723c434d..bedff1c5 100644 --- a/rog-control-center/src/widgets/top_bar.rs +++ b/rog-control-center/src/widgets/top_bar.rs @@ -1,3 +1,5 @@ +use std::sync::atomic::Ordering; + use crate::RogApp; impl<'a> RogApp<'a> { @@ -13,32 +15,19 @@ impl<'a> RogApp<'a> { } }); ui.menu_button("Settings", |ui| { - let (mut in_bg, mut hidden) = - { (config.run_in_background, config.startup_in_background) }; - if ui.checkbox(&mut in_bg, "Run in Background").clicked() { - config.run_in_background = in_bg; - config - .save() - .map_err(|err| { - states.error = Some(err.to_string()); - }) - .ok(); - } - if ui.checkbox(&mut hidden, "Startup Hidden").clicked() { - config.startup_in_background = in_bg; - config - .save() - .map_err(|err| { - states.error = Some(err.to_string()); - }) - .ok(); - } if ui - .checkbox(&mut config.enable_notifications, "Enable Notifications") + .checkbox(&mut config.run_in_background, "Run in Background") .clicked() + || ui + .checkbox(&mut config.startup_in_background, "Startup Hidden") + .clicked() + || ui + .checkbox(&mut config.enable_notifications, "Enable Notifications") + .clicked() { - config.enable_notifications = in_bg; - // TODO: set an atomicbool used in the notif thread + states + .notifs_enabled + .store(config.enable_notifications, Ordering::SeqCst); config .save() .map_err(|err| {