From d2e938efd2e9e877e7eef9208cdc581b0e89e708 Mon Sep 17 00:00:00 2001 From: Aaron Erhardt Date: Mon, 8 Apr 2024 16:10:59 +0200 Subject: [PATCH] fix: Parse profiles without LedMode without failing --- tailor_api/src/led.rs | 5 ++++- tailor_api/src/profile.rs | 1 + tailord/src/led/mod.rs | 2 +- tailord/src/util.rs | 5 ----- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tailor_api/src/led.rs b/tailor_api/src/led.rs index db021be..f93264a 100644 --- a/tailor_api/src/led.rs +++ b/tailor_api/src/led.rs @@ -1,6 +1,9 @@ -#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)] +#[derive( + Default, Debug, Copy, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash, +)] #[non_exhaustive] pub enum LedControllerMode { + #[default] Rgb, Monochrome, } diff --git a/tailor_api/src/profile.rs b/tailor_api/src/profile.rs index 7976fd5..31f7de1 100644 --- a/tailor_api/src/profile.rs +++ b/tailor_api/src/profile.rs @@ -22,5 +22,6 @@ pub struct LedProfile { pub device_name: String, pub function: String, pub profile: String, + #[serde(default)] pub mode: LedControllerMode, } diff --git a/tailord/src/led/mod.rs b/tailord/src/led/mod.rs index 6778363..792bc3a 100644 --- a/tailord/src/led/mod.rs +++ b/tailord/src/led/mod.rs @@ -32,7 +32,7 @@ impl LedRuntime { info: LedDeviceInfo { device_name: data.controller.device_name.clone(), function: data.controller.function.clone(), - mode: data.controller.mode().clone(), + mode: data.controller.mode(), }, profile_sender, color_sender, diff --git a/tailord/src/util.rs b/tailord/src/util.rs index 86cc05a..0435ac1 100644 --- a/tailord/src/util.rs +++ b/tailord/src/util.rs @@ -1,5 +1,4 @@ use serde::{de::DeserializeOwned, Serialize}; -use std::ffi::OsString; use zbus::fdo; pub fn normalize_json_path(base_path: &str, name: &str) -> fdo::Result { @@ -12,10 +11,6 @@ pub fn normalize_json_path(base_path: &str, name: &str) -> fdo::Result { Err(fdo::Error::InvalidArgs(format!( "Can't use '.' in profile names: `{name}`" ))) - } else if let Err(err) = OsString::try_from(name) { - Err(fdo::Error::InvalidArgs(format!( - "Can't convert `{name}` to OS string: `{err}`" - ))) } else if base_path.is_empty() { Ok(format!("{name}.json")) } else {