Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Fix javascript live preview for linux (#528)
Browse files Browse the repository at this point in the history
* Fix javascript live preview and reduce live preview verbosity (watching an entire directory produces a lot of 'Cooldown' text)
  • Loading branch information
gabbifish authored Sep 6, 2019
1 parent eb0d6af commit 9dca091
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/commands/build/watch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::thread;
use std::time::Duration;

pub const COOLDOWN_PERIOD: Duration = Duration::from_millis(2000);
const JAVASCRIPT_PATH: &str = "./";

/// watch a project for changes and re-build it when necessary,
/// outputting a build event to tx.
Expand All @@ -24,14 +25,14 @@ pub fn watch_and_build(
let project_type = &project.project_type;
match project_type {
ProjectType::JavaScript => {
let package = Package::new("./")?;
let entry = package.main()?;
thread::spawn(move || {
let (watcher_tx, watcher_rx) = mpsc::channel();
let mut watcher = notify::watcher(watcher_tx, Duration::from_secs(1)).unwrap();

watcher.watch(&entry, RecursiveMode::Recursive).unwrap();
message::info(&format!("watching {:?}", &entry));
watcher
.watch(JAVASCRIPT_PATH, RecursiveMode::Recursive)
.unwrap();
message::info(&format!("watching {:?}", &JAVASCRIPT_PATH));

loop {
match wait_for_changes(&watcher_rx, COOLDOWN_PERIOD) {
Expand Down
11 changes: 4 additions & 7 deletions src/commands/build/watch/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use failure::{format_err, Error};
use crate::terminal::message;
use log::info;

///Add cooldown for all types of events to watching logic
/// Add cooldown for all types of events to watching logic
pub fn wait_for_changes(
rx: &Receiver<DebouncedEvent>,
cooldown: Duration,
Expand All @@ -18,15 +18,12 @@ pub fn wait_for_changes(
match get_changed_path_from_event(event) {
Ok(Some(path)) => {
message::working("Detected changes...");
//wait for cooldown
while let Ok(_) = rx.recv_timeout(cooldown) {
message::working("Detected change during cooldown...");
}
message::working("Cooldown over, propogating changes...");
// wait for cooldown
while let Ok(_) = rx.recv_timeout(cooldown) {}
return Ok(path);
}
Ok(None) => {
continue; //was an event type we don't care about, continue
continue; // was an event type we don't care about, continue
}
Err(error) => {
message::user_error(&format!("WatchError {:?}", error));
Expand Down

0 comments on commit 9dca091

Please sign in to comment.