diff --git a/Cargo.lock b/Cargo.lock index 5ebcc63f..12e541df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2062,9 +2062,9 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "smol", "supergfxctl", "tempfile", + "tokio", "toml", "zbus 3.4.0", ] @@ -2436,7 +2436,7 @@ dependencies = [ [[package]] name = "supergfxctl" version = "5.0.2" -source = "git+https://gitlab.com/asus-linux/supergfxctl.git#f8f9a5a843e6960a13a5fd2c02995c7c979cbfba" +source = "git+https://gitlab.com/asus-linux/supergfxctl.git#e551271c53231d650123246cab43ccd42ffe926a" dependencies = [ "env_logger", "gumdrop", @@ -2599,7 +2599,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", + "bytes", "libc", + "memchr", "mio", "num_cpus", "pin-project-lite", @@ -3304,6 +3306,7 @@ dependencies = [ "futures-sink", "futures-util", "hex", + "lazy_static", "nix 0.25.0", "once_cell", "ordered-stream 0.1.1", @@ -3312,6 +3315,7 @@ dependencies = [ "serde_repr", "sha1 0.10.5", "static_assertions", + "tokio", "tracing", "uds_windows", "winapi", diff --git a/rog-control-center/Cargo.toml b/rog-control-center/Cargo.toml index 13b7b2ac..0af2f7c0 100644 --- a/rog-control-center/Cargo.toml +++ b/rog-control-center/Cargo.toml @@ -21,15 +21,13 @@ rog_platform = { path = "../rog-platform" } supergfxctl = { git = "https://gitlab.com/asus-linux/supergfxctl.git" } #supergfxctl = { path = "../../supergfxctl" } -smol.workspace = true - +tokio.workspace = true serde.workspace = true toml.workspace = true serde_json.workspace = true serde_derive.workspace = true zbus.workspace = true dirs.workspace = true - notify-rust.workspace = true nix = "^0.20.0" diff --git a/rog-control-center/src/app.rs b/rog-control-center/src/app.rs index f63031b7..847364fe 100644 --- a/rog-control-center/src/app.rs +++ b/rog-control-center/src/app.rs @@ -103,7 +103,7 @@ impl<'a> RogApp<'a> { } impl<'a> eframe::App for RogApp<'a> { - /// Called each time the UI needs repainting, which may be many times per second. + /// Called each time the UI needs repainting, which may be many times per second. /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { let Self { diff --git a/rog-control-center/src/error.rs b/rog-control-center/src/error.rs index a78cd468..b2f839e8 100644 --- a/rog-control-center/src/error.rs +++ b/rog-control-center/src/error.rs @@ -10,7 +10,7 @@ pub enum Error { ConfigLockFail, XdgVars, Zbus(zbus::Error), - Notification(notify_rust::error::Error) + Notification(notify_rust::error::Error), } impl fmt::Display for Error { diff --git a/rog-control-center/src/main.rs b/rog-control-center/src/main.rs index 00044cbc..232a4e7c 100644 --- a/rog-control-center/src/main.rs +++ b/rog-control-center/src/main.rs @@ -1,12 +1,12 @@ use eframe::NativeOptions; use rog_aura::layouts::KeyLayout; use rog_control_center::{ - error::Result, - config::Config, get_ipc_file, notify::start_notifications, on_tmp_dir_exists, + config::Config, error::Result, get_ipc_file, notify::start_notifications, on_tmp_dir_exists, page_states::PageDataStates, print_versions, startup_error::AppErrorShow, RogApp, RogDbusClientBlocking, SHOWING_GUI, SHOW_GUI, }; use rog_platform::supported::SupportedFunctions; +use tokio::runtime::Runtime; use std::{ fs::OpenOptions, @@ -24,6 +24,11 @@ const BOARD_NAME: &str = "/sys/class/dmi/id/board_name"; fn main() -> Result<()> { print_versions(); + // start tokio + let rt = Runtime::new().expect("Unable to create Runtime"); + // Enter the runtime so that `tokio::spawn` is available immediately. + let _enter = rt.enter(); + let native_options = eframe::NativeOptions { vsync: true, decorated: true, @@ -88,7 +93,9 @@ fn main() -> Result<()> { Err(_) => on_tmp_dir_exists().unwrap(), }; - let states = setup_page_state_and_notifs(layout.clone(), &config, native_options.clone(), &dbus).unwrap(); + let states = + setup_page_state_and_notifs(layout.clone(), &config, native_options.clone(), &dbus) + .unwrap(); loop { if !start_closed { @@ -110,6 +117,11 @@ fn main() -> Result<()> { } } } + + // loop { + // // This is just a blocker to idle and ensure the reator reacts + // sleep(Duration::from_millis(1000)).await; + // } Ok(()) } @@ -165,10 +177,7 @@ fn setup_page_state_and_notifs( ) } -fn start_app( - states: PageDataStates, - native_options: NativeOptions, -) -> Result<()> { +fn start_app(states: PageDataStates, native_options: NativeOptions) -> Result<()> { let mut ipc_file = get_ipc_file().unwrap(); ipc_file.write_all(&[SHOWING_GUI]).unwrap(); eframe::run_native( diff --git a/rog-control-center/src/notify.rs b/rog-control-center/src/notify.rs index 4902b102..0314901f 100644 --- a/rog-control-center/src/notify.rs +++ b/rog-control-center/src/notify.rs @@ -6,17 +6,15 @@ use rog_dbus::{ }; use rog_platform::platform::GpuMode; use rog_profiles::Profile; -use smol::{future, Executor}; use std::{ fmt::Display, sync::{ atomic::{AtomicBool, Ordering}, Arc, Mutex, }, - thread::spawn, }; use supergfxctl::pci_device::GfxPower; -use zbus::export::futures_util::StreamExt; +use zbus::export::futures_util::{future, StreamExt}; const NOTIF_HEADER: &str = "ROG Control"; @@ -32,8 +30,7 @@ macro_rules! notify { } macro_rules! recv_notif { - ($executor:ident, - $proxy:ident, + ($proxy:ident, $signal:ident, $was_notified:ident, $last_notif:ident, @@ -45,8 +42,7 @@ macro_rules! recv_notif { let notifs_enabled1 = $notif_enabled.clone(); let notified = $was_notified.clone(); // TODO: make a macro or generic function or something... - $executor - .spawn(async move { + tokio::spawn(async move { let conn = zbus::Connection::system().await.unwrap(); let proxy = $proxy::new(&conn).await.unwrap(); if let Ok(p) = proxy.$signal().await { @@ -63,8 +59,7 @@ macro_rules! recv_notif { }) .await; }; - }) - .detach(); + }); }; } @@ -81,10 +76,8 @@ pub fn start_notifications( ) -> Result<()> { let last_notification: SharedHandle = Arc::new(Mutex::new(None)); - let executor = Executor::new(); // BIOS notif recv_notif!( - executor, RogBiosProxy, receive_notify_post_boot_sound, bios_notified, @@ -96,7 +89,6 @@ pub fn start_notifications( ); recv_notif!( - executor, RogBiosProxy, receive_notify_panel_od, bios_notified, @@ -108,7 +100,6 @@ pub fn start_notifications( ); recv_notif!( - executor, RogBiosProxy, receive_notify_dgpu_disable, bios_notified, @@ -120,7 +111,6 @@ pub fn start_notifications( ); recv_notif!( - executor, RogBiosProxy, receive_notify_egpu_enable, bios_notified, @@ -132,7 +122,6 @@ pub fn start_notifications( ); recv_notif!( - executor, RogBiosProxy, receive_notify_gpu_mux_mode, bios_notified, @@ -145,7 +134,6 @@ pub fn start_notifications( // Charge notif recv_notif!( - executor, PowerProxy, receive_notify_charge_control_end_threshold, charge_notified, @@ -157,7 +145,6 @@ pub fn start_notifications( ); recv_notif!( - executor, PowerProxy, receive_notify_mains_online, bios_notified, @@ -170,7 +157,6 @@ pub fn start_notifications( // Profile notif recv_notif!( - executor, ProfileProxy, receive_notify_profile, profiles_notified, @@ -184,7 +170,6 @@ pub fn start_notifications( // LED notif recv_notif!( - executor, LedProxy, receive_notify_led, aura_notified, @@ -195,73 +180,64 @@ pub fn start_notifications( do_notification ); - executor - .spawn(async move { - let conn = zbus::Connection::system().await.unwrap(); - let proxy = LedProxy::new(&conn).await.unwrap(); - if let Ok(p) = proxy.receive_all_signals().await { - p.for_each(|_| { - aura_notified.store(true, Ordering::SeqCst); - future::ready(()) - }) - .await; - }; - }) - .detach(); + tokio::spawn(async move { + let conn = zbus::Connection::system().await.unwrap(); + let proxy = LedProxy::new(&conn).await.unwrap(); + if let Ok(p) = proxy.receive_all_signals().await { + p.for_each(|_| { + aura_notified.store(true, Ordering::SeqCst); + future::ready(()) + }) + .await; + }; + }); - executor - .spawn(async move { - 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(|_| { - anime_notified.store(true, Ordering::SeqCst); - future::ready(()) - }) - .await; - }; - }) - .detach(); + tokio::spawn(async move { + 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(|_| { + anime_notified.store(true, Ordering::SeqCst); + future::ready(()) + }) + .await; + }; + }); let notifs_enabled1 = notifs_enabled.clone(); let last_notif = last_notification.clone(); let bios_notified1 = bios_notified.clone(); - executor - .spawn(async move { - let conn = zbus::Connection::system().await.unwrap(); - let proxy = supergfxctl::zbus_proxy::DaemonProxy::new(&conn) - .await - .unwrap(); - if let Ok(p) = proxy.receive_notify_gfx_status().await { - p.for_each(|e| { - if let Ok(out) = e.args() { - if notifs_enabled1.load(Ordering::SeqCst) { - let status = out.status(); - if *status != GfxPower::Unknown { - // Required check because status cycles through active/unknown/suspended - if let Ok(ref mut lock) = last_notif.try_lock() { - notify!( - do_notification( - "dGPU status changed:", - &format!("{status:?}",) - ), - lock - ); - } + tokio::spawn(async move { + let conn = zbus::Connection::system().await.unwrap(); + let proxy = supergfxctl::zbus_proxy::DaemonProxy::new(&conn) + .await + .unwrap(); + if let Ok(p) = proxy.receive_notify_gfx_status().await { + p.for_each(|e| { + if let Ok(out) = e.args() { + if notifs_enabled1.load(Ordering::SeqCst) { + let status = out.status(); + if *status != GfxPower::Unknown { + // Required check because status cycles through active/unknown/suspended + if let Ok(ref mut lock) = last_notif.try_lock() { + notify!( + do_notification( + "dGPU status changed:", + &format!("{status:?}",) + ), + lock + ); } } } - bios_notified1.store(true, Ordering::SeqCst); - future::ready(()) - }) - .await; - }; - }) - .detach(); - - spawn(move || loop { - smol::block_on(executor.tick()); + } + bios_notified1.store(true, Ordering::SeqCst); + future::ready(()) + }) + .await; + }; }); + Ok(()) }