mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
ROGCC: splatter log messages everywhere. Rename state control
This commit is contained in:
@@ -145,7 +145,7 @@ impl AnimeConfig {
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(&ANIME_CONFIG_PATH)
|
||||
.open(ANIME_CONFIG_PATH)
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"The file {} or directory /etc/asusd/ is missing",
|
||||
@@ -249,7 +249,7 @@ impl AnimeConfig {
|
||||
pub fn read(&mut self) {
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(&ANIME_CONFIG_PATH)
|
||||
.open(ANIME_CONFIG_PATH)
|
||||
.unwrap_or_else(|err| panic!("Error reading {}: {}", ANIME_CONFIG_PATH, err));
|
||||
let mut buf = String::new();
|
||||
if let Ok(l) = file.read_to_string(&mut buf) {
|
||||
|
||||
@@ -192,7 +192,7 @@ impl AuraConfig {
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.open(&AURA_CONFIG_PATH)
|
||||
.open(AURA_CONFIG_PATH)
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"The file {} or directory /etc/asusd/ is missing",
|
||||
@@ -264,7 +264,7 @@ impl AuraConfig {
|
||||
pub fn read(&mut self) {
|
||||
let mut file = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(&AURA_CONFIG_PATH)
|
||||
.open(AURA_CONFIG_PATH)
|
||||
.unwrap_or_else(|err| panic!("Error reading {}: {}", AURA_CONFIG_PATH, err));
|
||||
let mut buf = String::new();
|
||||
if let Ok(l) = file.read_to_string(&mut buf) {
|
||||
|
||||
@@ -11,12 +11,12 @@ use egui::{Button, RichText};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
|
||||
use crate::{
|
||||
config::Config, error::Result, page_states::PageDataStates, Page, RogDbusClientBlocking,
|
||||
config::Config, error::Result, system_state::SystemState, Page, RogDbusClientBlocking,
|
||||
};
|
||||
|
||||
pub struct RogApp {
|
||||
pub page: Page,
|
||||
pub states: Arc<Mutex<PageDataStates>>,
|
||||
pub states: Arc<Mutex<SystemState>>,
|
||||
pub supported: SupportedFunctions,
|
||||
// TODO: can probably just open and read whenever
|
||||
pub config: Config,
|
||||
@@ -34,7 +34,7 @@ impl RogApp {
|
||||
/// Called once before the first frame.
|
||||
pub fn new(
|
||||
config: Config,
|
||||
states: Arc<Mutex<PageDataStates>>,
|
||||
states: Arc<Mutex<SystemState>>,
|
||||
_cc: &eframe::CreationContext<'_>,
|
||||
) -> Result<Self> {
|
||||
let (dbus, _) = RogDbusClientBlocking::new()?;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use log::{error, info, warn};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::{
|
||||
fs::{create_dir, OpenOptions},
|
||||
io::{Read, Write},
|
||||
};
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
//use log::{error, info, warn};
|
||||
|
||||
use crate::{error::Error, notify::EnabledNotifications};
|
||||
@@ -34,14 +34,17 @@ impl Default for Config {
|
||||
impl Config {
|
||||
pub fn load() -> Result<Config, Error> {
|
||||
let mut path = if let Some(dir) = dirs::config_dir() {
|
||||
info!("Found XDG config dir {dir:?}");
|
||||
dir
|
||||
} else {
|
||||
error!("Could not get XDG config dir");
|
||||
return Err(Error::XdgVars);
|
||||
};
|
||||
|
||||
path.push(CFG_DIR);
|
||||
if !path.exists() {
|
||||
create_dir(path.clone())?;
|
||||
info!("Created {path:?}");
|
||||
}
|
||||
|
||||
path.push(CFG_FILE_NAME);
|
||||
@@ -56,11 +59,13 @@ impl Config {
|
||||
|
||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||
if read_len == 0 {
|
||||
warn!("Zero len read of Config file");
|
||||
let default = Config::default();
|
||||
let t = toml::to_string_pretty(&default).unwrap();
|
||||
file.write_all(t.as_bytes())?;
|
||||
return Ok(default);
|
||||
} else if let Ok(data) = toml::from_str::<Config>(&buf) {
|
||||
info!("Loaded config file {path:?}");
|
||||
return Ok(data);
|
||||
}
|
||||
}
|
||||
@@ -77,6 +82,7 @@ impl Config {
|
||||
path.push(CFG_DIR);
|
||||
if !path.exists() {
|
||||
create_dir(path.clone())?;
|
||||
info!("Created {path:?}");
|
||||
}
|
||||
|
||||
path.push(CFG_FILE_NAME);
|
||||
@@ -90,6 +96,7 @@ impl Config {
|
||||
self.enabled_notifications = enabled_notifications.clone();
|
||||
let t = toml::to_string_pretty(&self).unwrap();
|
||||
file.write_all(t.as_bytes())?;
|
||||
info!("Saved config file {path:?}");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ pub mod error;
|
||||
#[cfg(feature = "mocking")]
|
||||
pub mod mocking;
|
||||
pub mod notify;
|
||||
pub mod page_states;
|
||||
pub mod pages;
|
||||
pub mod startup_error;
|
||||
pub mod system_state;
|
||||
pub mod tray;
|
||||
pub mod widgets;
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use eframe::{IconData, NativeOptions};
|
||||
use log::{error, LevelFilter};
|
||||
use log::{error, info, LevelFilter};
|
||||
use rog_aura::layouts::KeyLayout;
|
||||
use rog_control_center::notify::EnabledNotifications;
|
||||
use rog_control_center::tray::init_tray;
|
||||
use rog_control_center::{
|
||||
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,
|
||||
};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
@@ -118,7 +118,7 @@ fn main() -> Result<()> {
|
||||
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());
|
||||
|
||||
@@ -127,7 +127,7 @@ fn main() -> Result<()> {
|
||||
start_app(states.clone(), native_options.clone())?;
|
||||
}
|
||||
|
||||
let config = Config::load().unwrap();
|
||||
let config = Config::load()?;
|
||||
if !config.run_in_background {
|
||||
break;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ fn main() -> Result<()> {
|
||||
let mut buf = [0u8; 4];
|
||||
// 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)
|
||||
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;
|
||||
continue;
|
||||
}
|
||||
@@ -154,8 +154,8 @@ fn setup_page_state_and_notifs(
|
||||
keyboard_layout: KeyLayout,
|
||||
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
|
||||
supported: &SupportedFunctions,
|
||||
) -> Result<Arc<Mutex<PageDataStates>>> {
|
||||
let page_states = Arc::new(Mutex::new(PageDataStates::new(
|
||||
) -> Result<Arc<Mutex<SystemState>>> {
|
||||
let page_states = Arc::new(Mutex::new(SystemState::new(
|
||||
keyboard_layout,
|
||||
enabled_notifications.clone(),
|
||||
supported,
|
||||
@@ -166,9 +166,9 @@ fn setup_page_state_and_notifs(
|
||||
Ok(page_states)
|
||||
}
|
||||
|
||||
fn start_app(states: Arc<Mutex<PageDataStates>>, native_options: NativeOptions) -> Result<()> {
|
||||
let mut ipc_file = get_ipc_file().unwrap();
|
||||
ipc_file.write_all(&[SHOWING_GUI]).unwrap();
|
||||
fn start_app(states: Arc<Mutex<SystemState>>, native_options: NativeOptions) -> Result<()> {
|
||||
let mut ipc_file = get_ipc_file()?;
|
||||
ipc_file.write_all(&[SHOWING_GUI])?;
|
||||
eframe::run_native(
|
||||
"ROG Control Center",
|
||||
native_options,
|
||||
@@ -202,6 +202,7 @@ fn load_icon() -> IconData {
|
||||
rgba = ras.as_u8_slice().to_vec();
|
||||
width = ras.width();
|
||||
height = ras.height();
|
||||
info!("Loaded app icon. Not actually supported in Wayland yet");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -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 rog_dbus::{
|
||||
zbus_anime::AnimeProxy, zbus_led::LedProxy, zbus_platform::RogBiosProxy,
|
||||
@@ -90,14 +91,22 @@ macro_rules! recv_notif {
|
||||
let page_states1 = $page_states.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = $proxy::new(&conn).await.unwrap();
|
||||
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();
|
||||
if let Ok(mut p) = proxy.$signal().await {
|
||||
info!("Started zbus signal thread: {}", stringify!($signal));
|
||||
while let Some(e) = p.next().await {
|
||||
if let Ok(out) = e.args() {
|
||||
if let Ok(config) = notifs_enabled1.lock() {
|
||||
if config.all_enabled && config.$signal {
|
||||
if let Ok(ref mut lock) = last_notif.lock() {
|
||||
trace!("zbus signal {} locked last_notif", stringify!($signal));
|
||||
notify!($notifier($msg, &out.$($out_arg)+()), lock);
|
||||
}
|
||||
}
|
||||
@@ -116,7 +125,7 @@ macro_rules! recv_notif {
|
||||
type SharedHandle = Arc<Mutex<Option<NotificationHandle>>>;
|
||||
|
||||
pub fn start_notifications(
|
||||
page_states: Arc<Mutex<PageDataStates>>,
|
||||
page_states: Arc<Mutex<SystemState>>,
|
||||
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
|
||||
) -> Result<()> {
|
||||
let last_notification: SharedHandle = Arc::new(Mutex::new(None));
|
||||
@@ -236,9 +245,22 @@ pub fn start_notifications(
|
||||
|
||||
let page_states1 = page_states.clone();
|
||||
tokio::spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = AnimeProxy::new(&conn).await.unwrap();
|
||||
let conn = zbus::Connection::system()
|
||||
.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 {
|
||||
info!("Started zbus signal thread: receive_power_states");
|
||||
p.for_each(|_| {
|
||||
if let Ok(_lock) = page_states1.lock() {
|
||||
// TODO: lock.anime.
|
||||
@@ -273,13 +295,30 @@ pub fn start_notifications(
|
||||
// );
|
||||
|
||||
tokio::spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = SuperProxy::new(&conn).await.unwrap();
|
||||
let conn = zbus::Connection::system()
|
||||
.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 {
|
||||
info!("Started zbus signal thread: receive_notify_action");
|
||||
while let Some(e) = p.next().await {
|
||||
if let Ok(out) = e.args() {
|
||||
let action = out.action();
|
||||
do_gfx_action_notif("Gfx mode change requires", &format!("{action:?}",))
|
||||
.map_err(|e| {
|
||||
error!("zbus signal: do_gfx_action_notif: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
@@ -289,9 +328,22 @@ pub fn start_notifications(
|
||||
let notifs_enabled1 = enabled_notifications;
|
||||
let last_notif = last_notification;
|
||||
tokio::spawn(async move {
|
||||
let conn = zbus::Connection::system().await.unwrap();
|
||||
let proxy = SuperProxy::new(&conn).await.unwrap();
|
||||
let conn = zbus::Connection::system()
|
||||
.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 {
|
||||
info!("Started zbus signal thread: receive_notify_gfx_status");
|
||||
while let Some(e) = p.next().await {
|
||||
if let Ok(out) = e.args() {
|
||||
let status = out.status;
|
||||
|
||||
@@ -4,13 +4,13 @@ use egui::Color32;
|
||||
use rog_aura::{AuraEffect, AuraModeNum};
|
||||
|
||||
use crate::{
|
||||
page_states::PageDataStates,
|
||||
system_state::SystemState,
|
||||
widgets::{aura_modes_group, keyboard},
|
||||
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 {
|
||||
supported,
|
||||
oscillator1,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
page_states::{FanCurvesState, PageDataStates, ProfilesState},
|
||||
system_state::{FanCurvesState, ProfilesState, SystemState},
|
||||
widgets::fan_graphs,
|
||||
RogApp, RogDbusClientBlocking,
|
||||
};
|
||||
@@ -8,7 +8,7 @@ use rog_platform::supported::SupportedFunctions;
|
||||
use rog_profiles::Profile;
|
||||
|
||||
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;
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
page_states::PageDataStates,
|
||||
system_state::SystemState,
|
||||
widgets::{
|
||||
anime_power_group, app_settings, aura_power_group, platform_profile, rog_bios_group,
|
||||
},
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
};
|
||||
|
||||
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 {
|
||||
config, supported, ..
|
||||
} = self;
|
||||
|
||||
@@ -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 enabled_notifications: Arc<Mutex<EnabledNotifications>>,
|
||||
/// Because much of the app state here is the same as `RogBiosSupportedFunctions`
|
||||
@@ -268,7 +270,7 @@ pub struct PageDataStates {
|
||||
pub gfx_dbus: GfxProxyBlocking<'static>,
|
||||
}
|
||||
|
||||
impl PageDataStates {
|
||||
impl SystemState {
|
||||
/// Creates self, including the relevant dbus connections and proixies for internal use
|
||||
pub fn new(
|
||||
keyboard_layout: KeyLayout,
|
||||
@@ -301,7 +303,7 @@ impl PageDataStates {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PageDataStates {
|
||||
impl Default for SystemState {
|
||||
fn default() -> Self {
|
||||
let (asus_dbus, conn) = RogDbusClientBlocking::new().unwrap();
|
||||
let gfx_dbus = GfxProxyBlocking::new(&conn).unwrap();
|
||||
@@ -14,14 +14,14 @@ use gtk::{gio::Icon, prelude::*};
|
||||
use rog_dbus::zbus_platform::RogBiosProxyBlocking;
|
||||
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 supergfxctl::{
|
||||
pci_device::{GfxMode, GfxPower},
|
||||
zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking,
|
||||
};
|
||||
|
||||
use log::trace;
|
||||
use log::{debug, error, info, trace};
|
||||
|
||||
const TRAY_APP_ICON: &str = "rog-control-center";
|
||||
const TRAY_LABEL: &str = "ROG Control Center";
|
||||
@@ -86,13 +86,22 @@ pub struct ROGTray {
|
||||
|
||||
impl ROGTray {
|
||||
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 {
|
||||
tray: AppIndicator::new(TRAY_LABEL, TRAY_APP_ICON),
|
||||
menu: gtk::Menu::new(),
|
||||
icon: TRAY_APP_ICON,
|
||||
bios_proxy: RogBiosProxyBlocking::new(&conn).unwrap(),
|
||||
gfx_proxy: GfxProxyBlocking::new(&conn).unwrap(),
|
||||
bios_proxy: RogBiosProxyBlocking::new(&conn).map_err(|e| {
|
||||
error!("ROGTray: {e}");
|
||||
e
|
||||
})?,
|
||||
gfx_proxy: GfxProxyBlocking::new(&conn).map_err(|e| {
|
||||
error!("ROGTray: {e}");
|
||||
e
|
||||
})?,
|
||||
};
|
||||
Ok(rog_tray)
|
||||
}
|
||||
@@ -126,7 +135,11 @@ impl ROGTray {
|
||||
|
||||
let menu = gtk::Menu::new();
|
||||
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.show_all();
|
||||
menu.add(item);
|
||||
@@ -135,7 +148,7 @@ impl ROGTray {
|
||||
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
|
||||
F: Fn() + Send + 'static,
|
||||
{
|
||||
@@ -183,60 +196,124 @@ impl ROGTray {
|
||||
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)
|
||||
}
|
||||
|
||||
fn menu_add_base(&mut self) {
|
||||
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();
|
||||
debug!("ROGTray: built base menu");
|
||||
}
|
||||
|
||||
fn menu_add_charge_limit(&mut self, limit: u8) {
|
||||
self.add_inactive_label(&format!("Charge limit: {limit}"));
|
||||
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}"));
|
||||
debug!("ROGTray: appended charge limit menu");
|
||||
}
|
||||
}
|
||||
|
||||
fn menu_add_panel_od(&mut self, panel_od: bool) {
|
||||
let bios = self.bios_proxy.clone();
|
||||
self.add_check_menu_item("Panel Overdrive", panel_od, move |this| {
|
||||
bios.set_panel_od(this.is_active()).unwrap();
|
||||
});
|
||||
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();
|
||||
self.add_check_menu_item("Panel Overdrive", panel_od, move |this| {
|
||||
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) {
|
||||
let gfx_dbus = self.gfx_proxy.clone();
|
||||
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 {
|
||||
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();
|
||||
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 {
|
||||
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 {
|
||||
let gfx_dbus = self.bios_proxy.clone();
|
||||
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 {
|
||||
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 {
|
||||
let gfx_dbus = self.gfx_proxy.clone();
|
||||
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 {
|
||||
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(),
|
||||
gpu_menu,
|
||||
);
|
||||
|
||||
debug!("ROGTray: appended gpu menu");
|
||||
}
|
||||
|
||||
fn menu_clear(&mut self) {
|
||||
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.
|
||||
@@ -272,8 +352,8 @@ impl ROGTray {
|
||||
) {
|
||||
self.menu_clear();
|
||||
self.menu_add_base();
|
||||
self.menu_add_charge_limit(charge_limit);
|
||||
self.menu_add_panel_od(panel_od);
|
||||
self.menu_add_charge_limit(supported, charge_limit);
|
||||
self.menu_add_panel_od(supported, panel_od);
|
||||
self.menu_add_gpu(supported, current_gfx_mode);
|
||||
self.menu_update();
|
||||
}
|
||||
@@ -281,17 +361,39 @@ impl ROGTray {
|
||||
|
||||
pub fn init_tray(
|
||||
supported: SupportedFunctions,
|
||||
states: Arc<Mutex<PageDataStates>>,
|
||||
states: Arc<Mutex<SystemState>>,
|
||||
) -> Receiver<TrayToApp> {
|
||||
let (send, recv) = channel();
|
||||
let _send = Arc::new(Mutex::new(send));
|
||||
|
||||
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.set_icon(TRAY_APP_ICON);
|
||||
info!("Started ROGTray");
|
||||
|
||||
loop {
|
||||
if let Ok(mut lock) = states.lock() {
|
||||
@@ -303,6 +405,7 @@ pub fn init_tray(
|
||||
lock.bios.panel_overdrive,
|
||||
);
|
||||
lock.tray_should_update = false;
|
||||
debug!("ROGTray: rebuilt menus due to state change");
|
||||
|
||||
match lock.gfx_state.power_status {
|
||||
GfxPower::Active => tray.set_icon("asus_notif_red"),
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
use egui::{RichText, Ui};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
|
||||
use crate::page_states::PageDataStates;
|
||||
use crate::system_state::SystemState;
|
||||
|
||||
pub fn anime_power_group(
|
||||
_supported: &SupportedFunctions,
|
||||
states: &mut PageDataStates,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
pub fn anime_power_group(_supported: &SupportedFunctions, states: &mut SystemState, ui: &mut Ui) {
|
||||
ui.heading("AniMe Matrix Settings");
|
||||
ui.label("Options are incomplete. Awake + Boot should work");
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
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.label("Options are incomplete. Awake + Boot should work");
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@ use egui::{RichText, Ui};
|
||||
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour, Speed};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
|
||||
use crate::page_states::{AuraState, PageDataStates};
|
||||
use crate::system_state::{AuraState, SystemState};
|
||||
|
||||
pub fn aura_modes_group(
|
||||
supported: &SupportedFunctions,
|
||||
states: &mut PageDataStates,
|
||||
states: &mut SystemState,
|
||||
freq: &mut Arc<AtomicU8>,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
|
||||
@@ -5,9 +5,9 @@ use rog_aura::{
|
||||
};
|
||||
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");
|
||||
|
||||
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 mut boot = enabled_states.x1866.contains(&AuraDev1866::Boot);
|
||||
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 has_logo = supported
|
||||
.keyboard_led
|
||||
|
||||
@@ -3,7 +3,7 @@ use rog_platform::supported::SupportedFunctions;
|
||||
use rog_profiles::{FanCurvePU, Profile};
|
||||
|
||||
use crate::{
|
||||
page_states::{FanCurvesState, ProfilesState},
|
||||
system_state::{FanCurvesState, ProfilesState},
|
||||
RogDbusClientBlocking,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use egui::{Align, Color32, Vec2};
|
||||
use rog_aura::{keys::KeyShape, layouts::KeyLayout, AuraModeNum};
|
||||
|
||||
use crate::page_states::AuraState;
|
||||
use crate::system_state::AuraState;
|
||||
|
||||
pub fn keyboard(
|
||||
ui: &mut egui::Ui,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::page_states::PageDataStates;
|
||||
use crate::system_state::SystemState;
|
||||
use egui::Ui;
|
||||
use rog_platform::{platform::GpuMode, supported::SupportedFunctions};
|
||||
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");
|
||||
|
||||
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");
|
||||
|
||||
let slider = egui::Slider::new(&mut states.power_state.charge_limit, 20..=100)
|
||||
|
||||
@@ -52,7 +52,7 @@ impl Profile {
|
||||
}
|
||||
|
||||
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();
|
||||
file.read_to_string(&mut buf)?;
|
||||
@@ -60,7 +60,7 @@ impl Profile {
|
||||
}
|
||||
|
||||
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();
|
||||
file.read_to_string(&mut buf)?;
|
||||
|
||||
Reference in New Issue
Block a user