main.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. extern crate rustc_serialize;
  2. mod sensors;
  3. mod comm;
  4. mod config;
  5. mod events;
  6. mod store;
  7. mod music;
  8. use comm::{Channel, Message};
  9. use config::Config;
  10. use std::env;
  11. use std::sync::Arc;
  12. use std::sync::mpsc;
  13. use std::thread;
  14. fn main() {
  15. let config_path = env::args().nth(1).unwrap_or("./panel.toml".to_string());
  16. let cfg = config::load(&config_path);
  17. let cfg = Arc::new(cfg);
  18. let (tx, rx) = mpsc::channel::<Message>();
  19. make_thread(&tx, &cfg, events::handle);
  20. make_thread(&tx, &cfg, sensors::sensors);
  21. make_thread(&tx, &cfg, music::music);
  22. let mut data = store::Store::new();
  23. // i3bar header
  24. println!("{{\"version\": 1,\"click_events\":true}}");
  25. println!("[");
  26. loop {
  27. let msg = rx.recv().unwrap();
  28. data.save(msg);
  29. println!("[{},{}],",
  30. data.get("mpd"),
  31. data.get("sensors")
  32. );
  33. }
  34. }
  35. fn make_thread(tx: &Channel, cfg: &Arc<Config>, func: fn(&Channel, &Config) -> ()) {
  36. let thread_tx = tx.clone();
  37. let thread_cfg = cfg.clone();
  38. thread::spawn(move || {
  39. func(&thread_tx, &thread_cfg);
  40. });
  41. }