next: MenuItem,
prev: MenuItem,
preset: Vec<MenuItem>,
+ volume: Vec<MenuItem>,
}
struct ConnectrApp {
menu: MenuItems,
next: ptr::null_mut(),
prev: ptr::null_mut(),
preset: Vec::<MenuItem>::new(),
+ volume: Vec::<MenuItem>::new(),
}
};
let (tx,rx) = channel::<String>();
let device_list = spotify.request_device_list();
- status.add_label("Devices:");
- status.add_separator();
-
- println!("Visible Devices:");
- for dev in device_list {
- println!("{}", dev);
- let id = dev.id.clone();
- let cb: osx::NSCallback = Box::new(move |sender, tx| {
- let cmd = MenuCallbackCommand {
- action: CallbackAction::SelectDevice,
- sender: sender,
- data: id.to_owned(),
- };
- let _ = tx.send(json::encode(&cmd).unwrap());
- });
- let item = status.add_item(&dev.name, cb, dev.is_active);
- app.menu.device.push((item, dev.id.clone()));
- }
- println!("");
-
let player_state = spotify.request_player_state();
println!("Playback State:\n{}", player_state);
let play_str = format!("{: ^50}\n{: ^50}\n{: ^50}",
&player_state.item.album.name);
status.set_tooltip(&play_str);
+ status.add_label("Now Playing:");
+ status.add_separator();
+ //status.add_label(&player_state.item.name);
+ status.add_label(&format!("{:<50}", &player_state.item.name));
+ status.add_label(&format!("{:<50}", &player_state.item.artists[0].name));
+ status.add_label(&format!("{:<50}", &player_state.item.album.name));
+ let ms = player_state.item.duration_ms;
+ let min = ms / 1000 / 60;
+ let sec = (ms - (min * 60 * 1000)) / 1000;
+ status.add_label(&format!("{:<50}", format!("{}:{:02}", min, sec)));
+
status.add_label("");
status.add_label("Actions:");
status.add_separator();
}
status.add_label("");
+ status.add_label("Devices:");
+ status.add_separator();
+ println!("Visible Devices:");
+ let mut cur_volume: u32 = 0;
+ for dev in device_list {
+ println!("{}", dev);
+ let id = dev.id.clone();
+ let cb: osx::NSCallback = Box::new(move |sender, tx| {
+ let cmd = MenuCallbackCommand {
+ action: CallbackAction::SelectDevice,
+ sender: sender,
+ data: id.to_owned(),
+ };
+ let _ = tx.send(json::encode(&cmd).unwrap());
+ });
+ let item = status.add_item(&dev.name, cb, dev.is_active);
+ if dev.is_active {
+ cur_volume = match dev.volume_percent {
+ Some(v) => {
+ (v as f32 / 10.0).round() as u32 * 10
+ },
+ None => 100,
+ }
+ }
+ app.menu.device.push((item, dev.id.clone()));
+ }
+ println!("");
+
+ status.add_label("");
status.add_label("Volume:");
status.add_separator();
{
};
let _ = tx.send(json::encode(&cmd).unwrap());
});
- app.menu.play = status.add_item(&vol_str, cb, false);
+ let item = status.add_item(&vol_str, cb, i == cur_volume);
+ app.menu.volume.push(item);
i += 10;
}
}
CallbackAction::Volume => {
let vol = cmd.data.parse::<u32>().unwrap();
require(spotify.volume(vol));
+ let volume = &app.menu.volume;
+ for item in volume {
+ status.unsel_item(*item as u64);
+ }
+ status.sel_item(cmd.sender);
}
}
}
}
self.refresh_timer_channel = None;
let (access_token, expires_in) = self.refresh_oauth_tokens();
- self.access_token = Some(access_token);
+ self.access_token = Some(access_token.clone());
self.expire_utc = Some(self.expire_offset_to_utc(expires_in));
println!("Refreshed credentials.");
let _ = self.schedule_token_refresh();
+
+ let access_token = self.access_token.clone().unwrap();
+ let refresh_token = self.refresh_token.clone().unwrap();
+ let _ = settings::save_tokens(&access_token,
+ &refresh_token,
+ self.expire_utc.unwrap());
}
pub fn connect(&mut self) {
if self.access_token.is_some() && !self.is_token_expired() {