blob: 7570dcbe0d9f86a7362da80adec595e974198d80 (
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
|
use std::fs::File;
use std::io::prelude::*;
extern crate notify_rust;
extern crate toml;
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());
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();
}
_ => {}
}
}
}
|