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

Fix javascript live preview for linux #528

Merged
merged 4 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/commands/build/watch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ pub fn watch_and_build(
let project_type = &project.project_type;
match project_type {
ProjectType::JavaScript => {
let package = Package::new("./")?;
let entry = package.main()?;
let path = "./";
let package = Package::new(path)?;
// Confirm entrypoint is provided
gabbifish marked this conversation as resolved.
Show resolved Hide resolved
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(&path, RecursiveMode::Recursive).unwrap();
message::info(&format!("watching {:?}", &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...");
gabbifish marked this conversation as resolved.
Show resolved Hide resolved
}
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