Skip to content

Commit

Permalink
Removed need to canonicalize paths to fix #15
Browse files Browse the repository at this point in the history
  • Loading branch information
superlou committed Jun 4, 2023
1 parent 2cfaef1 commit 2c18f66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/js_env/files.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;
use std::rc::Rc;

Expand Down Expand Up @@ -39,10 +38,9 @@ fn watch_json(
let path = args[0].try_js_into::<String>(context)?;
full_path.push(path);

let Ok(canonical_path) = fs::canonicalize(&full_path) else {return Ok(JsValue::Undefined)};
let callback = args[1].try_js_into::<JsFunction>(context)?;
// todo Keeping the callback outside the JsEnv seems to cause core dump on quit
watches.borrow_mut().insert(canonical_path, callback.clone());
watches.borrow_mut().insert(full_path.clone(), callback.clone());

let run_first = match args.get(2) {
Some(arg) => arg.try_js_into::<bool>(context)?,
Expand Down
6 changes: 4 additions & 2 deletions src/window_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ impl SignWindowHandler {
pub fn new<P: AsRef<Path>>(app_root: P) -> Self {
let (tx, rx) = mpsc::channel();
let tx_for_watcher = tx.clone();

let mut watcher = notify::recommended_watcher(move |res: Result<notify::Event, notify::Error>| {
match res {
Ok(event) => match event.kind {
notify::EventKind::Modify(_) => {
for path_buf in event.paths {
let _ = tx_for_watcher.send(path_buf);
let cwd = std::env::current_dir().unwrap();
let path = path_buf.strip_prefix(&cwd).unwrap();
let _ = tx_for_watcher.send(path.to_owned());
}
},
_ => (),
Expand Down

0 comments on commit 2c18f66

Please sign in to comment.