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
|
||||
let new_state = determine_system_state(report);
|
||||
let new_state = determine_system_state(report, self);
|
||||
if new_state != self.current_state {
|
||||
// Record time spent in previous state
|
||||
let time_in_state = self.last_state_change.elapsed();
|
||||
|
@ -580,7 +580,7 @@ enum SystemState {
|
|||
}
|
||||
|
||||
/// 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
|
||||
if !report.batteries.is_empty() {
|
||||
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
|
||||
let is_idle = report
|
||||
.cpu_cores
|
||||
.iter()
|
||||
.filter_map(|c| c.usage_percent)
|
||||
.all(|usage| usage < 5.0);
|
||||
|
||||
if is_idle {
|
||||
// Check idle state
|
||||
if history.is_system_idle() {
|
||||
return SystemState::Idle;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue