blob: 523772cbd08ad2b89fba38e50d8db8f9213b8023 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#[macro_use] extern crate hyper;
extern crate notify_rust;
extern crate rustc_serialize;
extern crate toml;
extern crate websocket;
use std::fs::File;
use std::io::prelude::*;
use notify_rust::Notification;
pub mod message;
use message::{Message, Push};
pub mod pushbullet;
use pushbullet::PBClient;
fn main() {
let mut cfg_file = File::open("config.toml").expect("Could not find config.toml.");
let mut s = String::new();
cfg_file.read_to_string(&mut s).expect("Could not read config.toml");
let cfg = toml::Parser::new(s.as_ref()).parse().unwrap();
let cfg_pb = cfg.get("pushbullet")
.expect("Could not find [pushbullet] section in config.")
.as_table()
.expect("Config should contain a [pushbullet] section.");
let token = cfg_pb.get("token")
.expect("[pushbullet] section should contain 'token'")
.as_str()
.expect("'token' should be a string");
let mut client = PBClient::new(token.as_ref());
println!("Starting Pushbullet client...");
println!("{:?}", client.get_user().expect("Could not get user info from server!"));
for message in client.messages() {
match message {
Message::Push(Push::Mirror {
title,
body,
application_name,
..
}) => {
let title = format!("{}: {}", application_name, title);
Notification::new()
.body(body.as_ref())
.summary(title.as_ref())
.show()
.unwrap();
}
_ => {}
}
}
}
|