Cleanup after changes from Platform dbus rework

This commit is contained in:
Luke D. Jones
2023-11-18 22:36:55 +13:00
parent 1f696508e7
commit f6e4cc0626
9 changed files with 143 additions and 101 deletions

View File

@@ -39,13 +39,13 @@ pub struct BiosState {
impl BiosState {
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
Ok(Self {
post_sound: if supported.rog_bios_ctrl.post_sound {
dbus.proxies().rog_bios().post_boot_sound()? != 0
post_sound: if supported.rog_bios_ctrl.post_animation_sound {
dbus.proxies().rog_bios().post_animation_sound()?
} else {
false
},
dedicated_gfx: if supported.rog_bios_ctrl.gpu_mux {
dbus.proxies().rog_bios().gpu_mux_mode()?
GpuMode::from(dbus.proxies().rog_bios().gpu_mux_mode()?)
} else {
GpuMode::NotSupported
},

View File

@@ -325,7 +325,7 @@ impl ROGTray {
let mut reboot_required = false;
if let Ok(mode) = gfx_dbus.gpu_mux_mode() {
let mode = match mode {
let mode = match GpuMode::from(mode) {
GpuMode::Discrete => GfxMode::AsusMuxDgpu,
_ => GfxMode::Hybrid,
};

View File

@@ -37,11 +37,11 @@ static mut POWER_BAT_CMD: Option<Command> = None;
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct EnabledNotifications {
pub receive_notify_post_boot_sound: bool,
pub receive_notify_panel_od: bool,
pub receive_notify_mini_led_mode: bool,
pub receive_notify_dgpu_disable: bool,
pub receive_notify_egpu_enable: bool,
pub receive_post_animation_sound_changed: bool,
pub receive_panel_od_changed: bool,
pub receive_mini_led_mode_changed: bool,
pub receive_dgpu_disable_changed: bool,
pub receive_egpu_enable_changed: bool,
pub receive_notify_gpu_mux_mode: bool,
pub receive_notify_charge_control_end_threshold: bool,
pub receive_notify_mains_online: bool,
@@ -57,11 +57,11 @@ pub struct EnabledNotifications {
impl Default for EnabledNotifications {
fn default() -> Self {
Self {
receive_notify_post_boot_sound: false,
receive_notify_panel_od: true,
receive_notify_mini_led_mode: true,
receive_notify_dgpu_disable: true,
receive_notify_egpu_enable: true,
receive_post_animation_sound_changed: false,
receive_panel_od_changed: true,
receive_mini_led_mode_changed: true,
receive_dgpu_disable_changed: true,
receive_egpu_enable_changed: true,
receive_notify_gpu_mux_mode: true,
receive_notify_charge_control_end_threshold: true,
receive_notify_mains_online: false,
@@ -127,6 +127,49 @@ macro_rules! recv_notif {
};
}
macro_rules! recv_changed {
($proxy:ident,
$signal:ident,
$last_notif:ident,
$notif_enabled:ident,
$page_states:ident,
($($args: tt)*),
// ($($out_arg:tt)+),
$msg:literal,
$notifier:ident) => {
let notifs_enabled1 = $notif_enabled.clone();
let page_states1 = $page_states.clone();
tokio::spawn(async move {
let conn = zbus::Connection::system().await.map_err(|e| {
log::error!("zbus signal: {}: {e}", stringify!($signal));
e
}).unwrap();
let proxy = $proxy::new(&conn).await.map_err(|e| {
log::error!("zbus signal: {}: {e}", stringify!($signal));
e
}).unwrap();
info!("Started zbus signal thread: {}", stringify!($signal));
while let Some(e) = proxy.$signal().await.next().await {
if let Ok(out) = e.get().await {
if let Ok(config) = notifs_enabled1.lock() {
if config.all_enabled && config.$signal {
trace!("zbus signal {}", stringify!($signal));
$notifier($msg, &out).ok();
}
}
if let Ok(mut lock) = page_states1.lock() {
lock.$($args)+ = out;
lock.set_notified();
}
}
sleep(Duration::from_millis(500)).await;
}
});
};
}
pub fn start_notifications(
config: &Config,
page_states: &Arc<Mutex<SystemState>>,
@@ -157,62 +200,57 @@ pub fn start_notifications(
}
// BIOS notif
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_post_boot_sound,
receive_post_animation_sound_changed,
last_notification,
enabled_notifications,
page_states,
(bios.post_sound),
(on),
"BIOS Post sound",
do_notification
);
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_panel_od,
receive_panel_od_changed,
last_notification,
enabled_notifications,
page_states,
(bios.panel_overdrive),
(overdrive),
"Panel Overdrive enabled:",
do_notification
);
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_mini_led_mode,
receive_mini_led_mode_changed,
last_notification,
enabled_notifications,
page_states,
(bios.mini_led_mode),
(on),
"MiniLED mode enabled:",
do_notification
);
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_dgpu_disable,
receive_dgpu_disable_changed,
last_notification,
enabled_notifications,
page_states,
(bios.dgpu_disable),
(disable),
"BIOS dGPU disabled",
do_notification
);
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_egpu_enable,
receive_egpu_enable_changed,
last_notification,
enabled_notifications,
page_states,
(bios.egpu_enable),
(enable),
"BIOS eGPU enabled",
do_notification
);
@@ -314,7 +352,7 @@ pub fn start_notifications(
e
})
.unwrap();
if let Ok(mut p) = proxy.receive_device_state().await {
if let Ok(mut p) = proxy.receive_notify_device_state().await {
info!("Started zbus signal thread: receive_device_state");
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
@@ -345,25 +383,23 @@ pub fn start_notifications(
let mut actual_mux_mode = GpuMode::Error;
if let Ok(mode) = proxy.gpu_mux_mode().await {
actual_mux_mode = mode;
actual_mux_mode = GpuMode::from(mode);
}
if let Ok(mut p) = proxy.receive_notify_gpu_mux_mode().await {
info!("Started zbus signal thread: receive_notify_gpu_mux_mode");
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
if out.mode == actual_mux_mode {
continue;
}
if let Ok(mut lock) = page_states1.lock() {
lock.bios.dedicated_gfx = out.mode;
lock.set_notified();
}
do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &out.mode)
.ok();
info!("Started zbus signal thread: receive_notify_gpu_mux_mode");
while let Some(e) = proxy.receive_gpu_mux_mode_changed().await.next().await {
if let Ok(out) = e.get().await {
let mode = GpuMode::from(out);
if mode == actual_mux_mode {
continue;
}
if let Ok(mut lock) = page_states1.lock() {
lock.bios.dedicated_gfx = mode;
lock.set_notified();
}
do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &mode).ok();
}
};
}
});
if let Ok(lock) = page_states.try_lock() {

View File

@@ -51,13 +51,13 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_dgpu_disable,
&mut enabled_notifications.receive_dgpu_disable_changed,
"Enable dGPU disablement notification",
)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_egpu_enable,
&mut enabled_notifications.receive_egpu_enable_changed,
"Enable eGPU enablement notification",
)
.clicked()
@@ -81,19 +81,19 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_panel_od,
&mut enabled_notifications.receive_panel_od_changed,
"Enable panel overdrive notification",
)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_mini_led_mode,
&mut enabled_notifications.receive_mini_led_mode_changed,
"Enable MiniLED mode notification",
)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_post_boot_sound,
&mut enabled_notifications.receive_post_animation_sound_changed,
"Enable BIOS post sound notification",
)
.clicked();

View File

@@ -55,7 +55,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
.ok();
}
if supported.rog_bios_ctrl.post_sound
if supported.rog_bios_ctrl.post_animation_sound
&& ui
.add(egui::Checkbox::new(
&mut states.bios.post_sound,
@@ -67,7 +67,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
.asus_dbus
.proxies()
.rog_bios()
.set_post_boot_sound(states.bios.post_sound)
.set_post_animation_sound(states.bios.post_sound)
.map_err(|err| {
states.error = Some(err.to_string());
})
@@ -118,7 +118,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
let mut reboot_required = false;
if let Ok(mode) = states.asus_dbus.proxies().rog_bios().gpu_mux_mode() {
reboot_required = mode != states.bios.dedicated_gfx;
reboot_required = GpuMode::from(mode) != states.bios.dedicated_gfx;
}
ui.group(|ui| {