summary history branches tags files
commit:45b66f7b5d45f4644358aaf1c6ce95cbad9af833
author:Trevor Bentley
committer:Trevor Bentley
date:Tue Apr 11 22:10:47 2017 +0200
parents:a05596a03904a8ac7e311983411dece23af5e035
Handle optional volume.  Build dynamic libs too.
diff --git a/Cargo.toml b/Cargo.toml
line changes: +16/-1
index 3259d78..5777c6e
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,10 +1,21 @@
 [package]
-
 name = "connectr"
 version = "0.0.1"
 authors = [ "Trevor Bentley <trevor@trevorbentley.com>" ]
 build = "build.rs"
 
+[lib]
+crate-type = ["rlib", "dylib"]
+
+[profile.release]
+opt-level = 3
+debug = false
+rpath = false
+lto = true
+debug-assertions = false
+codegen-units = 1
+panic = 'unwind'
+
 [dependencies]
 curl = "0.4.6"
 open = "1.2.0"
@@ -12,3 +23,7 @@ regex = "0.2"
 rustc-serialize = "0.3.23"
 url = "1.4.0"
 rust-ini = "0.9"
+
+[target."cfg(windows)".dependencies]
+[target."cfg(all(unix, not(target_os = \"macos\")))".dependencies]
+[target."cfg(macos)".dependencies]

diff --git a/src/main.rs b/src/main.rs
line changes: +0/-1
index 9ba1456..2386814
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,3 @@
-
 extern crate connectr;
 use connectr::settings;
 use connectr::SpotifyResponse;

diff --git a/src/webapi/mod.rs b/src/webapi/mod.rs
line changes: +7/-2
index dbc1e79..217c435
--- a/src/webapi/mod.rs
+++ b/src/webapi/mod.rs
@@ -26,7 +26,7 @@ pub struct ConnectDevice {
     pub is_restricted: bool,
     pub name: String,
     pub device_type: String,
-    pub volume_percent: u32
+    pub volume_percent: Option<u32>
 }
 
 impl Decodable for ConnectDevice {
@@ -37,7 +37,12 @@ impl Decodable for ConnectDevice {
             let is_restricted = try!(d.read_struct_field("is_restricted", 2, |d| { d.read_bool() }));
             let name = try!(d.read_struct_field("name", 3, |d| { d.read_str() }));
             let device_type = try!(d.read_struct_field("type", 4, |d| { d.read_str() }));
-            let volume_percent = try!(d.read_struct_field("volume_percent", 5, |d| { d.read_u32() }));
+            let volume_percent = try!(d.read_struct_field("volume_percent", 5, |d| {
+                match d.read_u32() {
+                    Ok(x) => Ok(Some(x)),
+                    // 'null' triggers a decode error.  Convert error to valid None:
+                    Err(_) => Ok(None),
+                }}));
             Ok(ConnectDevice{ id: id,
                               is_active: is_active,
                               is_restricted: is_restricted,