From b34cb672c3aadc0edbf4a02fcad94ac3ed7d7f06 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Tue, 6 Dec 2022 14:28:35 +1300 Subject: [PATCH] Fix: ROGCC: log and show more errors on startup --- Cargo.lock | 242 +++++++++++++++++++- rog-control-center/Cargo.toml | 8 + rog-control-center/src/system_state.rs | 89 +++++-- rog-control-center/src/widgets/fan_graph.rs | 5 +- rog-platform/src/platform.rs | 3 +- 5 files changed, 323 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a84a0a8c..92369fe8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,6 +45,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anyhow" version = "1.0.66" @@ -271,6 +280,17 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73b5e5f48b927f04e952dedc932f31995a65a0bf65ec971c74436e51bf6e970d" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -318,6 +338,15 @@ dependencies = [ "futures-lite", ] +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "memchr", +] + [[package]] name = "bumpalo" version = "3.11.1" @@ -429,6 +458,21 @@ dependencies = [ "libc", ] +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim 0.8.0", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "clipboard-win" version = "4.4.2" @@ -693,7 +737,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn", ] @@ -865,6 +909,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + [[package]] name = "emath" version = "0.19.0" @@ -1378,6 +1428,25 @@ dependencies = [ "system-deps", ] +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "globset" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + [[package]] name = "glow" version = "0.11.2" @@ -1541,6 +1610,12 @@ dependencies = [ "syn", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + [[package]] name = "heck" version = "0.3.3" @@ -1602,6 +1677,34 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "ignore" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" +dependencies = [ + "crossbeam-utils", + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "inotify" version = "0.10.0" @@ -1658,6 +1761,15 @@ dependencies = [ "windows-sys 0.42.0", ] +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.4" @@ -1767,6 +1879,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.1.3" @@ -2440,12 +2558,14 @@ dependencies = [ "log", "nix 0.26.1", "notify-rust", + "once_cell", "png_pong", "rog_anime", "rog_aura", "rog_dbus", "rog_platform", "rog_profiles", + "rust-i18n", "serde", "serde_derive", "serde_json", @@ -2529,6 +2649,75 @@ dependencies = [ "libusb1-sys", ] +[[package]] +name = "rust-i18n" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23355ba4db77e057f2a48a4edf15a01c0f914702ef8c47e91edfdde715782f04" +dependencies = [ + "anyhow", + "clap", + "glob", + "itertools", + "once_cell", + "quote", + "regex", + "rust-i18n-extract", + "rust-i18n-macro", + "serde", + "serde_derive", + "toml", +] + +[[package]] +name = "rust-i18n-extract" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38ebea791b21c5bb7b40686ccab333f36b0b29ec29674fec08ea5987c7cfdbbb" +dependencies = [ + "anyhow", + "ignore", + "proc-macro2", + "quote", + "regex", + "rust-i18n-support", + "serde", + "serde_json", + "serde_yaml", + "syn", +] + +[[package]] +name = "rust-i18n-macro" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaebf89167a1d6483d77f316c49b21acd7b3e7cc8a9898c3ed7fe68975b7afca" +dependencies = [ + "glob", + "once_cell", + "proc-macro2", + "quote", + "rust-i18n-support", + "serde", + "serde_json", + "serde_yaml", + "syn", +] + +[[package]] +name = "rust-i18n-support" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd1367f05cbac4263ae801dbadc842b845456d995501e3d33209aec9e91d19" +dependencies = [ + "glob", + "once_cell", + "proc-macro2", + "serde", + "serde_json", + "serde_yaml", +] + [[package]] name = "rustc_version" version = "0.3.3" @@ -2660,6 +2849,18 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_yaml" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" +dependencies = [ + "indexmap", + "ryu", + "serde", + "yaml-rust", +] + [[package]] name = "servo-fontconfig" version = "0.5.1" @@ -2813,6 +3014,12 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "strsim" version = "0.10.0" @@ -2924,6 +3131,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.37" @@ -2944,6 +3160,15 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + [[package]] name = "time" version = "0.3.17" @@ -3154,6 +3379,12 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + [[package]] name = "url" version = "2.3.1" @@ -3681,6 +3912,15 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] + [[package]] name = "zbus" version = "3.5.0" diff --git a/rog-control-center/Cargo.toml b/rog-control-center/Cargo.toml index 01da148f..6c16f4ea 100644 --- a/rog-control-center/Cargo.toml +++ b/rog-control-center/Cargo.toml @@ -41,3 +41,11 @@ png_pong.workspace = true nix = "^0.26.1" tempfile = "3.3.0" + +once_cell = "1.10.0" +rust-i18n = "*" + +[package.metadata.i18n] +available-locales = ["en"] +default-locale = "en" +load-path = "locales" \ No newline at end of file diff --git a/rog-control-center/src/system_state.rs b/rog-control-center/src/system_state.rs index 91f891d6..ef9d7aea 100644 --- a/rog-control-center/src/system_state.rs +++ b/rog-control-center/src/system_state.rs @@ -13,8 +13,9 @@ use supergfxctl::{ }; use crate::{error::Result, notify::EnabledNotifications, RogDbusClientBlocking}; +use log::error; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct BiosState { /// To be shared to a thread that checks notifications. /// It's a bit general in that it won't provide *what* was @@ -51,7 +52,7 @@ impl BiosState { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct ProfilesState { pub list: Vec, pub current: Profile, @@ -76,7 +77,7 @@ impl ProfilesState { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct FanCurvesState { pub show_curve: Profile, pub show_graph: FanCurvePU, @@ -135,7 +136,7 @@ impl FanCurvesState { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct AuraState { pub current_mode: AuraModeNum, pub modes: BTreeMap, @@ -188,7 +189,7 @@ impl AuraState { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct AnimeState { pub bright: u8, pub boot: bool, @@ -231,7 +232,16 @@ impl GfxState { } } -#[derive(Clone, Debug)] +impl Default for GfxState { + fn default() -> Self { + Self { + mode: GfxMode::None, + power_status: GfxPower::Unknown, + } + } +} + +#[derive(Clone, Debug, Default)] pub struct PowerState { pub charge_limit: u8, pub ac_power: bool, @@ -276,19 +286,62 @@ impl SystemState { enabled_notifications: Arc>, supported: &SupportedFunctions, ) -> Result { - let (asus_dbus, conn) = RogDbusClientBlocking::new().unwrap(); - let gfx_dbus = GfxProxyBlocking::new(&conn).unwrap(); + let (asus_dbus, conn) = RogDbusClientBlocking::new()?; + let mut error = None; + let gfx_dbus = GfxProxyBlocking::new(&conn).expect("Couldn't connect to supergfxd"); Ok(Self { keyboard_layout, enabled_notifications, - power_state: PowerState::new(supported, &asus_dbus)?, - bios: BiosState::new(supported, &asus_dbus)?, - aura: AuraState::new(supported, &asus_dbus)?, - anime: AnimeState::new(supported, &asus_dbus)?, - profiles: ProfilesState::new(supported, &asus_dbus)?, - fan_curves: FanCurvesState::new(supported, &asus_dbus)?, - gfx_state: GfxState::new(supported, &gfx_dbus)?, - error: None, + power_state: PowerState::new(supported, &asus_dbus) + .map_err(|e| { + let e = format!("Could not get PowerState state: {e}"); + error!("{e}"); + error = Some(e); + }) + .unwrap_or_default(), + bios: BiosState::new(supported, &asus_dbus) + .map_err(|e| { + let e = format!("Could not get BiosState state: {e}"); + error!("{e}"); + error = Some(e); + }) + .unwrap_or_default(), + aura: AuraState::new(supported, &asus_dbus) + .map_err(|e| { + let e = format!("Could not get AuraState state: {e}"); + error!("{e}"); + error = Some(e); + }) + .unwrap_or_default(), + anime: AnimeState::new(supported, &asus_dbus) + .map_err(|e| { + let e = format!("Could not get AanimeState state: {e}"); + error!("{e}"); + error = Some(e); + }) + .unwrap_or_default(), + profiles: ProfilesState::new(supported, &asus_dbus) + .map_err(|e| { + let e = format!("Could not get ProfilesState state: {e}"); + error!("{e}"); + error = Some(e); + }) + .unwrap_or_default(), + fan_curves: FanCurvesState::new(supported, &asus_dbus) + .map_err(|e| { + let e = format!("Could not get FanCurvesState state: {e}"); + error!("{e}"); + error = Some(e); + }) + .unwrap_or_default(), + gfx_state: GfxState::new(supported, &gfx_dbus) + .map_err(|e| { + let e = format!("Could not get supergfxd state: {e}"); + error!("{e}"); + error = Some(e); + }) + .unwrap_or_default(), + error, tray_should_update: true, app_should_update: true, asus_dbus, @@ -304,8 +357,8 @@ impl SystemState { impl Default for SystemState { fn default() -> Self { - let (asus_dbus, conn) = RogDbusClientBlocking::new().unwrap(); - let gfx_dbus = GfxProxyBlocking::new(&conn).unwrap(); + let (asus_dbus, conn) = RogDbusClientBlocking::new().expect("Couldn't connect to asusd"); + let gfx_dbus = GfxProxyBlocking::new(&conn).expect("Couldn't connect to supergfxd"); Self { keyboard_layout: KeyLayout::ga401_layout(), diff --git a/rog-control-center/src/widgets/fan_graph.rs b/rog-control-center/src/widgets/fan_graph.rs index 1b48c0c2..584ad397 100644 --- a/rog-control-center/src/widgets/fan_graph.rs +++ b/rog-control-center/src/widgets/fan_graph.rs @@ -2,10 +2,7 @@ use egui::{plot::Points, Ui}; use rog_platform::supported::SupportedFunctions; use rog_profiles::{FanCurvePU, Profile}; -use crate::{ - system_state::{FanCurvesState, ProfilesState}, - RogDbusClientBlocking, -}; +use crate::{system_state::FanCurvesState, RogDbusClientBlocking}; pub fn fan_graphs( supported: &SupportedFunctions, diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index a98b5e21..ef84db77 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -65,12 +65,13 @@ impl AsusPlatform { attr_u8!("platform_profile", pp_path); } -#[derive(Serialize, Deserialize, Type, Debug, PartialEq, Eq, Clone, Copy)] +#[derive(Serialize, Deserialize, Default, Type, Debug, PartialEq, Eq, Clone, Copy)] pub enum GpuMode { Discrete, Optimus, Integrated, Egpu, + #[default] Error, NotSupported, }