Avoid spamming notifications, fix multi build
This commit is contained in:
parent
52ef41b9aa
commit
1ce0327bdb
|
@ -47,7 +47,7 @@ fn fetch_url(uri: hyper::Uri) -> impl Future<Item=(), Error=()> {
|
||||||
// If there was an error, build in client
|
// If there was an error, build in client
|
||||||
.map_err(move |_| {
|
.map_err(move |_| {
|
||||||
warn!("{}", "server not listening, building in client...");
|
warn!("{}", "server not listening, building in client...");
|
||||||
let builder = GeneralBuilder::new();
|
let mut builder = GeneralBuilder::new();
|
||||||
let uri = percent_decode(uri.path().as_bytes()).decode_utf8().unwrap();
|
let uri = percent_decode(uri.path().as_bytes()).decode_utf8().unwrap();
|
||||||
let (path, args) = builder_arguments_from_string(&*uri);
|
let (path, args) = builder_arguments_from_string(&*uri);
|
||||||
let _ = builder.build(&path, &args);
|
let _ = builder.build(&path, &args);
|
||||||
|
|
48
src/lib.rs
48
src/lib.rs
|
@ -11,9 +11,9 @@ use std::time::Duration;
|
||||||
|
|
||||||
use colored::*;
|
use colored::*;
|
||||||
|
|
||||||
use notify::{Watcher, RecursiveMode, watcher};
|
use notify::{Watcher, RecursiveMode, watcher, DebouncedEvent};
|
||||||
|
|
||||||
use notify_rust::Notification;
|
use notify_rust::{Notification, NotificationHandle};
|
||||||
|
|
||||||
/// The different types of error that can occur.
|
/// The different types of error that can occur.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -116,6 +116,7 @@ pub fn watch<P: AsRef<Path>>(p: P) -> Result<(), Error> {
|
||||||
path.push(p.as_ref());
|
path.push(p.as_ref());
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
let mut builder = GeneralBuilder::new();
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
let mut watcher = watcher(tx, Duration::from_millis(200)).unwrap();
|
let mut watcher = watcher(tx, Duration::from_millis(200)).unwrap();
|
||||||
watcher.watch(&path, RecursiveMode::Recursive).unwrap();
|
watcher.watch(&path, RecursiveMode::Recursive).unwrap();
|
||||||
|
@ -124,8 +125,11 @@ pub fn watch<P: AsRef<Path>>(p: P) -> Result<(), Error> {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match rx.recv() {
|
match rx.recv() {
|
||||||
Ok(_) => {
|
Ok(DebouncedEvent::NoticeWrite(_)) |
|
||||||
let builder = GeneralBuilder::new();
|
Ok(DebouncedEvent::Write(_)) |
|
||||||
|
Ok(DebouncedEvent::Create(_)) |
|
||||||
|
Ok(DebouncedEvent::Rename(_, _)) |
|
||||||
|
Ok(DebouncedEvent::Chmod(_)) => {
|
||||||
|
|
||||||
let start_string = format!("---- STARTING BUILD ---- from {}", path.display());
|
let start_string = format!("---- STARTING BUILD ---- from {}", path.display());
|
||||||
println!("{}", start_string.bold().green());
|
println!("{}", start_string.bold().green());
|
||||||
|
@ -141,6 +145,7 @@ pub fn watch<P: AsRef<Path>>(p: P) -> Result<(), Error> {
|
||||||
println!();
|
println!();
|
||||||
},
|
},
|
||||||
Err(e) => error!("watch error: {:?}", e),
|
Err(e) => error!("watch error: {:?}", e),
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -158,6 +163,9 @@ pub struct GeneralBuilder {
|
||||||
|
|
||||||
/// The builders contained.
|
/// The builders contained.
|
||||||
builders: Vec<Box<Builder>>,
|
builders: Vec<Box<Builder>>,
|
||||||
|
|
||||||
|
/// The id of the notification to update a notification if possible.
|
||||||
|
notification_handle: Option<NotificationHandle>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GeneralBuilder {
|
impl GeneralBuilder {
|
||||||
|
@ -203,11 +211,12 @@ impl GeneralBuilder {
|
||||||
Box::new(CMakeBuilder::new()),
|
Box::new(CMakeBuilder::new()),
|
||||||
Box::new(CargoBuilder::new()),
|
Box::new(CargoBuilder::new()),
|
||||||
],
|
],
|
||||||
|
notification_handle: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Triggers a build.
|
/// Triggers a build.
|
||||||
pub fn build(&self, path: &PathBuf, args: &Vec<String>) -> Result<(), Error> {
|
pub fn build(&mut self, path: &PathBuf, args: &Vec<String>) -> Result<(), Error> {
|
||||||
let result = build(path, args, &self.builders);
|
let result = build(path, args, &self.builders);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
@ -219,13 +228,32 @@ impl GeneralBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a notification of a successful build.
|
/// Sends a notification of a successful build.
|
||||||
pub fn notify_success(&self) {
|
pub fn notify_success(&mut self) {
|
||||||
|
|
||||||
|
match self.notification_handle.as_mut() {
|
||||||
|
Some(handle) => {
|
||||||
|
handle
|
||||||
|
.appname("Mars")
|
||||||
|
.summary("Success")
|
||||||
|
.body("Mars finished successfully")
|
||||||
|
.icon(self.success.to_str().unwrap());
|
||||||
|
|
||||||
|
handle.update();
|
||||||
|
},
|
||||||
|
|
||||||
|
None => {
|
||||||
|
let handle = Notification::new()
|
||||||
|
.appname("Mars")
|
||||||
|
.summary("Success")
|
||||||
|
.body("Mars finished successfully")
|
||||||
|
.icon(self.success.to_str().unwrap())
|
||||||
|
.show();
|
||||||
|
|
||||||
|
self.notification_handle = handle.ok();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
let _ = Notification::new()
|
let _ = Notification::new()
|
||||||
.appname("Mars")
|
|
||||||
.summary("Success")
|
|
||||||
.body("Mars finished successfully")
|
|
||||||
.icon(self.success.to_str().unwrap())
|
|
||||||
.show();
|
.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ fn main() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut builder = GeneralBuilder::new();
|
||||||
|
|
||||||
for _ in rx {
|
for _ in rx {
|
||||||
|
|
||||||
let uri = {
|
let uri = {
|
||||||
|
@ -62,7 +64,6 @@ fn main() {
|
||||||
|
|
||||||
if let Some(uri) = uri {
|
if let Some(uri) = uri {
|
||||||
|
|
||||||
let builder = GeneralBuilder::new();
|
|
||||||
let uri = percent_decode(uri.path().as_bytes()).decode_utf8().unwrap();
|
let uri = percent_decode(uri.path().as_bytes()).decode_utf8().unwrap();
|
||||||
let (path, args) = builder_arguments_from_string(&*uri);
|
let (path, args) = builder_arguments_from_string(&*uri);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue