Skip to content

Commit

Permalink
fix: accent color type error
Browse files Browse the repository at this point in the history
close: #37
  • Loading branch information
Decodetalkers committed Oct 17, 2024
1 parent 0a74579 commit ebefecd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
8 changes: 3 additions & 5 deletions libs/accessdialog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ async fn async_watch<P: AsRef<Path>>(path: P) -> notify::Result<()> {
AccentColor {
color: config.get_accent_color(),
}
.into(),
.try_into()
.unwrap(),
)
.await;
}
Expand Down
29 changes: 9 additions & 20 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,21 +21,10 @@ pub use self::config::SettingsConfig;
pub static SETTING_CONFIG: Lazy<Arc<Mutex<SettingsConfig>>> =
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<AccentColor> 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)]
Expand All @@ -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()))
}
Expand All @@ -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())
}
Expand Down
6 changes: 3 additions & 3 deletions src/settings/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ 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(
csscolorparser::parse(DEFAULT_ACCENT_COLLOR)
.unwrap()
.to_rgba8(),
);
[
(
color[0] as f64 / 256.0,
color[1] as f64 / 256.0,
color[2] as f64 / 256.0,
]
)
}
}

Expand Down

0 comments on commit ebefecd

Please sign in to comment.