diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ca5c182..9edf988e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -# [3.6.0] - 2021-05-15 +# [3.6.1] - 2021-05-25 +### Changed +- Bugfix for cycling through profiles + +# [3.6.0] - 2021-05-24 ### Changed - Add GX550L led modes - Don't save compute/vfio modes. Option in config for this is removed. diff --git a/Cargo.lock b/Cargo.lock index ba9dddba..7afa4291 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -207,7 +207,7 @@ dependencies = [ [[package]] name = "daemon" -version = "3.6.0" +version = "3.6.1" dependencies = [ "env_logger", "log", diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index d8bab45d..d255c5a7 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "daemon" -version = "3.6.0" +version = "3.6.1" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/daemon/src/ctrl_profiles/controller.rs b/daemon/src/ctrl_profiles/controller.rs index ab016900..16a9d13e 100644 --- a/daemon/src/ctrl_profiles/controller.rs +++ b/daemon/src/ctrl_profiles/controller.rs @@ -43,39 +43,39 @@ impl CtrlFanAndCpu { } /// Toggle to next profile in list - pub(super) fn do_next_profile(&mut self, config: &mut Config) -> Result<(), RogError> { - config.read(); + pub(super) fn do_next_profile(&mut self) -> Result<(), RogError> { + if let Ok(mut config) = self.config.clone().try_lock() { + config.read(); - let mut i = config - .toggle_profiles - .iter() - .position(|x| x == &config.active_profile) - .map(|i| i + 1) - .unwrap_or(0); - if i >= config.toggle_profiles.len() { - i = 0; + let mut i = config + .toggle_profiles + .binary_search(&config.active_profile) + .unwrap_or(0) + + 1; + if i >= config.toggle_profiles.len() { + i = 0; + } + + let profile = config.toggle_profiles[i].clone(); + + if let Some(existing) = config.power_profiles.get(&profile) { + existing.set_system_all()?; + config.active_profile = existing.name.clone(); + config.write(); + info!("Profile was changed to: {}", profile); + } } - - let new_profile = config - .toggle_profiles - .get(i) - .unwrap_or(&config.active_profile) - .clone(); - - self.set_active(&new_profile)?; - - info!("Profile was changed: {}", &new_profile); Ok(()) } pub(super) fn set_active(&mut self, profile: &str) -> Result<(), RogError> { if let Ok(mut cfg) = self.config.clone().try_lock() { cfg.read(); - - if let Some(existing) = cfg.power_profiles.get_mut(profile) { + if let Some(existing) = cfg.power_profiles.get(profile) { existing.set_system_all()?; cfg.active_profile = existing.name.clone(); cfg.write(); + info!("Profile was changed to: {}", profile); } } Ok(()) diff --git a/daemon/src/ctrl_profiles/zbus.rs b/daemon/src/ctrl_profiles/zbus.rs index c03895ba..4ae52096 100644 --- a/daemon/src/ctrl_profiles/zbus.rs +++ b/daemon/src/ctrl_profiles/zbus.rs @@ -25,15 +25,8 @@ impl FanAndCpuZbus { if let Ok(mut ctrl) = self.inner.try_lock() { ctrl.set_active(&profile) .unwrap_or_else(|err| warn!("{}", err)); - // Do notification - if let Ok(cfg) = ctrl.config.clone().try_lock() { - // Do notify - if let Some(profile) = cfg.power_profiles.get(&cfg.active_profile) { - self.notify_profile(&profile) - .unwrap_or_else(|err| warn!("{}", err)); - } - } } + self.do_notification(); } /// New or modify profile details and make active, will create if it does not exist @@ -41,30 +34,17 @@ impl FanAndCpuZbus { if let Ok(mut ctrl) = self.inner.try_lock() { ctrl.new_or_modify(&profile) .unwrap_or_else(|err| warn!("{}", err)); - // Do notification - if let Ok(cfg) = ctrl.config.clone().try_lock() { - // Do notify - if let Some(profile) = cfg.power_profiles.get(&cfg.active_profile) { - self.notify_profile(&profile) - .unwrap_or_else(|err| warn!("{}", err)); - } - } } + self.do_notification(); } /// Fetch the active profile name fn next_profile(&mut self) { if let Ok(mut ctrl) = self.inner.try_lock() { - if let Ok(mut cfg) = ctrl.config.clone().try_lock() { - cfg.read(); - ctrl.do_next_profile(&mut cfg) - .unwrap_or_else(|err| warn!("{}", err)); - if let Some(profile) = cfg.power_profiles.get(&cfg.active_profile) { - self.notify_profile(&profile) - .unwrap_or_else(|err| warn!("{}", err)); - } - } + ctrl.do_next_profile() + .unwrap_or_else(|err| warn!("{}", err)); } + self.do_notification(); } /// Fetch the active profile name @@ -154,6 +134,19 @@ impl FanAndCpuZbus { fn notify_profile(&self, profile: &Profile) -> zbus::Result<()> {} } +impl FanAndCpuZbus { + fn do_notification(&self) { + if let Ok(ctrl) = self.inner.try_lock() { + if let Ok(cfg) = ctrl.config.clone().try_lock() { + if let Some(profile) = cfg.power_profiles.get(&cfg.active_profile) { + self.notify_profile(&profile) + .unwrap_or_else(|err| warn!("{}", err)); + } + } + } + } +} + impl crate::ZbusAdd for FanAndCpuZbus { fn add_to_server(self, server: &mut zbus::ObjectServer) { server