mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
daemon: deduplicate idle state check logic
This commit is contained in:
parent
139746069a
commit
ff4e6e69c8
1 changed files with 4 additions and 10 deletions
|
@ -256,7 +256,7 @@ impl SystemHistory {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update system state tracking
|
// Update system state tracking
|
||||||
let new_state = determine_system_state(report);
|
let new_state = determine_system_state(report, self);
|
||||||
if new_state != self.current_state {
|
if new_state != self.current_state {
|
||||||
// Record time spent in previous state
|
// Record time spent in previous state
|
||||||
let time_in_state = self.last_state_change.elapsed();
|
let time_in_state = self.last_state_change.elapsed();
|
||||||
|
@ -580,7 +580,7 @@ enum SystemState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine the current system state for adaptive polling
|
/// Determine the current system state for adaptive polling
|
||||||
fn determine_system_state(report: &SystemReport) -> SystemState {
|
fn determine_system_state(report: &SystemReport, history: &SystemHistory) -> SystemState {
|
||||||
// Check power state first
|
// Check power state first
|
||||||
if !report.batteries.is_empty() {
|
if !report.batteries.is_empty() {
|
||||||
if let Some(battery) = report.batteries.first() {
|
if let Some(battery) = report.batteries.first() {
|
||||||
|
@ -603,14 +603,8 @@ fn determine_system_state(report: &SystemReport) -> SystemState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check idle state by checking very low CPU usage
|
// Check idle state
|
||||||
let is_idle = report
|
if history.is_system_idle() {
|
||||||
.cpu_cores
|
|
||||||
.iter()
|
|
||||||
.filter_map(|c| c.usage_percent)
|
|
||||||
.all(|usage| usage < 5.0);
|
|
||||||
|
|
||||||
if is_idle {
|
|
||||||
return SystemState::Idle;
|
return SystemState::Idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue