mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Clean up unwrap()'s. Print out info in asusctl if error
This commit is contained in:
@@ -13,7 +13,12 @@ use rog_anime::{
|
||||
};
|
||||
use rog_supported::AnimeSupportedFunctions;
|
||||
use rusb::{Device, DeviceHandle};
|
||||
use std::{cell::RefCell, error::Error, sync::{Arc, Mutex}, thread::sleep};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
error::Error,
|
||||
sync::{Arc, Mutex},
|
||||
thread::sleep,
|
||||
};
|
||||
use std::{
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
time::Duration,
|
||||
@@ -176,12 +181,17 @@ impl CtrlAnime {
|
||||
for action in actions.iter() {
|
||||
match action {
|
||||
ActionData::Animation(frames) => {
|
||||
rog_anime::run_animation(frames, thread_exit.clone(), &|frame| {
|
||||
if rog_anime::run_animation(frames, thread_exit.clone(), &|frame| {
|
||||
if let Ok(lock) = inner.try_lock() {
|
||||
lock.write_data_buffer(frame);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
.map_err(|err| warn!("rog_anime::run_animation: {}", err))
|
||||
.is_err()
|
||||
{
|
||||
break 'main;
|
||||
};
|
||||
|
||||
if thread_exit.load(Ordering::SeqCst) {
|
||||
break 'main;
|
||||
@@ -289,9 +299,11 @@ pub struct CtrlAnimeTask<'a> {
|
||||
|
||||
impl<'a> CtrlAnimeTask<'a> {
|
||||
pub fn new(inner: Arc<Mutex<CtrlAnime>>) -> Self {
|
||||
let connection = Connection::new_system().unwrap();
|
||||
let connection =
|
||||
Connection::new_system().expect("CtrlAnimeTask could not create dbus connection");
|
||||
|
||||
let manager = ManagerProxy::new(&connection).unwrap();
|
||||
let manager =
|
||||
ManagerProxy::new(&connection).expect("CtrlAnimeTask could not create ManagerProxy");
|
||||
|
||||
let c1 = inner.clone();
|
||||
// Run this action when the system starts shutting down
|
||||
|
||||
@@ -62,9 +62,11 @@ pub struct CtrlKbdLedTask<'a> {
|
||||
|
||||
impl<'a> CtrlKbdLedTask<'a> {
|
||||
pub fn new(inner: Arc<Mutex<CtrlKbdLed>>) -> Self {
|
||||
let connection = Connection::new_system().unwrap();
|
||||
let connection =
|
||||
Connection::new_system().expect("CtrlKbdLedTask could not create dbus connection");
|
||||
|
||||
let manager = ManagerProxy::new(&connection).unwrap();
|
||||
let manager =
|
||||
ManagerProxy::new(&connection).expect("CtrlKbdLedTask could not create ManagerProxy");
|
||||
|
||||
let c1 = inner.clone();
|
||||
// Run this action when the system wakes up from sleep
|
||||
@@ -239,7 +241,7 @@ impl CtrlKbdLed {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn next_brightness(&mut self) -> Result<(), RogError> {
|
||||
pub fn next_brightness(&mut self) -> Result<(), RogError> {
|
||||
let mut bright = (self.config.brightness as u32) + 1;
|
||||
if bright > 3 {
|
||||
bright = 0;
|
||||
@@ -249,7 +251,7 @@ impl CtrlKbdLed {
|
||||
self.set_brightness(self.config.brightness)
|
||||
}
|
||||
|
||||
pub fn prev_brightness(&mut self) -> Result<(), RogError> {
|
||||
pub fn prev_brightness(&mut self) -> Result<(), RogError> {
|
||||
let mut bright = self.config.brightness as u32;
|
||||
if bright == 0 {
|
||||
bright = 3;
|
||||
|
||||
@@ -100,15 +100,15 @@ impl CtrlPlatformProfile {
|
||||
|
||||
match config.active {
|
||||
Profile::Balanced => {
|
||||
Profile::set_profile(Profile::Performance);
|
||||
Profile::set_profile(Profile::Performance)?;
|
||||
config.active = Profile::Performance;
|
||||
}
|
||||
Profile::Performance => {
|
||||
Profile::set_profile(Profile::Quiet);
|
||||
Profile::set_profile(Profile::Quiet)?;
|
||||
config.active = Profile::Quiet;
|
||||
}
|
||||
Profile::Quiet => {
|
||||
Profile::set_profile(Profile::Balanced);
|
||||
Profile::set_profile(Profile::Balanced)?;
|
||||
config.active = Profile::Balanced;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,9 @@ impl ProfileZbus {
|
||||
if let Ok(mut cfg) = ctrl.config.try_lock() {
|
||||
// Read first just incase the user has modified the config before calling this
|
||||
cfg.read();
|
||||
Profile::set_profile(profile);
|
||||
Profile::set_profile(profile)
|
||||
.map_err(|e| warn!("Profile::set_profile, {}", e))
|
||||
.ok();
|
||||
cfg.active = profile;
|
||||
}
|
||||
ctrl.save_config();
|
||||
|
||||
@@ -168,7 +168,7 @@ impl CtrlRogBios {
|
||||
.map_err(|err| RogError::Path(path.into(), err))?;
|
||||
|
||||
let mut data = Vec::new();
|
||||
file.read_to_end(&mut data).unwrap();
|
||||
file.read_to_end(&mut data)?;
|
||||
|
||||
let idx = data.len() - 1;
|
||||
if dedicated {
|
||||
@@ -269,7 +269,7 @@ impl CtrlRogBios {
|
||||
RogError::Write(module_include.to_string_lossy().to_string(), err)
|
||||
})?;
|
||||
// add nvidia modules to module_include
|
||||
file.write_all(modules.concat().as_bytes()).unwrap();
|
||||
file.write_all(modules.concat().as_bytes())?;
|
||||
} else {
|
||||
let file = std::fs::OpenOptions::new()
|
||||
.read(true)
|
||||
@@ -292,7 +292,7 @@ impl CtrlRogBios {
|
||||
.map_err(|err| {
|
||||
RogError::Write(module_include.to_string_lossy().to_string(), err)
|
||||
})?;
|
||||
std::io::BufWriter::new(file).write_all(&buf).unwrap();
|
||||
std::io::BufWriter::new(file).write_all(&buf)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
let supported = SupportedFunctions::get_supported();
|
||||
print_board_info();
|
||||
println!("{}", serde_json::to_string_pretty(&supported).unwrap());
|
||||
println!("{}", serde_json::to_string_pretty(&supported)?);
|
||||
|
||||
// Collect tasks for task thread
|
||||
let mut tasks: Vec<Box<dyn CtrlTask + Send>> = Vec::new();
|
||||
|
||||
@@ -10,10 +10,8 @@ pub const ASUS_KEYBOARD_DEVICES: [&str; 4] = ["1866", "1869", "1854", "19b6"];
|
||||
pub fn print_board_info() {
|
||||
let dmi = sysfs_class::DmiId::default();
|
||||
let board_name = dmi.board_name().expect("Could not get board_name");
|
||||
let prod_name = dmi.product_name().expect("Could not get product_name");
|
||||
let prod_family = dmi.product_family().expect("Could not get product_family");
|
||||
|
||||
info!("Product name: {}", prod_name.trim());
|
||||
info!("Product family: {}", prod_family.trim());
|
||||
info!("Board name: {}", board_name.trim());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user