summary history branches tags files
commit:d0818829bcc4b45376abc5ab0ffc3b7c923c6b29
author:Trevor Bentley
committer:Trevor Bentley
date:Sun Jun 4 20:43:29 2017 +0200
parents:15581deff9ba97bd61ce8a7842353cc0ac927e35
Support null response in active device ID
diff --git a/src/main.rs b/src/main.rs
line changes: +7/-3
index b39eeed..5a9fe79
--- a/src/main.rs
+++ b/src/main.rs
@@ -168,12 +168,16 @@ fn fill_menu<T: TStatusBar>(app: &mut ConnectrApp, spotify: &mut connectr::Spoti
     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());
         });
@@ -186,7 +190,7 @@ fn fill_menu<T: TStatusBar>(app: &mut ConnectrApp, spotify: &mut connectr::Spoti
                 None => 100,
             }
         }
-        app.menu.device.push((item, dev.id.clone()));
+        app.menu.device.push((item, id));
     }
     println!("");
 

diff --git a/src/webapi/mod.rs b/src/webapi/mod.rs
line changes: +6/-2
index 8ed5296..328a923
--- a/src/webapi/mod.rs
+++ b/src/webapi/mod.rs
@@ -37,7 +37,7 @@ pub fn parse_spotify_token(json: &str) -> (String, String, u64) {
 
 #[derive(Deserialize, Debug)]
 pub struct ConnectDevice {
-    pub id: String,
+    pub id: Option<String>,
     pub is_active: bool,
     pub is_restricted: bool,
     pub name: String,
@@ -48,7 +48,11 @@ pub struct ConnectDevice {
 
 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)
     }
 }