mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Add display-manager restart check
This commit is contained in:
@@ -317,25 +317,25 @@ impl CtrlGraphics {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wait_display_manager_inactive() -> Result<(), RogError> {
|
fn wait_display_manager_state(state: &str) -> Result<(), RogError> {
|
||||||
let mut cmd = Command::new("systemctl");
|
let mut cmd = Command::new("systemctl");
|
||||||
cmd.arg("is-active");
|
cmd.arg("is-active");
|
||||||
cmd.arg(DISPLAY_MANAGER);
|
cmd.arg(DISPLAY_MANAGER);
|
||||||
|
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
while count <= 4 {
|
while count <= 5 {
|
||||||
let output = cmd
|
let output = cmd
|
||||||
.output()
|
.output()
|
||||||
.map_err(|err| RogError::Command(format!("{:?}", cmd), err))?;
|
.map_err(|err| RogError::Command(format!("{:?}", cmd), err))?;
|
||||||
if output.stdout.starts_with("inactive".as_bytes()) {
|
if output.stdout.starts_with(state.as_bytes()) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
return Err(
|
return Err(
|
||||||
GfxError::DisplayManager("display-manager did not completely stop".into()).into(),
|
GfxError::DisplayManager(format!("display-manager timed out waiting for {} state", state).into()).into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,9 +373,13 @@ impl CtrlGraphics {
|
|||||||
/// Will stop and start display manager without warning
|
/// Will stop and start display manager without warning
|
||||||
pub fn set_gfx_config(&mut self, vendor: GfxVendors) -> Result<String, RogError> {
|
pub fn set_gfx_config(&mut self, vendor: GfxVendors) -> Result<String, RogError> {
|
||||||
Self::do_display_manager_action("stop")?;
|
Self::do_display_manager_action("stop")?;
|
||||||
Self::wait_display_manager_inactive()?;
|
Self::wait_display_manager_state("inactive")?;
|
||||||
self.do_vendor_tasks(vendor)?;
|
self.do_vendor_tasks(vendor)?;
|
||||||
Self::do_display_manager_action("start")?;
|
Self::do_display_manager_action("start")?;
|
||||||
|
if Self::wait_display_manager_state("active").is_err() {
|
||||||
|
Self::do_display_manager_action("restart")?;
|
||||||
|
}
|
||||||
|
Self::wait_display_manager_state("active")?;
|
||||||
// TODO: undo if failed? Save last mode, catch errors...
|
// TODO: undo if failed? Save last mode, catch errors...
|
||||||
let v: &str = vendor.into();
|
let v: &str = vendor.into();
|
||||||
Ok(format!("Graphics mode changed to {} successfully", v))
|
Ok(format!("Graphics mode changed to {} successfully", v))
|
||||||
|
|||||||
Reference in New Issue
Block a user