ROGCC: splatter log messages everywhere. Rename state control

This commit is contained in:
Luke D. Jones
2022-11-16 20:32:00 +13:00
parent 73b1a7050a
commit ad79adcbfa
20 changed files with 250 additions and 89 deletions

View File

@@ -145,7 +145,7 @@ impl AnimeConfig {
.read(true) .read(true)
.write(true) .write(true)
.create(true) .create(true)
.open(&ANIME_CONFIG_PATH) .open(ANIME_CONFIG_PATH)
.unwrap_or_else(|_| { .unwrap_or_else(|_| {
panic!( panic!(
"The file {} or directory /etc/asusd/ is missing", "The file {} or directory /etc/asusd/ is missing",
@@ -249,7 +249,7 @@ impl AnimeConfig {
pub fn read(&mut self) { pub fn read(&mut self) {
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.read(true) .read(true)
.open(&ANIME_CONFIG_PATH) .open(ANIME_CONFIG_PATH)
.unwrap_or_else(|err| panic!("Error reading {}: {}", ANIME_CONFIG_PATH, err)); .unwrap_or_else(|err| panic!("Error reading {}: {}", ANIME_CONFIG_PATH, err));
let mut buf = String::new(); let mut buf = String::new();
if let Ok(l) = file.read_to_string(&mut buf) { if let Ok(l) = file.read_to_string(&mut buf) {

View File

@@ -192,7 +192,7 @@ impl AuraConfig {
.read(true) .read(true)
.write(true) .write(true)
.create(true) .create(true)
.open(&AURA_CONFIG_PATH) .open(AURA_CONFIG_PATH)
.unwrap_or_else(|_| { .unwrap_or_else(|_| {
panic!( panic!(
"The file {} or directory /etc/asusd/ is missing", "The file {} or directory /etc/asusd/ is missing",
@@ -264,7 +264,7 @@ impl AuraConfig {
pub fn read(&mut self) { pub fn read(&mut self) {
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.read(true) .read(true)
.open(&AURA_CONFIG_PATH) .open(AURA_CONFIG_PATH)
.unwrap_or_else(|err| panic!("Error reading {}: {}", AURA_CONFIG_PATH, err)); .unwrap_or_else(|err| panic!("Error reading {}: {}", AURA_CONFIG_PATH, err));
let mut buf = String::new(); let mut buf = String::new();
if let Ok(l) = file.read_to_string(&mut buf) { if let Ok(l) = file.read_to_string(&mut buf) {

View File

@@ -11,12 +11,12 @@ use egui::{Button, RichText};
use rog_platform::supported::SupportedFunctions; use rog_platform::supported::SupportedFunctions;
use crate::{ use crate::{
config::Config, error::Result, page_states::PageDataStates, Page, RogDbusClientBlocking, config::Config, error::Result, system_state::SystemState, Page, RogDbusClientBlocking,
}; };
pub struct RogApp { pub struct RogApp {
pub page: Page, pub page: Page,
pub states: Arc<Mutex<PageDataStates>>, pub states: Arc<Mutex<SystemState>>,
pub supported: SupportedFunctions, pub supported: SupportedFunctions,
// TODO: can probably just open and read whenever // TODO: can probably just open and read whenever
pub config: Config, pub config: Config,
@@ -34,7 +34,7 @@ impl RogApp {
/// Called once before the first frame. /// Called once before the first frame.
pub fn new( pub fn new(
config: Config, config: Config,
states: Arc<Mutex<PageDataStates>>, states: Arc<Mutex<SystemState>>,
_cc: &eframe::CreationContext<'_>, _cc: &eframe::CreationContext<'_>,
) -> Result<Self> { ) -> Result<Self> {
let (dbus, _) = RogDbusClientBlocking::new()?; let (dbus, _) = RogDbusClientBlocking::new()?;

View File

@@ -1,9 +1,9 @@
use log::{error, info, warn};
use serde_derive::{Deserialize, Serialize};
use std::{ use std::{
fs::{create_dir, OpenOptions}, fs::{create_dir, OpenOptions},
io::{Read, Write}, io::{Read, Write},
}; };
use serde_derive::{Deserialize, Serialize};
//use log::{error, info, warn}; //use log::{error, info, warn};
use crate::{error::Error, notify::EnabledNotifications}; use crate::{error::Error, notify::EnabledNotifications};
@@ -34,14 +34,17 @@ impl Default for Config {
impl Config { impl Config {
pub fn load() -> Result<Config, Error> { pub fn load() -> Result<Config, Error> {
let mut path = if let Some(dir) = dirs::config_dir() { let mut path = if let Some(dir) = dirs::config_dir() {
info!("Found XDG config dir {dir:?}");
dir dir
} else { } else {
error!("Could not get XDG config dir");
return Err(Error::XdgVars); return Err(Error::XdgVars);
}; };
path.push(CFG_DIR); path.push(CFG_DIR);
if !path.exists() { if !path.exists() {
create_dir(path.clone())?; create_dir(path.clone())?;
info!("Created {path:?}");
} }
path.push(CFG_FILE_NAME); path.push(CFG_FILE_NAME);
@@ -56,11 +59,13 @@ impl Config {
if let Ok(read_len) = file.read_to_string(&mut buf) { if let Ok(read_len) = file.read_to_string(&mut buf) {
if read_len == 0 { if read_len == 0 {
warn!("Zero len read of Config file");
let default = Config::default(); let default = Config::default();
let t = toml::to_string_pretty(&default).unwrap(); let t = toml::to_string_pretty(&default).unwrap();
file.write_all(t.as_bytes())?; file.write_all(t.as_bytes())?;
return Ok(default); return Ok(default);
} else if let Ok(data) = toml::from_str::<Config>(&buf) { } else if let Ok(data) = toml::from_str::<Config>(&buf) {
info!("Loaded config file {path:?}");
return Ok(data); return Ok(data);
} }
} }
@@ -77,6 +82,7 @@ impl Config {
path.push(CFG_DIR); path.push(CFG_DIR);
if !path.exists() { if !path.exists() {
create_dir(path.clone())?; create_dir(path.clone())?;
info!("Created {path:?}");
} }
path.push(CFG_FILE_NAME); path.push(CFG_FILE_NAME);
@@ -90,6 +96,7 @@ impl Config {
self.enabled_notifications = enabled_notifications.clone(); self.enabled_notifications = enabled_notifications.clone();
let t = toml::to_string_pretty(&self).unwrap(); let t = toml::to_string_pretty(&self).unwrap();
file.write_all(t.as_bytes())?; file.write_all(t.as_bytes())?;
info!("Saved config file {path:?}");
Ok(()) Ok(())
} }
} }

View File

@@ -14,9 +14,9 @@ pub mod error;
#[cfg(feature = "mocking")] #[cfg(feature = "mocking")]
pub mod mocking; pub mod mocking;
pub mod notify; pub mod notify;
pub mod page_states;
pub mod pages; pub mod pages;
pub mod startup_error; pub mod startup_error;
pub mod system_state;
pub mod tray; pub mod tray;
pub mod widgets; pub mod widgets;

View File

@@ -1,11 +1,11 @@
use eframe::{IconData, NativeOptions}; use eframe::{IconData, NativeOptions};
use log::{error, LevelFilter}; use log::{error, info, LevelFilter};
use rog_aura::layouts::KeyLayout; use rog_aura::layouts::KeyLayout;
use rog_control_center::notify::EnabledNotifications; use rog_control_center::notify::EnabledNotifications;
use rog_control_center::tray::init_tray; use rog_control_center::tray::init_tray;
use rog_control_center::{ use rog_control_center::{
config::Config, error::Result, 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, print_versions, startup_error::AppErrorShow, system_state::SystemState, RogApp,
RogDbusClientBlocking, SHOWING_GUI, SHOW_GUI, RogDbusClientBlocking, SHOWING_GUI, SHOW_GUI,
}; };
use rog_platform::supported::SupportedFunctions; use rog_platform::supported::SupportedFunctions;
@@ -118,7 +118,7 @@ fn main() -> Result<()> {
Err(_) => on_tmp_dir_exists().unwrap(), Err(_) => on_tmp_dir_exists().unwrap(),
}; };
let states = setup_page_state_and_notifs(layout, enabled_notifications, &supported).unwrap(); let states = setup_page_state_and_notifs(layout, enabled_notifications, &supported)?;
init_tray(supported, states.clone()); init_tray(supported, states.clone());
@@ -127,7 +127,7 @@ fn main() -> Result<()> {
start_app(states.clone(), native_options.clone())?; start_app(states.clone(), native_options.clone())?;
} }
let config = Config::load().unwrap(); let config = Config::load()?;
if !config.run_in_background { if !config.run_in_background {
break; break;
} }
@@ -136,7 +136,7 @@ fn main() -> Result<()> {
let mut buf = [0u8; 4]; let mut buf = [0u8; 4];
// blocks until it is read, typically the read will happen after a second // blocks until it is read, typically the read will happen after a second
// process writes to the IPC (so there is data to actually read) // process writes to the IPC (so there is data to actually read)
if get_ipc_file().unwrap().read(&mut buf).is_ok() && buf[0] == SHOW_GUI { if get_ipc_file()?.read(&mut buf).is_ok() && buf[0] == SHOW_GUI {
start_closed = false; start_closed = false;
continue; continue;
} }
@@ -154,8 +154,8 @@ fn setup_page_state_and_notifs(
keyboard_layout: KeyLayout, keyboard_layout: KeyLayout,
enabled_notifications: Arc<Mutex<EnabledNotifications>>, enabled_notifications: Arc<Mutex<EnabledNotifications>>,
supported: &SupportedFunctions, supported: &SupportedFunctions,
) -> Result<Arc<Mutex<PageDataStates>>> { ) -> Result<Arc<Mutex<SystemState>>> {
let page_states = Arc::new(Mutex::new(PageDataStates::new( let page_states = Arc::new(Mutex::new(SystemState::new(
keyboard_layout, keyboard_layout,
enabled_notifications.clone(), enabled_notifications.clone(),
supported, supported,
@@ -166,9 +166,9 @@ fn setup_page_state_and_notifs(
Ok(page_states) Ok(page_states)
} }
fn start_app(states: Arc<Mutex<PageDataStates>>, native_options: NativeOptions) -> Result<()> { fn start_app(states: Arc<Mutex<SystemState>>, native_options: NativeOptions) -> Result<()> {
let mut ipc_file = get_ipc_file().unwrap(); let mut ipc_file = get_ipc_file()?;
ipc_file.write_all(&[SHOWING_GUI]).unwrap(); ipc_file.write_all(&[SHOWING_GUI])?;
eframe::run_native( eframe::run_native(
"ROG Control Center", "ROG Control Center",
native_options, native_options,
@@ -202,6 +202,7 @@ fn load_icon() -> IconData {
rgba = ras.as_u8_slice().to_vec(); rgba = ras.as_u8_slice().to_vec();
width = ras.width(); width = ras.width();
height = ras.height(); height = ras.height();
info!("Loaded app icon. Not actually supported in Wayland yet");
} }
} }
} else { } else {

View File

@@ -1,4 +1,5 @@
use crate::{config::Config, error::Result, page_states::PageDataStates}; use crate::{config::Config, error::Result, system_state::SystemState};
use log::{error, info, trace};
use notify_rust::{Hint, Notification, NotificationHandle, Urgency}; use notify_rust::{Hint, Notification, NotificationHandle, Urgency};
use rog_dbus::{ use rog_dbus::{
zbus_anime::AnimeProxy, zbus_led::LedProxy, zbus_platform::RogBiosProxy, zbus_anime::AnimeProxy, zbus_led::LedProxy, zbus_platform::RogBiosProxy,
@@ -90,14 +91,22 @@ macro_rules! recv_notif {
let page_states1 = $page_states.clone(); let page_states1 = $page_states.clone();
tokio::spawn(async move { tokio::spawn(async move {
let conn = zbus::Connection::system().await.unwrap(); let conn = zbus::Connection::system().await.map_err(|e| {
let proxy = $proxy::new(&conn).await.unwrap(); 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();
if let Ok(mut p) = proxy.$signal().await { if let Ok(mut p) = proxy.$signal().await {
info!("Started zbus signal thread: {}", stringify!($signal));
while let Some(e) = p.next().await { while let Some(e) = p.next().await {
if let Ok(out) = e.args() { if let Ok(out) = e.args() {
if let Ok(config) = notifs_enabled1.lock() { if let Ok(config) = notifs_enabled1.lock() {
if config.all_enabled && config.$signal { if config.all_enabled && config.$signal {
if let Ok(ref mut lock) = last_notif.lock() { if let Ok(ref mut lock) = last_notif.lock() {
trace!("zbus signal {} locked last_notif", stringify!($signal));
notify!($notifier($msg, &out.$($out_arg)+()), lock); notify!($notifier($msg, &out.$($out_arg)+()), lock);
} }
} }
@@ -116,7 +125,7 @@ macro_rules! recv_notif {
type SharedHandle = Arc<Mutex<Option<NotificationHandle>>>; type SharedHandle = Arc<Mutex<Option<NotificationHandle>>>;
pub fn start_notifications( pub fn start_notifications(
page_states: Arc<Mutex<PageDataStates>>, page_states: Arc<Mutex<SystemState>>,
enabled_notifications: Arc<Mutex<EnabledNotifications>>, enabled_notifications: Arc<Mutex<EnabledNotifications>>,
) -> Result<()> { ) -> Result<()> {
let last_notification: SharedHandle = Arc::new(Mutex::new(None)); let last_notification: SharedHandle = Arc::new(Mutex::new(None));
@@ -236,9 +245,22 @@ pub fn start_notifications(
let page_states1 = page_states.clone(); let page_states1 = page_states.clone();
tokio::spawn(async move { tokio::spawn(async move {
let conn = zbus::Connection::system().await.unwrap(); let conn = zbus::Connection::system()
let proxy = AnimeProxy::new(&conn).await.unwrap(); .await
.map_err(|e| {
error!("zbus signal: receive_power_states: {e}");
e
})
.unwrap();
let proxy = AnimeProxy::new(&conn)
.await
.map_err(|e| {
error!("zbus signal: receive_power_states: {e}");
e
})
.unwrap();
if let Ok(p) = proxy.receive_power_states().await { if let Ok(p) = proxy.receive_power_states().await {
info!("Started zbus signal thread: receive_power_states");
p.for_each(|_| { p.for_each(|_| {
if let Ok(_lock) = page_states1.lock() { if let Ok(_lock) = page_states1.lock() {
// TODO: lock.anime. // TODO: lock.anime.
@@ -273,13 +295,30 @@ pub fn start_notifications(
// ); // );
tokio::spawn(async move { tokio::spawn(async move {
let conn = zbus::Connection::system().await.unwrap(); let conn = zbus::Connection::system()
let proxy = SuperProxy::new(&conn).await.unwrap(); .await
.map_err(|e| {
error!("zbus signal: receive_notify_action: {e}");
e
})
.unwrap();
let proxy = SuperProxy::new(&conn)
.await
.map_err(|e| {
error!("zbus signal: receive_notify_action: {e}");
e
})
.unwrap();
if let Ok(mut p) = proxy.receive_notify_action().await { if let Ok(mut p) = proxy.receive_notify_action().await {
info!("Started zbus signal thread: receive_notify_action");
while let Some(e) = p.next().await { while let Some(e) = p.next().await {
if let Ok(out) = e.args() { if let Ok(out) = e.args() {
let action = out.action(); let action = out.action();
do_gfx_action_notif("Gfx mode change requires", &format!("{action:?}",)) do_gfx_action_notif("Gfx mode change requires", &format!("{action:?}",))
.map_err(|e| {
error!("zbus signal: do_gfx_action_notif: {e}");
e
})
.unwrap(); .unwrap();
} }
} }
@@ -289,9 +328,22 @@ pub fn start_notifications(
let notifs_enabled1 = enabled_notifications; let notifs_enabled1 = enabled_notifications;
let last_notif = last_notification; let last_notif = last_notification;
tokio::spawn(async move { tokio::spawn(async move {
let conn = zbus::Connection::system().await.unwrap(); let conn = zbus::Connection::system()
let proxy = SuperProxy::new(&conn).await.unwrap(); .await
.map_err(|e| {
error!("zbus signal: receive_notify_gfx_status: {e}");
e
})
.unwrap();
let proxy = SuperProxy::new(&conn)
.await
.map_err(|e| {
error!("zbus signal: receive_notify_gfx_status: {e}");
e
})
.unwrap();
if let Ok(mut p) = proxy.receive_notify_gfx_status().await { if let Ok(mut p) = proxy.receive_notify_gfx_status().await {
info!("Started zbus signal thread: receive_notify_gfx_status");
while let Some(e) = p.next().await { while let Some(e) = p.next().await {
if let Ok(out) = e.args() { if let Ok(out) = e.args() {
let status = out.status; let status = out.status;

View File

@@ -4,13 +4,13 @@ use egui::Color32;
use rog_aura::{AuraEffect, AuraModeNum}; use rog_aura::{AuraEffect, AuraModeNum};
use crate::{ use crate::{
page_states::PageDataStates, system_state::SystemState,
widgets::{aura_modes_group, keyboard}, widgets::{aura_modes_group, keyboard},
RogApp, RogApp,
}; };
impl RogApp { impl RogApp {
pub fn aura_page(&mut self, states: &mut PageDataStates, ctx: &egui::Context) { pub fn aura_page(&mut self, states: &mut SystemState, ctx: &egui::Context) {
let Self { let Self {
supported, supported,
oscillator1, oscillator1,

View File

@@ -1,5 +1,5 @@
use crate::{ use crate::{
page_states::{FanCurvesState, PageDataStates, ProfilesState}, system_state::{FanCurvesState, ProfilesState, SystemState},
widgets::fan_graphs, widgets::fan_graphs,
RogApp, RogDbusClientBlocking, RogApp, RogDbusClientBlocking,
}; };
@@ -8,7 +8,7 @@ use rog_platform::supported::SupportedFunctions;
use rog_profiles::Profile; use rog_profiles::Profile;
impl RogApp { impl RogApp {
pub fn fan_curve_page(&mut self, states: &mut PageDataStates, ctx: &egui::Context) { pub fn fan_curve_page(&mut self, states: &mut SystemState, ctx: &egui::Context) {
let Self { supported, .. } = self; let Self { supported, .. } = self;
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {

View File

@@ -1,5 +1,5 @@
use crate::{ use crate::{
page_states::PageDataStates, system_state::SystemState,
widgets::{ widgets::{
anime_power_group, app_settings, aura_power_group, platform_profile, rog_bios_group, anime_power_group, app_settings, aura_power_group, platform_profile, rog_bios_group,
}, },
@@ -7,7 +7,7 @@ use crate::{
}; };
impl RogApp { impl RogApp {
pub fn system_page(&mut self, states: &mut PageDataStates, ctx: &egui::Context) { pub fn system_page(&mut self, states: &mut SystemState, ctx: &egui::Context) {
let Self { let Self {
config, supported, .. config, supported, ..
} = self; } = self;

View File

@@ -247,7 +247,9 @@ impl PowerState {
} }
} }
pub struct PageDataStates { /// State stored from system daemons. This is shared with: tray, zbus notifications thread
/// and the GUI app thread.
pub struct SystemState {
pub keyboard_layout: KeyLayout, pub keyboard_layout: KeyLayout,
pub enabled_notifications: Arc<Mutex<EnabledNotifications>>, pub enabled_notifications: Arc<Mutex<EnabledNotifications>>,
/// Because much of the app state here is the same as `RogBiosSupportedFunctions` /// Because much of the app state here is the same as `RogBiosSupportedFunctions`
@@ -268,7 +270,7 @@ pub struct PageDataStates {
pub gfx_dbus: GfxProxyBlocking<'static>, pub gfx_dbus: GfxProxyBlocking<'static>,
} }
impl PageDataStates { impl SystemState {
/// Creates self, including the relevant dbus connections and proixies for internal use /// Creates self, including the relevant dbus connections and proixies for internal use
pub fn new( pub fn new(
keyboard_layout: KeyLayout, keyboard_layout: KeyLayout,
@@ -301,7 +303,7 @@ impl PageDataStates {
} }
} }
impl Default for PageDataStates { impl Default for SystemState {
fn default() -> Self { fn default() -> Self {
let (asus_dbus, conn) = RogDbusClientBlocking::new().unwrap(); let (asus_dbus, conn) = RogDbusClientBlocking::new().unwrap();
let gfx_dbus = GfxProxyBlocking::new(&conn).unwrap(); let gfx_dbus = GfxProxyBlocking::new(&conn).unwrap();

View File

@@ -14,14 +14,14 @@ use gtk::{gio::Icon, prelude::*};
use rog_dbus::zbus_platform::RogBiosProxyBlocking; use rog_dbus::zbus_platform::RogBiosProxyBlocking;
use rog_platform::{platform::GpuMode, supported::SupportedFunctions}; use rog_platform::{platform::GpuMode, supported::SupportedFunctions};
use crate::{error::Result, get_ipc_file, page_states::PageDataStates, SHOW_GUI}; use crate::{error::Result, get_ipc_file, system_state::SystemState, SHOW_GUI};
use libappindicator::{AppIndicator, AppIndicatorStatus}; use libappindicator::{AppIndicator, AppIndicatorStatus};
use supergfxctl::{ use supergfxctl::{
pci_device::{GfxMode, GfxPower}, pci_device::{GfxMode, GfxPower},
zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking, zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking,
}; };
use log::trace; use log::{debug, error, info, trace};
const TRAY_APP_ICON: &str = "rog-control-center"; const TRAY_APP_ICON: &str = "rog-control-center";
const TRAY_LABEL: &str = "ROG Control Center"; const TRAY_LABEL: &str = "ROG Control Center";
@@ -86,13 +86,22 @@ pub struct ROGTray {
impl ROGTray { impl ROGTray {
pub fn new() -> Result<Self> { pub fn new() -> Result<Self> {
let conn = zbus::blocking::Connection::system().unwrap(); let conn = zbus::blocking::Connection::system().map_err(|e| {
error!("ROGTray: {e}");
e
})?;
let rog_tray = Self { let rog_tray = Self {
tray: AppIndicator::new(TRAY_LABEL, TRAY_APP_ICON), tray: AppIndicator::new(TRAY_LABEL, TRAY_APP_ICON),
menu: gtk::Menu::new(), menu: gtk::Menu::new(),
icon: TRAY_APP_ICON, icon: TRAY_APP_ICON,
bios_proxy: RogBiosProxyBlocking::new(&conn).unwrap(), bios_proxy: RogBiosProxyBlocking::new(&conn).map_err(|e| {
gfx_proxy: GfxProxyBlocking::new(&conn).unwrap(), error!("ROGTray: {e}");
e
})?,
gfx_proxy: GfxProxyBlocking::new(&conn).map_err(|e| {
error!("ROGTray: {e}");
e
})?,
}; };
Ok(rog_tray) Ok(rog_tray)
} }
@@ -126,7 +135,11 @@ impl ROGTray {
let menu = gtk::Menu::new(); let menu = gtk::Menu::new();
for item in sub_menu.0.iter() { for item in sub_menu.0.iter() {
item.set_active(item.label().unwrap() == active_label); if let Some(label) = item.label() {
item.set_active(label == active_label);
} else {
item.set_active(false);
}
item.set_no_show_all(false); item.set_no_show_all(false);
item.show_all(); item.show_all();
menu.add(item); menu.add(item);
@@ -135,7 +148,7 @@ impl ROGTray {
header_item.set_submenu(Some(&menu)); header_item.set_submenu(Some(&menu));
} }
fn add_menu_item<F>(&mut self, label: &str, cb: F) fn _add_menu_item<F>(&mut self, label: &str, cb: F)
where where
F: Fn() + Send + 'static, F: Fn() + Send + 'static,
{ {
@@ -183,60 +196,124 @@ impl ROGTray {
self.tray.set_menu(&mut self.menu); self.tray.set_menu(&mut self.menu);
} }
fn set_status(&mut self, status: AppIndicatorStatus) { fn _set_status(&mut self, status: AppIndicatorStatus) {
self.tray.set_status(status) self.tray.set_status(status)
} }
fn menu_add_base(&mut self) { fn menu_add_base(&mut self) {
self.add_icon_menu_item("Open app", "asus_notif_red", move || { self.add_icon_menu_item("Open app", "asus_notif_red", move || {
get_ipc_file().unwrap().write_all(&[SHOW_GUI]).ok(); if let Ok(mut ipc) = get_ipc_file().map_err(|e| {
error!("ROGTray: get_ipc_file: {}", e);
}) {
ipc.write_all(&[SHOW_GUI]).ok();
}
}); });
self.add_separator(); self.add_separator();
debug!("ROGTray: built base menu");
} }
fn menu_add_charge_limit(&mut self, limit: u8) { fn menu_add_charge_limit(&mut self, supported: &SupportedFunctions, limit: u8) {
if supported.charge_ctrl.charge_level_set {
self.add_inactive_label(&format!("Charge limit: {limit}")); self.add_inactive_label(&format!("Charge limit: {limit}"));
debug!("ROGTray: appended charge limit menu");
}
} }
fn menu_add_panel_od(&mut self, panel_od: bool) { fn menu_add_panel_od(&mut self, supported: &SupportedFunctions, panel_od: bool) {
if supported.rog_bios_ctrl.panel_overdrive {
let bios = self.bios_proxy.clone(); let bios = self.bios_proxy.clone();
self.add_check_menu_item("Panel Overdrive", panel_od, move |this| { self.add_check_menu_item("Panel Overdrive", panel_od, move |this| {
bios.set_panel_od(this.is_active()).unwrap(); bios.set_panel_od(this.is_active())
.map_err(|e| {
error!("ROGTray: set_panel_od: {e}");
e
})
.ok();
}); });
debug!("ROGTray: appended panel overdrive menu");
}
} }
fn menu_add_gpu(&mut self, supported: &SupportedFunctions, current_mode: GfxMode) { fn menu_add_gpu(&mut self, supported: &SupportedFunctions, current_mode: GfxMode) {
let gfx_dbus = self.gfx_proxy.clone(); let gfx_dbus = self.gfx_proxy.clone();
let mut gpu_menu = RadioGroup::new("Integrated", move |_| { let mut gpu_menu = RadioGroup::new("Integrated", move |_| {
let mode = gfx_dbus.mode().unwrap(); let mode = gfx_dbus
.mode()
.map_err(|e| {
error!("ROGTray: mode: {e}");
e
})
.unwrap_or(GfxMode::None);
if mode != GfxMode::Integrated { if mode != GfxMode::Integrated {
gfx_dbus.set_mode(&GfxMode::Integrated).unwrap(); gfx_dbus
.set_mode(&GfxMode::Integrated)
.map_err(|e| {
error!("ROGTray: srt_mode: {e}");
e
})
.ok();
} }
}); });
let gfx_dbus = self.gfx_proxy.clone(); let gfx_dbus = self.gfx_proxy.clone();
gpu_menu.add("Hybrid", move |_| { gpu_menu.add("Hybrid", move |_| {
let mode = gfx_dbus.mode().unwrap(); let mode = gfx_dbus
.mode()
.map_err(|e| {
error!("ROGTray: mode: {e}");
e
})
.unwrap_or(GfxMode::None);
if mode != GfxMode::Hybrid { if mode != GfxMode::Hybrid {
gfx_dbus.set_mode(&GfxMode::Hybrid).unwrap(); gfx_dbus
.set_mode(&GfxMode::Hybrid)
.map_err(|e| {
error!("ROGTray: set_mode: {e}");
e
})
.ok();
} }
}); });
if supported.rog_bios_ctrl.gpu_mux { if supported.rog_bios_ctrl.gpu_mux {
let gfx_dbus = self.bios_proxy.clone(); let gfx_dbus = self.bios_proxy.clone();
gpu_menu.add("Ultimate (Reboot required)", move |_| { gpu_menu.add("Ultimate (Reboot required)", move |_| {
let mode = gfx_dbus.gpu_mux_mode().unwrap(); let mode = gfx_dbus
.gpu_mux_mode()
.map_err(|e| {
error!("ROGTray: mode: {e}");
e
})
.unwrap_or(GpuMode::Error);
if mode != GpuMode::Discrete { if mode != GpuMode::Discrete {
gfx_dbus.set_gpu_mux_mode(GpuMode::Discrete).unwrap(); gfx_dbus
.set_gpu_mux_mode(GpuMode::Discrete)
.map_err(|e| {
error!("ROGTray: set_mode: {e}");
e
})
.ok();
} }
}); });
} }
if supported.rog_bios_ctrl.egpu_enable { if supported.rog_bios_ctrl.egpu_enable {
let gfx_dbus = self.gfx_proxy.clone(); let gfx_dbus = self.gfx_proxy.clone();
gpu_menu.add("eGPU", move |_| { gpu_menu.add("eGPU", move |_| {
let mode = gfx_dbus.mode().unwrap(); let mode = gfx_dbus
.mode()
.map_err(|e| {
error!("ROGTray: mode: {e}");
e
})
.unwrap_or(GfxMode::None);
if mode != GfxMode::Egpu { if mode != GfxMode::Egpu {
gfx_dbus.set_mode(&GfxMode::Egpu).unwrap(); gfx_dbus
.set_mode(&GfxMode::Egpu)
.map_err(|e| {
error!("ROGTray: set_mode: {e}");
e
})
.ok();
} }
}); });
} }
@@ -250,10 +327,13 @@ impl ROGTray {
active.as_str(), active.as_str(),
gpu_menu, gpu_menu,
); );
debug!("ROGTray: appended gpu menu");
} }
fn menu_clear(&mut self) { fn menu_clear(&mut self) {
self.menu = gtk::Menu::new(); self.menu = gtk::Menu::new();
debug!("ROGTray: cleared self");
} }
/// Reset GTK menu to internal state, this can be called after clearing and rebuilding the menu too. /// Reset GTK menu to internal state, this can be called after clearing and rebuilding the menu too.
@@ -272,8 +352,8 @@ impl ROGTray {
) { ) {
self.menu_clear(); self.menu_clear();
self.menu_add_base(); self.menu_add_base();
self.menu_add_charge_limit(charge_limit); self.menu_add_charge_limit(supported, charge_limit);
self.menu_add_panel_od(panel_od); self.menu_add_panel_od(supported, panel_od);
self.menu_add_gpu(supported, current_gfx_mode); self.menu_add_gpu(supported, current_gfx_mode);
self.menu_update(); self.menu_update();
} }
@@ -281,17 +361,39 @@ impl ROGTray {
pub fn init_tray( pub fn init_tray(
supported: SupportedFunctions, supported: SupportedFunctions,
states: Arc<Mutex<PageDataStates>>, states: Arc<Mutex<SystemState>>,
) -> Receiver<TrayToApp> { ) -> Receiver<TrayToApp> {
let (send, recv) = channel(); let (send, recv) = channel();
let _send = Arc::new(Mutex::new(send)); let _send = Arc::new(Mutex::new(send));
std::thread::spawn(move || { std::thread::spawn(move || {
gtk::init().unwrap(); // Make this the main thread for gtk if gtk::init()
.map_err(|e| {
error!("ROGTray: gtk init {e}");
e
})
.is_err()
{
return;
} // Make this the main thread for gtk
debug!("init_tray gtk");
let mut tray = ROGTray::new().unwrap(); let mut tray = match ROGTray::new() {
Ok(t) => {
info!("init_tray: built menus");
t
}
Err(e) => {
error!("ROGTray: tray init {e}");
if let Ok(mut states) = states.lock() {
states.error = Some(format!("Could not start tray: {e}"));
}
return;
}
};
tray.rebuild_and_update(&supported, GfxMode::Hybrid, 100, false); tray.rebuild_and_update(&supported, GfxMode::Hybrid, 100, false);
tray.set_icon(TRAY_APP_ICON); tray.set_icon(TRAY_APP_ICON);
info!("Started ROGTray");
loop { loop {
if let Ok(mut lock) = states.lock() { if let Ok(mut lock) = states.lock() {
@@ -303,6 +405,7 @@ pub fn init_tray(
lock.bios.panel_overdrive, lock.bios.panel_overdrive,
); );
lock.tray_should_update = false; lock.tray_should_update = false;
debug!("ROGTray: rebuilt menus due to state change");
match lock.gfx_state.power_status { match lock.gfx_state.power_status {
GfxPower::Active => tray.set_icon("asus_notif_red"), GfxPower::Active => tray.set_icon("asus_notif_red"),

View File

@@ -1,13 +1,9 @@
use egui::{RichText, Ui}; use egui::{RichText, Ui};
use rog_platform::supported::SupportedFunctions; use rog_platform::supported::SupportedFunctions;
use crate::page_states::PageDataStates; use crate::system_state::SystemState;
pub fn anime_power_group( pub fn anime_power_group(_supported: &SupportedFunctions, states: &mut SystemState, ui: &mut Ui) {
_supported: &SupportedFunctions,
states: &mut PageDataStates,
ui: &mut Ui,
) {
ui.heading("AniMe Matrix Settings"); ui.heading("AniMe Matrix Settings");
ui.label("Options are incomplete. Awake + Boot should work"); ui.label("Options are incomplete. Awake + Boot should work");

View File

@@ -1,8 +1,8 @@
use egui::Ui; use egui::Ui;
use crate::{config::Config, page_states::PageDataStates}; use crate::{config::Config, system_state::SystemState};
pub fn app_settings(config: &mut Config, states: &mut PageDataStates, ui: &mut Ui) { pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui) {
ui.heading("ROG GUI Settings"); ui.heading("ROG GUI Settings");
// ui.label("Options are incomplete. Awake + Boot should work"); // ui.label("Options are incomplete. Awake + Boot should work");

View File

@@ -7,11 +7,11 @@ use egui::{RichText, Ui};
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour, Speed}; use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour, Speed};
use rog_platform::supported::SupportedFunctions; use rog_platform::supported::SupportedFunctions;
use crate::page_states::{AuraState, PageDataStates}; use crate::system_state::{AuraState, SystemState};
pub fn aura_modes_group( pub fn aura_modes_group(
supported: &SupportedFunctions, supported: &SupportedFunctions,
states: &mut PageDataStates, states: &mut SystemState,
freq: &mut Arc<AtomicU8>, freq: &mut Arc<AtomicU8>,
ui: &mut Ui, ui: &mut Ui,
) { ) {

View File

@@ -5,9 +5,9 @@ use rog_aura::{
}; };
use rog_platform::supported::SupportedFunctions; use rog_platform::supported::SupportedFunctions;
use crate::page_states::PageDataStates; use crate::system_state::SystemState;
pub fn aura_power_group(supported: &SupportedFunctions, states: &mut PageDataStates, ui: &mut Ui) { pub fn aura_power_group(supported: &SupportedFunctions, states: &mut SystemState, ui: &mut Ui) {
ui.heading("LED settings"); ui.heading("LED settings");
match supported.keyboard_led.prod_id { match supported.keyboard_led.prod_id {
@@ -20,7 +20,7 @@ pub fn aura_power_group(supported: &SupportedFunctions, states: &mut PageDataSta
} }
} }
fn aura_power1(supported: &SupportedFunctions, states: &mut PageDataStates, ui: &mut Ui) { fn aura_power1(supported: &SupportedFunctions, states: &mut SystemState, ui: &mut Ui) {
let enabled_states = &mut states.aura.enabled; let enabled_states = &mut states.aura.enabled;
let mut boot = enabled_states.x1866.contains(&AuraDev1866::Boot); let mut boot = enabled_states.x1866.contains(&AuraDev1866::Boot);
let mut sleep = enabled_states.x1866.contains(&AuraDev1866::Sleep); let mut sleep = enabled_states.x1866.contains(&AuraDev1866::Sleep);
@@ -201,7 +201,7 @@ fn aura_power1(supported: &SupportedFunctions, states: &mut PageDataStates, ui:
} }
} }
fn aura_power2(supported: &SupportedFunctions, states: &mut PageDataStates, ui: &mut Ui) { fn aura_power2(supported: &SupportedFunctions, states: &mut SystemState, ui: &mut Ui) {
let enabled_states = &mut states.aura.enabled; let enabled_states = &mut states.aura.enabled;
let has_logo = supported let has_logo = supported
.keyboard_led .keyboard_led

View File

@@ -3,7 +3,7 @@ use rog_platform::supported::SupportedFunctions;
use rog_profiles::{FanCurvePU, Profile}; use rog_profiles::{FanCurvePU, Profile};
use crate::{ use crate::{
page_states::{FanCurvesState, ProfilesState}, system_state::{FanCurvesState, ProfilesState},
RogDbusClientBlocking, RogDbusClientBlocking,
}; };

View File

@@ -1,7 +1,7 @@
use egui::{Align, Color32, Vec2}; use egui::{Align, Color32, Vec2};
use rog_aura::{keys::KeyShape, layouts::KeyLayout, AuraModeNum}; use rog_aura::{keys::KeyShape, layouts::KeyLayout, AuraModeNum};
use crate::page_states::AuraState; use crate::system_state::AuraState;
pub fn keyboard( pub fn keyboard(
ui: &mut egui::Ui, ui: &mut egui::Ui,

View File

@@ -1,9 +1,9 @@
use crate::page_states::PageDataStates; use crate::system_state::SystemState;
use egui::Ui; use egui::Ui;
use rog_platform::{platform::GpuMode, supported::SupportedFunctions}; use rog_platform::{platform::GpuMode, supported::SupportedFunctions};
use rog_profiles::Profile; use rog_profiles::Profile;
pub fn platform_profile(states: &mut PageDataStates, ui: &mut Ui) { pub fn platform_profile(states: &mut SystemState, ui: &mut Ui) {
ui.heading("Platform profile"); ui.heading("Platform profile");
let mut changed = false; let mut changed = false;
@@ -35,7 +35,7 @@ pub fn platform_profile(states: &mut PageDataStates, ui: &mut Ui) {
}; };
} }
pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut PageDataStates, ui: &mut Ui) { pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState, ui: &mut Ui) {
ui.heading("Bios options"); ui.heading("Bios options");
let slider = egui::Slider::new(&mut states.power_state.charge_limit, 20..=100) let slider = egui::Slider::new(&mut states.power_state.charge_limit, 20..=100)

View File

@@ -52,7 +52,7 @@ impl Profile {
} }
pub fn get_active_profile() -> Result<Profile, ProfileError> { pub fn get_active_profile() -> Result<Profile, ProfileError> {
let mut file = OpenOptions::new().read(true).open(&PLATFORM_PROFILE)?; let mut file = OpenOptions::new().read(true).open(PLATFORM_PROFILE)?;
let mut buf = String::new(); let mut buf = String::new();
file.read_to_string(&mut buf)?; file.read_to_string(&mut buf)?;
@@ -60,7 +60,7 @@ impl Profile {
} }
pub fn get_profile_names() -> Result<Vec<Profile>, ProfileError> { pub fn get_profile_names() -> Result<Vec<Profile>, ProfileError> {
let mut file = OpenOptions::new().read(true).open(&PLATFORM_PROFILES)?; let mut file = OpenOptions::new().read(true).open(PLATFORM_PROFILES)?;
let mut buf = String::new(); let mut buf = String::new();
file.read_to_string(&mut buf)?; file.read_to_string(&mut buf)?;