mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fix rogcc not closing when run-in-background
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,6 +10,7 @@ pub enum Error {
|
||||
ConfigLockFail,
|
||||
XdgVars,
|
||||
Zbus(zbus::Error),
|
||||
Notification(notify_rust::error::Error)
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
@@ -22,6 +23,7 @@ impl fmt::Display for Error {
|
||||
Error::ConfigLockFail => write!(f, "Failed to lock user config"),
|
||||
Error::XdgVars => write!(f, "XDG environment vars appear unset"),
|
||||
Error::Zbus(err) => write!(f, "Error: {}", err),
|
||||
Error::Notification(err) => write!(f, "Notification Error: {}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,3 +47,9 @@ impl From<zbus::Error> for Error {
|
||||
Error::Zbus(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<notify_rust::error::Error> for Error {
|
||||
fn from(err: notify_rust::error::Error) -> Self {
|
||||
Error::Notification(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ pub fn on_tmp_dir_exists() -> Result<TempDir, std::io::Error> {
|
||||
// If the app is running this ends up stacked on top of SHOWING_GUI
|
||||
ipc_file.write_all(&[SHOW_GUI])?;
|
||||
// tiny sleep to give the app a chance to respond
|
||||
sleep(Duration::from_millis(10));
|
||||
sleep(Duration::from_millis(100));
|
||||
ipc_file.read(&mut buf).ok();
|
||||
|
||||
// First entry is the actual state
|
||||
|
||||
@@ -1,9 +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,
|
||||
page_states::PageDataStates, print_versions, startup_error::AppErrorShow, RogApp,
|
||||
RogDbusClientBlocking, SHOWING_GUI, SHOW_GUI,
|
||||
};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
|
||||
use std::{
|
||||
fs::OpenOptions,
|
||||
@@ -18,12 +21,12 @@ const DATA_DIR: &str = "/usr/share/rog-gui/";
|
||||
const DATA_DIR: &str = env!("CARGO_MANIFEST_DIR");
|
||||
const BOARD_NAME: &str = "/sys/class/dmi/id/board_name";
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn main() -> Result<()> {
|
||||
print_versions();
|
||||
|
||||
let native_options = eframe::NativeOptions {
|
||||
vsync: false,
|
||||
decorated: false,
|
||||
vsync: true,
|
||||
decorated: true,
|
||||
transparent: false,
|
||||
min_window_size: Some(egui::vec2(840.0, 600.0)),
|
||||
max_window_size: Some(egui::vec2(840.0, 600.0)),
|
||||
@@ -75,6 +78,51 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
})
|
||||
.unwrap_or_else(|_| KeyLayout::ga401_layout());
|
||||
|
||||
// tmp-dir must live to the end of program life
|
||||
let _tmp_dir = match tempfile::Builder::new()
|
||||
.prefix("rog-gui")
|
||||
.rand_bytes(0)
|
||||
.tempdir()
|
||||
{
|
||||
Ok(tmp) => tmp,
|
||||
Err(_) => on_tmp_dir_exists().unwrap(),
|
||||
};
|
||||
|
||||
let states = setup_page_state_and_notifs(layout.clone(), &config, native_options.clone(), &dbus).unwrap();
|
||||
|
||||
loop {
|
||||
dbg!();
|
||||
if !start_closed {
|
||||
start_app(states.clone(), native_options.clone())?;
|
||||
}
|
||||
dbg!();
|
||||
|
||||
let config = Config::load().unwrap();
|
||||
if !config.run_in_background {
|
||||
break;
|
||||
}
|
||||
|
||||
if config.run_in_background {
|
||||
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 {
|
||||
start_closed = false;
|
||||
dbg!();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
dbg!();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn setup_page_state_and_notifs(
|
||||
keyboard_layout: KeyLayout,
|
||||
config: &Config,
|
||||
native_options: NativeOptions,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
) -> Result<PageDataStates> {
|
||||
// Cheap method to alert to notifications rather than spinning a thread for each
|
||||
// This is quite different when done in a retained mode app
|
||||
let charge_notified = Arc::new(AtomicBool::new(false));
|
||||
@@ -95,68 +143,42 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
notifs_enabled.clone(),
|
||||
)?;
|
||||
|
||||
// tmp-dir must live to the end of program life
|
||||
let _tmp_dir = match tempfile::Builder::new()
|
||||
.prefix("rog-gui")
|
||||
.rand_bytes(0)
|
||||
.tempdir()
|
||||
{
|
||||
Ok(tmp) => tmp,
|
||||
Err(_) => on_tmp_dir_exists().unwrap(),
|
||||
};
|
||||
|
||||
loop {
|
||||
let states = {
|
||||
let supported = match dbus.proxies().supported().supported_functions() {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
eframe::run_native(
|
||||
"ROG Control Center",
|
||||
native_options.clone(),
|
||||
Box::new(move |_| Box::new(AppErrorShow::new(e.to_string()))),
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
PageDataStates::new(
|
||||
layout.clone(),
|
||||
notifs_enabled.clone(),
|
||||
charge_notified.clone(),
|
||||
bios_notified.clone(),
|
||||
aura_notified.clone(),
|
||||
anime_notified.clone(),
|
||||
profiles_notified.clone(),
|
||||
fans_notified.clone(),
|
||||
&supported,
|
||||
&dbus,
|
||||
)?
|
||||
};
|
||||
|
||||
if !start_closed {
|
||||
let mut ipc_file = get_ipc_file().unwrap();
|
||||
ipc_file.write_all(&[SHOWING_GUI]).unwrap();
|
||||
let supported = match dbus.proxies().supported().supported_functions() {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
eframe::run_native(
|
||||
"ROG Control Center",
|
||||
native_options.clone(),
|
||||
Box::new(move |cc| {
|
||||
Box::new(RogApp::new(Config::load().unwrap(), states, cc).unwrap())
|
||||
}),
|
||||
native_options,
|
||||
Box::new(move |_| Box::new(AppErrorShow::new(e.to_string()))),
|
||||
);
|
||||
SupportedFunctions::default()
|
||||
}
|
||||
};
|
||||
|
||||
let config = Config::load().unwrap();
|
||||
if !config.run_in_background {
|
||||
break;
|
||||
}
|
||||
PageDataStates::new(
|
||||
keyboard_layout,
|
||||
notifs_enabled.clone(),
|
||||
charge_notified.clone(),
|
||||
bios_notified.clone(),
|
||||
aura_notified.clone(),
|
||||
anime_notified.clone(),
|
||||
profiles_notified.clone(),
|
||||
fans_notified.clone(),
|
||||
&supported,
|
||||
&dbus,
|
||||
)
|
||||
}
|
||||
|
||||
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 {
|
||||
start_closed = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
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(
|
||||
"ROG Control Center",
|
||||
native_options,
|
||||
Box::new(move |cc| Box::new(RogApp::new(Config::load().unwrap(), states, cc).unwrap())),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use std::{
|
||||
};
|
||||
use supergfxctl::pci_device::GfxPower;
|
||||
use zbus::export::futures_util::StreamExt;
|
||||
use crate::error::Result;
|
||||
|
||||
const NOTIF_HEADER: &str = "ROG Control";
|
||||
|
||||
@@ -76,7 +77,7 @@ pub fn start_notifications(
|
||||
profiles_notified: Arc<AtomicBool>,
|
||||
_fans_notified: Arc<AtomicBool>,
|
||||
notifs_enabled: Arc<AtomicBool>,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
) -> Result<()> {
|
||||
let last_notification: SharedHandle = Arc::new(Mutex::new(None));
|
||||
|
||||
let executor = Executor::new();
|
||||
@@ -101,7 +102,7 @@ pub fn start_notifications(
|
||||
last_notification,
|
||||
notifs_enabled,
|
||||
[overdrive],
|
||||
"BIOS Panel Overdrive",
|
||||
"Panel Overdrive enabled:",
|
||||
do_notification
|
||||
);
|
||||
|
||||
@@ -154,6 +155,18 @@ pub fn start_notifications(
|
||||
do_notification
|
||||
);
|
||||
|
||||
recv_notif!(
|
||||
executor,
|
||||
PowerProxy,
|
||||
receive_notify_mains_online,
|
||||
bios_notified,
|
||||
last_notification,
|
||||
notifs_enabled,
|
||||
[on],
|
||||
"AC Power power is",
|
||||
ac_power_notification
|
||||
);
|
||||
|
||||
// Profile notif
|
||||
recv_notif!(
|
||||
executor,
|
||||
@@ -261,7 +274,7 @@ where
|
||||
.summary(NOTIF_HEADER)
|
||||
.body(&format!("{message} {data}"))
|
||||
.timeout(2000)
|
||||
.hint(Hint::Resident(true))
|
||||
//.hint(Hint::Resident(true))
|
||||
.hint(Hint::Category("device".into()));
|
||||
|
||||
notif
|
||||
@@ -270,17 +283,25 @@ where
|
||||
fn do_notification<T>(
|
||||
message: &str,
|
||||
data: &T,
|
||||
) -> Result<NotificationHandle, notify_rust::error::Error>
|
||||
) -> Result<NotificationHandle>
|
||||
where
|
||||
T: Display,
|
||||
{
|
||||
base_notification(message, data).show()
|
||||
Ok(base_notification(message, data).show()?)
|
||||
}
|
||||
|
||||
fn ac_power_notification(
|
||||
message: &str,
|
||||
on: &bool,
|
||||
) -> Result<NotificationHandle> {
|
||||
let data = if *on { "plugged".to_string() } else { "unplugged".to_string() };
|
||||
Ok(base_notification(message, &data).show()?)
|
||||
}
|
||||
|
||||
fn do_thermal_notif(
|
||||
message: &str,
|
||||
profile: &Profile,
|
||||
) -> Result<NotificationHandle, notify_rust::error::Error> {
|
||||
) -> Result<NotificationHandle> {
|
||||
let icon = match profile {
|
||||
Profile::Balanced => "asus_notif_yellow",
|
||||
Profile::Performance => "asus_notif_red",
|
||||
@@ -288,5 +309,5 @@ fn do_thermal_notif(
|
||||
};
|
||||
let profile: &str = (*profile).into();
|
||||
let mut notif = base_notification(message, &profile.to_uppercase());
|
||||
notif.icon(icon).show()
|
||||
Ok(notif.icon(icon).show()?)
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ impl AnimeState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PageDataStates {
|
||||
pub keyboard_layout: KeyLayout,
|
||||
pub notifs_enabled: Arc<AtomicBool>,
|
||||
|
||||
@@ -16,7 +16,7 @@ impl<'a> RogApp<'a> {
|
||||
} = self;
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.heading("Experimental application for asusd");
|
||||
ui.heading("Base settings");
|
||||
|
||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||
ui.spacing_mut().item_spacing = egui::vec2(8.0, 10.0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use egui::{vec2, Align2, Button, FontId, Id, Rect, RichText, Sense, Vec2};
|
||||
use egui::{vec2, Align2, FontId, Id, Sense};
|
||||
|
||||
use crate::{RogApp, VERSION};
|
||||
|
||||
@@ -27,20 +27,20 @@ impl<'a> RogApp<'a> {
|
||||
let height = titlebar_rect.height();
|
||||
// Paint the title:
|
||||
ui.painter().text(
|
||||
titlebar_rect.center_top() + vec2(0.0, height / 2.0),
|
||||
Align2::CENTER_CENTER,
|
||||
format!("ROG Control Center v{}", VERSION),
|
||||
titlebar_rect.right_top() + vec2(0.0, height / 2.0),
|
||||
Align2::RIGHT_CENTER,
|
||||
format!("v{}", VERSION),
|
||||
FontId::proportional(height - 2.0),
|
||||
text_color,
|
||||
);
|
||||
// Add the close button:
|
||||
let close_response = ui.put(
|
||||
Rect::from_min_size(titlebar_rect.right_top(), Vec2::splat(height)),
|
||||
Button::new(RichText::new("❌").size(height - 4.0)).frame(false),
|
||||
);
|
||||
if close_response.clicked() {
|
||||
frame.close();
|
||||
}
|
||||
// // Add the close button:
|
||||
// let close_response = ui.put(
|
||||
// Rect::from_min_size(titlebar_rect.right_top(), Vec2::splat(height)),
|
||||
// Button::new(RichText::new("❌").size(height - 4.0)).frame(false),
|
||||
// );
|
||||
// if close_response.clicked() {
|
||||
// frame.close();
|
||||
// }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user