Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused variables in daemon and add back 15s usage rule timer #300

Merged
merged 3 commits into from
Jun 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use nix::unistd::Uid;

use super::config::Config;
use super::cpu::{Speed, CPU};
use super::debug;
use super::graph::{Graph, Grapher};
use super::logger;
use super::logger::Interface;
Expand Down Expand Up @@ -80,11 +79,6 @@ pub struct Daemon {
pub usage: f32,
pub logger: logger::Logger,
pub config: Config,
pub already_charging: bool,
pub already_closed: bool,
pub already_under_powersave_under_percent: bool,
pub already_high_temp: bool,
pub already_high_usage: bool,
pub last_below_cpu_usage_percent: Option<SystemTime>,
pub state: State,
pub graph: String,
Expand Down Expand Up @@ -182,8 +176,21 @@ impl Checker for Daemon {
fn run_state_machine(&mut self) -> Result<State, Error> {
let mut state = State::Normal;

if self.usage > 70.0 {
state = State::CpuUsageHigh;
if self.usage > 70.0 && self.last_below_cpu_usage_percent.is_none() {
self.last_below_cpu_usage_percent = Some(SystemTime::now());
}

if self.usage <= 70.0 {
self.last_below_cpu_usage_percent = None;
}

match self.last_below_cpu_usage_percent {
Some(last) => {
if SystemTime::now().duration_since(last)?.as_secs() >= 15 {
state = State::CpuUsageHigh;
}
}
None => {}
}

if self.lid_state == LidState::Closed {
Expand Down Expand Up @@ -243,13 +250,6 @@ impl Checker for Daemon {

self.timeout_battery = time::Duration::from_millis(self.settings.delay_battery);
self.timeout = time::Duration::from_millis(self.settings.delay);

// If we just daemonized then make sure the states are the opposite of what they should
// The logic after this block will make sure that they are set to the correct state
// but only if the previous states were incorrect
self.already_charging = !self.charging;
self.already_under_powersave_under_percent = !(self.charge < self.config.powersave_under);
self.already_closed = self.lid_state == LidState::Closed;
}

fn start_loop(&mut self) -> Result<(), Error> {
Expand Down Expand Up @@ -530,11 +530,6 @@ pub fn daemon_init(settings: Settings, config: Config) -> Result<Daemon, Error>
logs: Vec::<logger::Log>::new(),
},
config,
already_charging: false,
already_closed: false,
already_under_powersave_under_percent: false,
already_high_temp: false,
already_high_usage: false,
last_below_cpu_usage_percent: None,
graph: String::new(),
grapher: Graph { freqs: vec![0.0] },
Expand Down