mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Remove many unwraps or change to maps
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -46,7 +46,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "asus-nb-ctrl"
|
name = "asus-nb-ctrl"
|
||||||
version = "2.0.2"
|
version = "2.0.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"asus-nb",
|
"asus-nb",
|
||||||
"ctrl-gfx",
|
"ctrl-gfx",
|
||||||
@@ -189,7 +189,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ctrl-gfx"
|
name = "ctrl-gfx"
|
||||||
version = "2.1.0"
|
version = "2.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"sysfs-class",
|
"sysfs-class",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "asus-nb-ctrl"
|
name = "asus-nb-ctrl"
|
||||||
version = "2.0.2"
|
version = "2.0.3"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Luke <luke@ljones.dev>"]
|
authors = ["Luke <luke@ljones.dev>"]
|
||||||
|
|||||||
@@ -40,7 +40,11 @@ impl crate::ZbusAdd for CtrlAnimeDisplay {
|
|||||||
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
||||||
server
|
server
|
||||||
.at(&"/org/asuslinux/Anime".try_into().unwrap(), self)
|
.at(&"/org/asuslinux/Anime".try_into().unwrap(), self)
|
||||||
.unwrap();
|
.map_err(|err| {
|
||||||
|
warn!("CtrlAnimeDisplay: add_to_server {}", err);
|
||||||
|
err
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,18 @@ trait Dbus {
|
|||||||
impl Dbus for CtrlCharge {
|
impl Dbus for CtrlCharge {
|
||||||
fn set_limit(&mut self, limit: u8) {
|
fn set_limit(&mut self, limit: u8) {
|
||||||
if let Ok(mut config) = self.config.try_lock() {
|
if let Ok(mut config) = self.config.try_lock() {
|
||||||
self.set(limit, &mut config).unwrap();
|
self.set(limit, &mut config)
|
||||||
self.notify_charge(limit).unwrap();
|
.map_err(|err| {
|
||||||
|
warn!("CtrlCharge: set_limit {}", err);
|
||||||
|
err
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
self.notify_charge(limit)
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("CtrlCharge: set_limit {}", err);
|
||||||
|
err
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +56,11 @@ impl crate::ZbusAdd for CtrlCharge {
|
|||||||
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
||||||
server
|
server
|
||||||
.at(&"/org/asuslinux/Charge".try_into().unwrap(), self)
|
.at(&"/org/asuslinux/Charge".try_into().unwrap(), self)
|
||||||
.unwrap();
|
.map_err(|err| {
|
||||||
|
warn!("CtrlCharge: add_to_server {}", err);
|
||||||
|
err
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,11 @@ impl crate::ZbusAdd for DbusFanAndCpu {
|
|||||||
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
||||||
server
|
server
|
||||||
.at(&"/org/asuslinux/Profile".try_into().unwrap(), self)
|
.at(&"/org/asuslinux/Profile".try_into().unwrap(), self)
|
||||||
.unwrap();
|
.map_err(|err| {
|
||||||
|
warn!("DbusFanAndCpu: {}", err);
|
||||||
|
err
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +315,7 @@ impl CtrlFanAndCPU {
|
|||||||
|
|
||||||
let boost = if mode_config.turbo { "1" } else { "0" }; // opposite of Intel
|
let boost = if mode_config.turbo { "1" } else { "0" }; // opposite of Intel
|
||||||
file.write_all(boost.as_bytes())
|
file.write_all(boost.as_bytes())
|
||||||
.map_err(|err| RogError::Write(AMD_BOOST_PATH.into(), err))?;
|
.map_err(|err| RogError::Write(AMD_BOOST_PATH.into(), err))?;
|
||||||
info!("AMD CPU Turbo: {}", boost);
|
info!("AMD CPU Turbo: {}", boost);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ impl crate::ZbusAdd for DbusKbdBacklight {
|
|||||||
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
||||||
server
|
server
|
||||||
.at(&"/org/asuslinux/Led".try_into().unwrap(), self)
|
.at(&"/org/asuslinux/Led".try_into().unwrap(), self)
|
||||||
.unwrap();
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,10 +58,11 @@ impl DbusKbdBacklight {
|
|||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.unwrap_or_else(|err| warn!("{}", err));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let json = serde_json::to_string(&data).unwrap();
|
if let Ok(json) = serde_json::to_string(&data) {
|
||||||
ctrl.do_command(data, &mut cfg)
|
ctrl.do_command(data, &mut cfg)
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.unwrap_or_else(|err| warn!("{}", err));
|
||||||
self.notify_led(&json).unwrap();
|
self.notify_led(&json).ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,8 +234,11 @@ impl CtrlKbdBacklight {
|
|||||||
RogError::Udev("parent_with_subsystem_devtype failed".into(), err)
|
RogError::Udev("parent_with_subsystem_devtype failed".into(), err)
|
||||||
})?
|
})?
|
||||||
{
|
{
|
||||||
if parent.attribute_value("idProduct").unwrap() == id_product {
|
if parent
|
||||||
// && device.parent().unwrap().sysnum().unwrap() == 3
|
.attribute_value("idProduct")
|
||||||
|
.ok_or(RogError::NotFound("LED idProduct".into()))?
|
||||||
|
== id_product
|
||||||
|
{
|
||||||
if let Some(dev_node) = device.devnode() {
|
if let Some(dev_node) = device.devnode() {
|
||||||
info!("Using device at: {:?} for LED control", dev_node);
|
info!("Using device at: {:?} for LED control", dev_node);
|
||||||
return Ok(dev_node.to_string_lossy().to_string());
|
return Ok(dev_node.to_string_lossy().to_string());
|
||||||
@@ -264,13 +268,17 @@ impl CtrlKbdBacklight {
|
|||||||
RogError::Udev("match_property failed".into(), err)
|
RogError::Udev("match_property failed".into(), err)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
for device in enumerator.scan_devices().map_err(|err| {
|
for device in enumerator
|
||||||
warn!("{}", err);
|
.scan_devices()
|
||||||
err
|
.map_err(|err| {
|
||||||
}).map_err(|err| {
|
warn!("{}", err);
|
||||||
warn!("{}", err);
|
err
|
||||||
RogError::Udev("scan_devices failed".into(), err)
|
})
|
||||||
})? {
|
.map_err(|err| {
|
||||||
|
warn!("{}", err);
|
||||||
|
RogError::Udev("scan_devices failed".into(), err)
|
||||||
|
})?
|
||||||
|
{
|
||||||
if let Some(dev_node) = device.devnode() {
|
if let Some(dev_node) = device.devnode() {
|
||||||
if let Some(inum) = device.property_value("ID_USB_INTERFACE_NUM") {
|
if let Some(inum) = device.property_value("ID_USB_INTERFACE_NUM") {
|
||||||
if let Some(iface) = iface {
|
if let Some(iface) = iface {
|
||||||
@@ -298,8 +306,7 @@ impl CtrlKbdBacklight {
|
|||||||
fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
||||||
if let Some(led_node) = &self.led_node {
|
if let Some(led_node) = &self.led_node {
|
||||||
if let Ok(mut file) = OpenOptions::new().write(true).open(led_node) {
|
if let Ok(mut file) = OpenOptions::new().write(true).open(led_node) {
|
||||||
file.write_all(message).unwrap();
|
return file.write_all(message).map_err(|err| RogError::Write("write_bytes".into(), err));
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(RogError::NotSupported)
|
Err(RogError::NotSupported)
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
for ctrl in tasks.iter() {
|
for ctrl in tasks.iter() {
|
||||||
if let Ok(mut lock) = ctrl.try_lock() {
|
if let Ok(mut lock) = ctrl.try_lock() {
|
||||||
lock.do_task().unwrap();
|
lock.do_task().ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use config::Config;
|
|||||||
use crate::error::RogError;
|
use crate::error::RogError;
|
||||||
use zbus::ObjectServer;
|
use zbus::ObjectServer;
|
||||||
|
|
||||||
pub static VERSION: &str = "2.0.2";
|
pub static VERSION: &str = "2.0.3";
|
||||||
|
|
||||||
pub trait Reloadable {
|
pub trait Reloadable {
|
||||||
fn reload(&mut self) -> Result<(), RogError>;
|
fn reload(&mut self) -> Result<(), RogError>;
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ impl AuraDbusClient {
|
|||||||
"/org/asuslinux/Gfx",
|
"/org/asuslinux/Gfx",
|
||||||
Duration::from_millis(5000),
|
Duration::from_millis(5000),
|
||||||
);
|
);
|
||||||
let x = proxy.power().unwrap();
|
let x = proxy.power()?;
|
||||||
Ok(x)
|
Ok(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ impl AuraDbusClient {
|
|||||||
"/org/asuslinux/Gfx",
|
"/org/asuslinux/Gfx",
|
||||||
Duration::from_millis(5000),
|
Duration::from_millis(5000),
|
||||||
);
|
);
|
||||||
let x = proxy.vendor().unwrap();
|
let x = proxy.vendor()?;
|
||||||
Ok(x)
|
Ok(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ use std::error::Error;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("Version 1.0.1");
|
||||||
|
|
||||||
let mut cfg = Config::read_new()?;
|
let mut cfg = Config::read_new()?;
|
||||||
let mut last_profile = String::new();
|
let mut last_profile = String::new();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ctrl-gfx"
|
name = "ctrl-gfx"
|
||||||
version = "2.1.0"
|
version = "2.1.1"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Luke <luke@ljones.dev>"]
|
authors = ["Luke <luke@ljones.dev>"]
|
||||||
|
|||||||
@@ -37,15 +37,11 @@ use std::convert::TryInto;
|
|||||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
||||||
impl Dbus for CtrlGraphics {
|
impl Dbus for CtrlGraphics {
|
||||||
fn vendor(&self) -> String {
|
fn vendor(&self) -> String {
|
||||||
Self::get_vendor()
|
Self::get_vendor().unwrap_or_else(|err| format!("Get vendor failed: {}", err))
|
||||||
.map_err(|err| format!("Get vendor failed: {}", err))
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn power(&self) -> String {
|
fn power(&self) -> String {
|
||||||
Self::get_runtime_status()
|
Self::get_runtime_status().unwrap_or_else(|err| format!("Get power status failed: {}", err))
|
||||||
.map_err(|err| format!("Get power status failed: {}", err))
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_vendor(&mut self, vendor: String) {
|
fn set_vendor(&mut self, vendor: String) {
|
||||||
@@ -149,7 +145,11 @@ impl CtrlGraphics {
|
|||||||
pub fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
pub fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
||||||
server
|
server
|
||||||
.at(&"/org/asuslinux/Gfx".try_into().unwrap(), self)
|
.at(&"/org/asuslinux/Gfx".try_into().unwrap(), self)
|
||||||
.unwrap();
|
.map_err(|err| {
|
||||||
|
warn!("CtrlGraphics: add_to_server {}", err);
|
||||||
|
err
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reload(&mut self) -> Result<(), Box<dyn Error>> {
|
pub fn reload(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
@@ -328,8 +328,7 @@ impl CtrlGraphics {
|
|||||||
// }
|
// }
|
||||||
pub fn get_runtime_status() -> Result<String, GfxError> {
|
pub fn get_runtime_status() -> Result<String, GfxError> {
|
||||||
const PATH: &str = "/sys/bus/pci/devices/0000:01:00.0/power/runtime_status";
|
const PATH: &str = "/sys/bus/pci/devices/0000:01:00.0/power/runtime_status";
|
||||||
let buf = std::fs::read_to_string(PATH)
|
let buf = std::fs::read_to_string(PATH).map_err(|err| GfxError::Read(PATH.into(), err))?;
|
||||||
.map_err(|err| GfxError::Read(PATH.into(), err))?;
|
|
||||||
Ok(buf)
|
Ok(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ impl GraphicsDevice {
|
|||||||
warn!("{}: Already removed", func.id());
|
warn!("{}: Already removed", func.id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info!("Remmoved all gfx devices");
|
info!("Removed all gfx devices");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user