only do standby mode for pi (#2102)

This commit is contained in:
Aiden McClelland
2023-01-09 16:21:30 -07:00
committed by GitHub
parent 011bac7b4f
commit 1dc7c7b0a4
2 changed files with 16 additions and 6 deletions

View File

@@ -19,7 +19,7 @@ use embassy::shutdown::Shutdown;
use embassy::sound::CHIME;
use embassy::util::logger::EmbassyLogger;
use embassy::util::Invoke;
use embassy::{Error, ErrorKind, ResultExt};
use embassy::{Error, ErrorKind, ResultExt, IS_RASPBERRY_PI};
use tokio::process::Command;
use tracing::instrument;
@@ -162,7 +162,7 @@ async fn run_script_if_exists<P: AsRef<Path>>(path: P) {
#[instrument]
async fn inner_main(cfg_path: Option<PathBuf>) -> Result<Option<Shutdown>, Error> {
if tokio::fs::metadata(STANDBY_MODE_PATH).await.is_ok() {
if *IS_RASPBERRY_PI && tokio::fs::metadata(STANDBY_MODE_PATH).await.is_ok() {
tokio::fs::remove_file(STANDBY_MODE_PATH).await?;
Command::new("sync").invoke(ErrorKind::Filesystem).await?;
embassy::sound::SHUTDOWN.play().await?;

View File

@@ -9,7 +9,7 @@ use crate::disk::main::export;
use crate::init::{STANDBY_MODE_PATH, SYSTEM_REBUILD_PATH};
use crate::sound::SHUTDOWN;
use crate::util::{display_none, Invoke};
use crate::{Error, ErrorKind};
use crate::{Error, ErrorKind, IS_RASPBERRY_PI};
#[derive(Debug, Clone)]
pub struct Shutdown {
@@ -68,10 +68,20 @@ impl Shutdown {
}
});
drop(rt);
if !self.restart {
std::fs::write(STANDBY_MODE_PATH, "").unwrap();
if *IS_RASPBERRY_PI {
if !self.restart {
std::fs::write(STANDBY_MODE_PATH, "").unwrap();
}
Command::new("reboot").spawn().unwrap().wait().unwrap();
} else {
Command::new("shutdown")
.arg("-h")
.arg("now")
.spawn()
.unwrap()
.wait()
.unwrap();
}
Command::new("reboot").spawn().unwrap().wait().unwrap();
}
}