-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
144 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
[package] | ||
name = "wsnotify" | ||
version = "0.1.0" | ||
authors = ["Tomasz Cichocki <tomasz.cichocki@optiva.com>"] | ||
authors = ["Tomasz Cichocki <cichymail@gmail.com>"] | ||
|
||
[dependencies] | ||
notify = "4.0.0" | ||
app_dirs = "^1.1.1" | ||
app_dirs = "^1.1.1" | ||
systray = { git = "https://github.com/tocisz/systray-rs" } | ||
# systray = { path = "../systray-rs" } | ||
|
||
[build-dependencies] | ||
embed-resource = { git = "https://github.com/nabijaczleweli/rust-embed-resource" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extern crate embed_resource; | ||
|
||
fn main() { | ||
embed_resource::compile("resource/icons.res"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Delete ICON "if_Delete_132746.ico" | ||
Stop ICON "if_No-entry_132776.ico" | ||
OK ICON "if_OK_132710.ico" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
extern crate systray; | ||
|
||
use std::sync::mpsc::Receiver; | ||
|
||
use std::time::{Duration, SystemTime, UNIX_EPOCH}; | ||
use std::process; | ||
|
||
pub enum MeterControlMessage { | ||
MarkSafe | ||
} | ||
|
||
pub struct TenMinutesMeter { | ||
app : systray::Application, | ||
rx : Receiver<MeterControlMessage>, | ||
last_reminder : u16, | ||
} | ||
|
||
impl TenMinutesMeter { | ||
pub fn new(rx : Receiver<MeterControlMessage>) -> TenMinutesMeter { | ||
match systray::Application::new() { | ||
Ok(w) => { | ||
let mut app = w; | ||
TenMinutesMeter::init(&mut app); | ||
TenMinutesMeter { | ||
app, | ||
rx, | ||
last_reminder: 0, | ||
} | ||
}, | ||
Err(_) => panic!("Can't create window!") | ||
} | ||
} | ||
|
||
fn init(app : &mut systray::Application) -> () { | ||
app.set_icon_from_resource(&"Stop".to_string()).ok(); | ||
// app.add_menu_item(&"Print a thing".to_string(), |_| { | ||
// println!("Printing a thing!"); | ||
// }).ok(); | ||
// app.add_menu_separator().ok(); | ||
app.add_menu_item(&"Quit".to_string(), |window| { | ||
window.shutdown().ok(); | ||
window.quit(); | ||
process::exit(0); | ||
}).ok(); | ||
} | ||
|
||
pub fn main(&mut self) -> () { | ||
loop { | ||
match self.app.wait_for_message_timeout(Duration::from_secs(1)) { | ||
Ok(()) => (), | ||
Err(e) => { | ||
println!("{:?}", e); | ||
return; | ||
}, | ||
} | ||
|
||
for m in self.rx.try_iter() { | ||
match m { | ||
MeterControlMessage::MarkSafe => self.mark_safe() | ||
} | ||
} | ||
|
||
let since_epoch = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); | ||
let reminder = (since_epoch.as_secs() % 600) as u16; | ||
|
||
if self.last_reminder > reminder { | ||
self.mark_unsafe(); | ||
} | ||
|
||
self.last_reminder = reminder; | ||
} | ||
} | ||
|
||
pub fn mark_unsafe(&self) { | ||
self.app.set_icon_from_resource(&"Stop".to_string()).ok(); | ||
} | ||
|
||
pub fn mark_safe(&self) { | ||
self.app.set_icon_from_resource(&"OK".to_string()).ok(); | ||
} | ||
} | ||
|