Support null response in active device ID
let mut cur_volume: u32 = 0;
for dev in *device_list {
println!("{}", dev);
- let id = dev.id.clone();
+ let id = match dev.id {
+ Some(ref id) => id.clone(),
+ None => "".to_string(),
+ };
+ let cb_id = id.clone();
let cb: NSCallback = Box::new(move |sender, tx| {
let cmd = MenuCallbackCommand {
action: CallbackAction::SelectDevice,
sender: sender,
- data: id.to_owned(),
+ data: cb_id.to_owned(),
};
let _ = tx.send(serde_json::to_string(&cmd).unwrap());
});
None => 100,
}
}
- app.menu.device.push((item, dev.id.clone()));
+ app.menu.device.push((item, id));
}
println!("");
#[derive(Deserialize, Debug)]
pub struct ConnectDevice {
- pub id: String,
+ pub id: Option<String>,
pub is_active: bool,
pub is_restricted: bool,
pub name: String,
impl fmt::Display for ConnectDevice {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{:<40} <{}>", self.name, self.id)
+ let id = match self.id {
+ Some(ref id) => id,
+ None => "",
+ };
+ write!(f, "{:<40} <{}>", self.name, id)
}
}