From ebefecd0a290828e2ddda660710114b75c709514 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Thu, 17 Oct 2024 11:48:21 +0900 Subject: [PATCH] fix: accent color type error close: https://github.com/waycrate/xdg-desktop-portal-luminous/issues/37 --- libs/accessdialog/src/lib.rs | 8 +++----- src/main.rs | 3 ++- src/settings.rs | 29 +++++++++-------------------- src/settings/config.rs | 6 +++--- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/libs/accessdialog/src/lib.rs b/libs/accessdialog/src/lib.rs index 27695e9..5abd78b 100644 --- a/libs/accessdialog/src/lib.rs +++ b/libs/accessdialog/src/lib.rs @@ -21,9 +21,7 @@ pub fn confirmgui(title: String, information: String) -> bool { ui.set_information(information.into()); let (sender, receiver) = mpsc::channel(); init_slots(&ui, sender); - if let Ok(message) = receiver.recv_timeout(std::time::Duration::from_nanos(300)) { - message - } else { - false - } + receiver + .recv_timeout(std::time::Duration::from_nanos(300)) + .unwrap_or_default() } diff --git a/src/main.rs b/src/main.rs index 42e632d..bf7c58e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,7 +117,8 @@ async fn async_watch>(path: P) -> notify::Result<()> { AccentColor { color: config.get_accent_color(), } - .into(), + .try_into() + .unwrap(), ) .await; } diff --git a/src/settings.rs b/src/settings.rs index 1b8ffeb..c509639 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -2,7 +2,7 @@ mod config; use tokio::sync::Mutex; use zbus::{fdo, interface, SignalContext}; -use zbus::zvariant::{Array, DeserializeDict, OwnedValue, SerializeDict, Signature, Type}; +use zbus::zvariant::{DeserializeDict, OwnedValue, SerializeDict, Type, Value}; const DEFAULT_COLOR: u32 = 0; const DARK_COLOR: u32 = 1; @@ -21,21 +21,10 @@ pub use self::config::SettingsConfig; pub static SETTING_CONFIG: Lazy>> = Lazy::new(|| Arc::new(Mutex::new(SettingsConfig::config_from_file()))); -#[derive(DeserializeDict, SerializeDict, Clone, Copy, PartialEq, Type)] +#[derive(DeserializeDict, SerializeDict, Clone, Copy, PartialEq, Type, OwnedValue, Value)] #[zvariant(signature = "dict")] pub struct AccentColor { - pub color: [f64; 3], -} - -impl From for OwnedValue { - fn from(val: AccentColor) -> Self { - let arraysignature = Signature::try_from("d").unwrap(); - let mut array = Array::new(arraysignature); - for col in val.color { - array.append(col.into()).unwrap(); - } - OwnedValue::try_from(array).unwrap() - } + pub color: (f64, f64, f64), } #[derive(Debug)] @@ -57,10 +46,10 @@ impl SettingsBackend { return Ok(OwnedValue::from(config.get_color_scheme())); } if key == ACCENT_COLOR { - return Ok(AccentColor { + return Ok(OwnedValue::try_from(AccentColor { color: config.get_accent_color(), - } - .into()); + }) + .unwrap()); } Err(zbus::fdo::Error::Failed("No such namespace".to_string())) } @@ -74,10 +63,10 @@ impl SettingsBackend { output.insert(COLOR_SCHEME.to_string(), config.get_color_scheme().into()); output.insert( ACCENT_COLOR.to_string(), - AccentColor { + OwnedValue::try_from(AccentColor { color: config.get_accent_color(), - } - .into(), + }) + .unwrap(), ); Ok(output.into()) } diff --git a/src/settings/config.rs b/src/settings/config.rs index 24fdfb4..148006d 100644 --- a/src/settings/config.rs +++ b/src/settings/config.rs @@ -21,7 +21,7 @@ impl SettingsConfig { _ => unreachable!(), } } - pub fn get_accent_color(&self) -> [f64; 3] { + pub fn get_accent_color(&self) -> (f64, f64, f64) { let color = csscolorparser::parse(&self.accent_color) .map(|color| color.to_rgba8()) .unwrap_or( @@ -29,11 +29,11 @@ impl SettingsConfig { .unwrap() .to_rgba8(), ); - [ + ( color[0] as f64 / 256.0, color[1] as f64 / 256.0, color[2] as f64 / 256.0, - ] + ) } }