Skip to content

Commit

Permalink
Add name method to DeviceInfo and update serialization; enhance UI la…
Browse files Browse the repository at this point in the history
…bels in settings
  • Loading branch information
samclane committed Oct 30, 2024
1 parent 933d873 commit c317e15
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/device_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,38 @@ impl DeviceInfo {
),
}
}

pub fn name(&self) -> Option<String> {
match self {
DeviceInfo::Bulb(b) => b
.name
.data
.as_ref()
.map(|n| n.to_string_lossy().to_string()),
DeviceInfo::Group(g) => Some(g.label.to_string()),
}
}
}

impl Serialize for DeviceInfo {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.id().serialize(serializer)
(self.id(), self.name()).serialize(serializer)
}
}

impl<'de> Deserialize<'de> for DeviceInfo {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let id = u64::deserialize(deserializer)?;
let (id, name) = <(u64, Option<String>)>::deserialize(deserializer)?;
Ok(DeviceInfo::Bulb(Box::new(BulbInfo {
last_seen: Instant::now(),
source: 0,
target: id,
addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 56700),
name: RefreshableData::empty(HOUR, Message::GetLabel),
name: RefreshableData::new(
CString::new(name.unwrap_or_default()).expect("Failed to create CString"),
HOUR,
Message::GetLabel,
),
model: RefreshableData::empty(HOUR, Message::GetVersion),
location: RefreshableData::empty(HOUR, Message::GetLocation),
host_firmware: RefreshableData::empty(HOUR, Message::GetHostFirmware),
Expand Down
4 changes: 4 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ impl MantleApp {
.striped(true)
.min_col_width(100.0)
.show(ui, |ui| {
ui.label(egui::RichText::new("Name").strong());
ui.label(egui::RichText::new("Device").strong());
ui.label(egui::RichText::new("Action").strong());
ui.label(egui::RichText::new("Shortcut").strong());
ui.label(egui::RichText::new("Remove").strong());
Expand All @@ -72,6 +74,8 @@ impl MantleApp {
let mut to_remove = Vec::new();
for shortcut in self.settings.custom_shortcuts.iter() {
ui.label(&shortcut.name);
ui.label(shortcut.device.as_ref().unwrap().to_string());
ui.label(shortcut.action.to_string());
ui.label(&shortcut.shortcut.display_name);
if ui
.button("Remove")
Expand Down

0 comments on commit c317e15

Please sign in to comment.