extern crate connectr;
use connectr::SpotifyResponse;
+use connectr::TStatusBar;
+use connectr::MenuItem;
+use connectr::NSCallback;
#[macro_use]
extern crate log;
#[cfg(target_os = "macos")]
use connectr::osx;
-#[cfg(target_os = "macos")]
-use connectr::osx::TStatusBar;
-#[cfg(target_os = "macos")]
-use connectr::osx::MenuItem;
struct MenuItems {
device: Vec<(MenuItem, String)>,
status.add_separator();
{
let play_str = play_action_label(player_state.is_playing);
- let cb: osx::NSCallback = Box::new(move |sender, tx| {
+ let cb: NSCallback = Box::new(move |sender, tx| {
let is_playing = &player_state.is_playing;
let cmd = MenuCallbackCommand {
action: CallbackAction::PlayPause,
});
app.menu.play = status.add_item(&play_str, cb, false);
- let cb: osx::NSCallback = Box::new(move |sender, tx| {
+ let cb: NSCallback = Box::new(move |sender, tx| {
let cmd = MenuCallbackCommand {
action: CallbackAction::SkipNext,
sender: sender,
});
app.menu.next = status.add_item("Next", cb, false);
- let cb: osx::NSCallback = Box::new(move |sender, tx| {
+ let cb: NSCallback = Box::new(move |sender, tx| {
let cmd = MenuCallbackCommand {
action: CallbackAction::SkipPrev,
sender: sender,
for preset in presets {
let ref name = preset.0;
let uri = preset.1.clone();
- let cb: osx::NSCallback = Box::new(move |sender, tx| {
+ let cb: NSCallback = Box::new(move |sender, tx| {
let cmd = MenuCallbackCommand {
action: CallbackAction::Preset,
sender: sender,
for dev in device_list {
println!("{}", dev);
let id = dev.id.clone();
- let cb: osx::NSCallback = Box::new(move |sender, tx| {
+ let cb: NSCallback = Box::new(move |sender, tx| {
let cmd = MenuCallbackCommand {
action: CallbackAction::SelectDevice,
sender: sender,
let mut i = 0;
while i <= 100 {
let vol_str = format!("{}%", i);
- let cb: osx::NSCallback = Box::new(move |sender, tx| {
+ let cb: NSCallback = Box::new(move |sender, tx| {
let cmd = MenuCallbackCommand {
action: CallbackAction::Volume,
sender: sender,
spotify.connect();
info!("Created Spotify connection.");
spotify.set_target_device(None);
+ #[cfg(target_os = "macos")]
let mut status = osx::OSXStatusBar::new(tx);
info!("Created status bar.");
+ #[cfg(not(target_os = "macos"))]
+ let mut status = connectr::DummyStatusBar::new(tx);
loop {
let now = time::now_utc().to_timespec().sec as i64;
extern crate cocoa;
extern crate libc;
-pub use self::rustnsobject::NSCallback;
+pub use ::TStatusBar;
+pub use ::NSCallback;
-use objc::runtime::{Class, Object};
+use objc::runtime::Class;
use self::cocoa::base::{nil, YES};
use self::cocoa::appkit::NSStatusBar;
extern crate objc_id;
use self::objc_id::Id;
-pub type MenuItem = *mut Object;
+pub type Object = objc::runtime::Object;
pub struct OSXStatusBar {
object: NSObj,
status_bar_item: *mut objc::runtime::Object,
menu_bar: *mut objc::runtime::Object,
}
-pub trait TStatusBar {
- type S: TStatusBar;
- fn new(tx: Sender<String>) -> Self::S;
- fn clear_items(&mut self);
- fn add_separator(&mut self);
- fn add_label(&mut self, label: &str);
- fn add_item(&mut self, item: &str, callback: NSCallback, selected: bool) -> *mut Object;
- fn add_quit(&mut self, label: &str);
- fn update_item(&mut self, item: *mut Object, label: &str);
- fn sel_item(&mut self, sender: u64);
- fn unsel_item(&mut self, sender: u64);
- fn set_tooltip(&self, text: &str);
- fn run(&mut self, block: bool);
-}
impl TStatusBar for OSXStatusBar {
type S = OSXStatusBar;
extern crate objc_foundation;
extern crate objc_id;
+pub use ::NSCallback;
+
use std::sync::{Once, ONCE_INIT};
use objc::Message;
}
pub type NSObjCallback<T> = Box<Fn(&mut T, u64)>;
-pub type NSCallback = Box<Fn(u64, &Sender<String>)>;
impl NSObjCallbackTrait for NSObj {
fn set_value(&mut self, key: u64, val: NSCallback) {