mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
ROGCC: Use tokio instead of smol
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user