diff --git a/.cargo-husky/hooks/pre-commit b/.cargo-husky/hooks/pre-commit index 14a00bb3..97a2f878 100755 --- a/.cargo-husky/hooks/pre-commit +++ b/.cargo-husky/hooks/pre-commit @@ -12,7 +12,7 @@ echo '+cargo clippy --all -- -D warnings' cargo clippy --all -- -D warnings echo '+cargo test --all' -cargo test --all +cargo test --all --test-threads=1 echo '+cargo cranky' -cargo cranky \ No newline at end of file +cargo cranky diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 38c85e3a..f4e3f7b0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,7 +52,7 @@ test: <<: *rust_cache script: - mkdir -p .git/hooks > /dev/null - - cargo test --all + - cargo test --all --test-threads=1 release: only: diff --git a/CHANGELOG.md b/CHANGELOG.md index e40a47ae..ac962820 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Add G512L laptop DB entry + +### Changed +- Add more tests to verify things + +### Fix +- asusctl incorrectly assumes fan-curves unsupported. Now fixed. + ## [v6.0.7] ### Changed diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 9392232d..84a5b577 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -5,7 +5,6 @@ use std::process::Command; use std::thread::sleep; use anime_cli::{AnimeActions, AnimeCommand}; -use asusd::ctrl_fancurves::FAN_CURVE_ZBUS_NAME; use aura_cli::{LedPowerCommand1, LedPowerCommand2}; use dmi_id::DMIID; use fan_curve_cli::FanCurveCommand; @@ -172,7 +171,7 @@ fn do_parsed( handle_throttle_profile(&conn, supported_properties, cmd)? } Some(CliCommand::FanCurve(cmd)) => { - handle_fan_curve(&conn, supported_interfaces, cmd)?; + handle_fan_curve(&conn, cmd)?; } Some(CliCommand::Graphics(_)) => do_gfx(), Some(CliCommand::Anime(cmd)) => handle_anime(&conn, cmd)?, @@ -807,13 +806,13 @@ fn handle_throttle_profile( fn handle_fan_curve( conn: &Connection, - supported: &[String], cmd: &FanCurveCommand, ) -> Result<(), Box> { - if !supported.contains(&FAN_CURVE_ZBUS_NAME.to_string()) { - println!("Fan-curves not supported by either this kernel or by the laptop."); + let Ok(fan_proxy) = FanCurvesProxyBlocking::new(conn).map_err(|e| { + println!("Fan-curves not supported by either this kernel or by the laptop: {e:?}"); + }) else { return Err(ProfileError::NotSupported.into()); - } + }; if !cmd.get_enabled && !cmd.default && cmd.mod_profile.is_none() { if !cmd.help { @@ -838,7 +837,6 @@ fn handle_fan_curve( } let plat_proxy = PlatformProxyBlocking::new(conn)?; - let fan_proxy = FanCurvesProxyBlocking::new(conn)?; if cmd.get_enabled { let profile = plat_proxy.throttle_thermal_policy()?; let curves = fan_proxy.fan_curve_data(profile)?; diff --git a/asusd/src/ctrl_aura/config.rs b/asusd/src/ctrl_aura/config.rs index de05efdc..e09ad63e 100644 --- a/asusd/src/ctrl_aura/config.rs +++ b/asusd/src/ctrl_aura/config.rs @@ -134,12 +134,16 @@ impl AuraConfig { #[cfg(test)] mod tests { - use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour}; + use rog_aura::keyboard::AuraPowerState; + use rog_aura::{ + AuraEffect, AuraModeNum, AuraZone, Colour, Direction, LedBrightness, PowerZones, Speed, + }; use super::AuraConfig; #[test] fn set_multizone_4key_config() { + std::env::set_var("BOARD_NAME", ""); let mut config = AuraConfig::new("19b6"); let effect = AuraEffect { @@ -230,6 +234,7 @@ mod tests { #[test] fn set_multizone_multimode_config() { + std::env::set_var("BOARD_NAME", ""); let mut config = AuraConfig::new("19b6"); let effect = AuraEffect { @@ -274,4 +279,66 @@ mod tests { let sta = res.get(&AuraModeNum::Pulse).unwrap(); assert_eq!(sta.len(), 1); } + + #[test] + fn verify_0x1866_g531i() { + std::env::set_var("BOARD_NAME", "G513I"); + let mut config = AuraConfig::new("1866"); + + assert_eq!(config.brightness, LedBrightness::Med); + assert_eq!(config.builtins.len(), 5); + assert_eq!( + config.builtins.first_entry().unwrap().get(), + &AuraEffect { + mode: AuraModeNum::Static, + zone: AuraZone::None, + colour1: Colour { r: 166, g: 0, b: 0 }, + colour2: Colour { r: 0, g: 0, b: 0 }, + speed: Speed::Med, + direction: Direction::Right + } + ); + assert_eq!(config.enabled.states.len(), 1); + assert_eq!( + config.enabled.states[0], + AuraPowerState { + zone: PowerZones::KeyboardAndLightbar, + boot: true, + awake: true, + sleep: true, + shutdown: true + } + ); + } + + #[test] + fn verify_0x19b6_g634j() { + std::env::set_var("BOARD_NAME", "G634J"); + let mut config = AuraConfig::new("19b6"); + + assert_eq!(config.brightness, LedBrightness::Med); + assert_eq!(config.builtins.len(), 12); + assert_eq!( + config.builtins.first_entry().unwrap().get(), + &AuraEffect { + mode: AuraModeNum::Static, + zone: AuraZone::None, + colour1: Colour { r: 166, g: 0, b: 0 }, + colour2: Colour { r: 0, g: 0, b: 0 }, + speed: Speed::Med, + direction: Direction::Right + } + ); + assert_eq!(config.enabled.states.len(), 4); + assert_eq!( + config.enabled.states[0], + AuraPowerState { + zone: PowerZones::Keyboard, + boot: true, + awake: true, + sleep: true, + shutdown: true + } + ); + } } diff --git a/rog-aura/data/aura_support.ron b/rog-aura/data/aura_support.ron index 11e44626..bc1928a0 100644 --- a/rog-aura/data/aura_support.ron +++ b/rog-aura/data/aura_support.ron @@ -80,6 +80,15 @@ advanced_type: None, power_zones: [Keyboard], ), + ( + device_name: "G512L", + product_id: "", + layout_name: "g512", + basic_modes: [Static, Breathe, Strobe, Rainbow, Pulse], + basic_zones: [Key1, Key2, Key3, Key4], + advanced_type: None, + power_zones: [Keyboard, Lightbar], + ), ( device_name: "G513I", product_id: "", diff --git a/rog-aura/src/aura_detection.rs b/rog-aura/src/aura_detection.rs index 65657c52..6eb4de0e 100644 --- a/rog-aura/src/aura_detection.rs +++ b/rog-aura/src/aura_detection.rs @@ -1,3 +1,5 @@ +use std::env; + use dmi_id::DMIID; use log::{error, info, warn}; use serde_derive::{Deserialize, Serialize}; @@ -60,7 +62,10 @@ impl LedSupportData { /// matches against laptops first, then will proceed with matching the /// `device_name` if there are no DMI matches. pub fn get_data(product_id: &str) -> Self { - let dmi = DMIID::new().unwrap_or_default(); + let mut dmi = DMIID::new().unwrap_or_default(); + if let Ok(board_name) = env::var("BOARD_NAME") { + dmi.board_name = board_name; + } // let prod_family = dmi.product_family().expect("Could not get // product_family"); diff --git a/rog-aura/src/builtin_modes.rs b/rog-aura/src/builtin_modes.rs index ceca2c79..34317444 100644 --- a/rog-aura/src/builtin_modes.rs +++ b/rog-aura/src/builtin_modes.rs @@ -434,7 +434,7 @@ impl From for i32 { /// ``` #[typeshare] #[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))] -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct AuraEffect { /// The effect type pub mode: AuraModeNum, diff --git a/rog-aura/src/keyboard/layouts.rs b/rog-aura/src/keyboard/layouts.rs index 09e8321c..4a363128 100644 --- a/rog-aura/src/keyboard/layouts.rs +++ b/rog-aura/src/keyboard/layouts.rs @@ -488,7 +488,7 @@ mod tests { let rows = &data.key_rows; for row in rows { for k in &row.row { - if data.key_shapes.get(&k.1).is_some() { + if data.key_shapes.contains_key(&k.1) { unused.remove(&k.1); } else { panic!("Key {:?} was missing matching shape {}", k.0, k.1); diff --git a/rog-control-center/src/ui/setup_aura.rs b/rog-control-center/src/ui/setup_aura.rs index b7ab999a..7f300156 100644 --- a/rog-control-center/src/ui/setup_aura.rs +++ b/rog-control-center/src/ui/setup_aura.rs @@ -2,6 +2,7 @@ use std::sync::{Arc, Mutex}; use log::{error, info}; use rog_aura::keyboard::LaptopAuraPower; +use rog_aura::{AuraDeviceType, PowerZones}; use rog_dbus::zbus_aura::AuraProxy; use slint::{ComponentHandle, Model, RgbaColor, SharedString}; @@ -84,24 +85,40 @@ pub fn setup_aura_page(ui: &MainWindow, _states: Arc>) { set_ui_props_async!(handle, aura, AuraPageData, led_power); set_ui_props_async!(handle, aura, AuraPageData, device_type); - if let Ok(pow3r) = aura.supported_power_zones().await { + if let Ok(mut pow3r) = aura.supported_power_zones().await { + let dev_type = aura + .device_type() + .await + .unwrap_or(AuraDeviceType::LaptopPost2021); log::debug!("Available LED power modes {pow3r:?}"); handle .upgrade_in_event_loop(move |handle| { - let power: Vec = pow3r.iter().map(|p| (*p).into()).collect(); let names: Vec = handle .global::() .get_power_zone_names() .iter() .collect(); - let names: Vec = - pow3r.iter().map(|n| names[(*n) as usize].clone()).collect(); - handle - .global::() - .set_supported_power_zones(power.as_slice().into()); - handle - .global::() - .set_power_zone_names_old(names.as_slice().into()); + + if dev_type.is_old_laptop() { + // Need to add the specific KeyboardAndLightbar + if pow3r.contains(&PowerZones::Keyboard) + && pow3r.contains(&PowerZones::Lightbar) + { + pow3r.push(PowerZones::KeyboardAndLightbar); + } + let names: Vec = + pow3r.iter().map(|n| names[(*n) as usize].clone()).collect(); + handle + .global::() + .set_power_zone_names_old(names.as_slice().into()); + } else { + let power: Vec = + pow3r.iter().map(|p| (*p).into()).collect(); + + handle + .global::() + .set_supported_power_zones(power.as_slice().into()); + } }) .ok(); } diff --git a/rog-control-center/translations/en/rog-control-center.po b/rog-control-center/translations/en/rog-control-center.po index 02407a35..7c44420d 100644 --- a/rog-control-center/translations/en/rog-control-center.po +++ b/rog-control-center/translations/en/rog-control-center.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2024-05-14 05:08+0000\n" +"POT-Creation-Date: 2024-05-16 21:35+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -642,42 +642,42 @@ msgctxt "AuraPowerGroupOld" msgid "Sleep" msgstr "" -#: rog-control-center/ui/main_window.slint:50 +#: rog-control-center/ui/main_window.slint:51 msgctxt "MainWindow" msgid "ROG" msgstr "" -#: rog-control-center/ui/main_window.slint:52 +#: rog-control-center/ui/main_window.slint:53 msgctxt "Menu1" msgid "System Control" msgstr "" -#: rog-control-center/ui/main_window.slint:53 +#: rog-control-center/ui/main_window.slint:54 msgctxt "Menu2" msgid "Keyboard Aura" msgstr "" -#: rog-control-center/ui/main_window.slint:54 +#: rog-control-center/ui/main_window.slint:55 msgctxt "Menu3" msgid "AniMe Matrix" msgstr "" -#: rog-control-center/ui/main_window.slint:55 +#: rog-control-center/ui/main_window.slint:56 msgctxt "Menu4" msgid "Fan Curves" msgstr "" -#: rog-control-center/ui/main_window.slint:56 +#: rog-control-center/ui/main_window.slint:57 msgctxt "Menu5" msgid "App Settings" msgstr "" -#: rog-control-center/ui/main_window.slint:57 +#: rog-control-center/ui/main_window.slint:58 msgctxt "Menu6" msgid "About" msgstr "" -#: rog-control-center/ui/main_window.slint:69 +#: rog-control-center/ui/main_window.slint:70 msgctxt "MainWindow" msgid "Quit" msgstr "" diff --git a/rog-control-center/ui/main_window.slint b/rog-control-center/ui/main_window.slint index ca3ea77c..d49d9599 100644 --- a/rog-control-center/ui/main_window.slint +++ b/rog-control-center/ui/main_window.slint @@ -5,6 +5,7 @@ import { SideBar } from "widgets/sidebar.slint"; import { PageAbout } from "pages/about.slint"; import { PageFans } from "pages/fans.slint"; import { PageAnime, AnimePageData } from "pages/anime.slint"; +import { RogItem } from "widgets/common.slint"; import { PageAura } from "pages/aura.slint"; import { Node } from "widgets/graph.slint"; export { Node } @@ -178,4 +179,39 @@ export component MainWindow inherits Window { } } } + + if SomeError.error_message != "": Rectangle { + x: 0px; + y: 0px; + width: root.width; + height: root.height; + padding: 10px; + + background: Palette.background; + border-color: Palette.border; + border-width: 3px; + border-radius: 10px; + + VerticalBox { + RogItem { + min-height: 50px; + max-height: 100px; + Text { + text <=> SomeError.error_message; + font-size: 18px; + } + } + + Text { + text <=> SomeError.error_help; + horizontal-alignment: TextHorizontalAlignment.center; + vertical-alignment: TextVerticalAlignment.center; + } + } + } +} + +export global SomeError { + in property error_message: ""; + in property error_help: ""; }