mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
system: is_ac
This commit is contained in:
parent
004b879672
commit
a343e38d95
2 changed files with 26 additions and 29 deletions
|
@ -246,20 +246,6 @@ pub fn get_cpu_global_info(cpu_cores: &[CpuCoreInfo]) -> CpuGlobalInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_battery_info(config: &AppConfig) -> anyhow::Result<Vec<BatteryInfo>> {
|
|
||||||
// No AC adapter detected but we're on a desktop system
|
|
||||||
// Default to AC power for desktops
|
|
||||||
if !overall_ac_connected {
|
|
||||||
overall_ac_connected = is_likely_desktop_system();
|
|
||||||
}
|
|
||||||
// If we found no batteries but have power supplies, we're likely on a desktop
|
|
||||||
if batteries.is_empty() && overall_ac_connected {
|
|
||||||
log::debug!("No laptop batteries found, likely a desktop system");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(batteries)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_cpu_model() -> anyhow::Result<String> {
|
pub fn get_cpu_model() -> anyhow::Result<String> {
|
||||||
let path = Path::new("/proc/cpuinfo");
|
let path = Path::new("/proc/cpuinfo");
|
||||||
let content = fs::read_to_string(path).map_err(|_| {
|
let content = fs::read_to_string(path).map_err(|_| {
|
||||||
|
|
|
@ -1,19 +1,25 @@
|
||||||
use anyhow::{Context, bail};
|
use anyhow::{Context, bail};
|
||||||
|
|
||||||
use crate::fs;
|
use crate::{cpu, fs, power_supply};
|
||||||
|
|
||||||
pub struct System {
|
pub struct System {
|
||||||
pub is_desktop: bool,
|
pub is_ac: bool,
|
||||||
|
|
||||||
pub load_average_1min: f64,
|
pub load_average_1min: f64,
|
||||||
pub load_average_5min: f64,
|
pub load_average_5min: f64,
|
||||||
pub load_average_15min: f64,
|
pub load_average_15min: f64,
|
||||||
|
|
||||||
|
pub cpus: Vec<cpu::Cpu>,
|
||||||
|
pub power_supplies: Vec<power_supply::PowerSupply>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl System {
|
impl System {
|
||||||
pub fn new() -> anyhow::Result<Self> {
|
pub fn new() -> anyhow::Result<Self> {
|
||||||
let mut system = Self {
|
let mut system = Self {
|
||||||
is_desktop: false,
|
is_ac: false,
|
||||||
|
|
||||||
|
cpus: Vec::new(),
|
||||||
|
power_supplies: Vec::new(),
|
||||||
|
|
||||||
load_average_1min: 0.0,
|
load_average_1min: 0.0,
|
||||||
load_average_5min: 0.0,
|
load_average_5min: 0.0,
|
||||||
|
@ -26,13 +32,23 @@ impl System {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rescan(&mut self) -> anyhow::Result<()> {
|
pub fn rescan(&mut self) -> anyhow::Result<()> {
|
||||||
self.rescan_is_desktop()?;
|
self.cpus = cpu::Cpu::all().context("failed to scan CPUs")?;
|
||||||
|
|
||||||
|
self.power_supplies =
|
||||||
|
power_supply::PowerSupply::all().context("failed to scan power supplies")?;
|
||||||
|
|
||||||
|
self.is_ac = self
|
||||||
|
.power_supplies
|
||||||
|
.iter()
|
||||||
|
.any(|power_supply| power_supply.is_ac())
|
||||||
|
|| self.is_desktop()?;
|
||||||
|
|
||||||
self.rescan_load_average()?;
|
self.rescan_load_average()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rescan_is_desktop(&mut self) -> anyhow::Result<()> {
|
fn is_desktop(&mut self) -> anyhow::Result<bool> {
|
||||||
if let Some(chassis_type) =
|
if let Some(chassis_type) =
|
||||||
fs::read("/sys/class/dmi/id/chassis_type").context("failed to read chassis type")?
|
fs::read("/sys/class/dmi/id/chassis_type").context("failed to read chassis type")?
|
||||||
{
|
{
|
||||||
|
@ -42,13 +58,11 @@ impl System {
|
||||||
match chassis_type.trim() {
|
match chassis_type.trim() {
|
||||||
// Desktop form factors.
|
// Desktop form factors.
|
||||||
"3" | "4" | "5" | "6" | "7" | "15" | "16" | "17" => {
|
"3" | "4" | "5" | "6" | "7" | "15" | "16" | "17" => {
|
||||||
self.is_desktop = true;
|
return Ok(true);
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
// Laptop form factors.
|
// Laptop form factors.
|
||||||
"9" | "10" | "14" => {
|
"9" | "10" | "14" => {
|
||||||
self.is_desktop = false;
|
return Ok(false);
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unknown, continue with other checks
|
// Unknown, continue with other checks
|
||||||
|
@ -61,8 +75,7 @@ impl System {
|
||||||
|| fs::exists("/sys/devices/system/cpu/cpufreq/conservative");
|
|| fs::exists("/sys/devices/system/cpu/cpufreq/conservative");
|
||||||
|
|
||||||
if !power_saving_exists {
|
if !power_saving_exists {
|
||||||
self.is_desktop = true;
|
return Ok(true); // Likely a desktop.
|
||||||
return Ok(()); // Likely a desktop.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check battery-specific ACPI paths that laptops typically have
|
// Check battery-specific ACPI paths that laptops typically have
|
||||||
|
@ -74,14 +87,12 @@ impl System {
|
||||||
|
|
||||||
for path in laptop_acpi_paths {
|
for path in laptop_acpi_paths {
|
||||||
if fs::exists(path) {
|
if fs::exists(path) {
|
||||||
self.is_desktop = false; // Likely a laptop.
|
return Ok(false); // Likely a laptop.
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to assuming desktop if we can't determine.
|
// Default to assuming desktop if we can't determine.
|
||||||
self.is_desktop = true;
|
Ok(true)
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rescan_load_average(&mut self) -> anyhow::Result<()> {
|
fn rescan_load_average(&mut self) -> anyhow::Result<()> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue