From 2c18f66ca8d35e62a1d882f46ebbd5c8f6f41ddb Mon Sep 17 00:00:00 2001 From: superlou <lousimons@gmail.com> Date: Sun, 4 Jun 2023 11:05:34 -0400 Subject: [PATCH] Removed need to canonicalize paths to fix #15 --- src/js_env/files.rs | 4 +--- src/window_handler.rs | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js_env/files.rs b/src/js_env/files.rs index 1a42c0c..9673150 100644 --- a/src/js_env/files.rs +++ b/src/js_env/files.rs @@ -1,6 +1,5 @@ use std::cell::RefCell; use std::collections::HashMap; -use std::fs; use std::path::PathBuf; use std::rc::Rc; @@ -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)?, diff --git a/src/window_handler.rs b/src/window_handler.rs index 0e21575..74584d4 100644 --- a/src/window_handler.rs +++ b/src/window_handler.rs @@ -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()); } }, _ => (),