diff --git a/src/app.rs b/src/app.rs index 4db4989..c1cd404 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1452,7 +1452,10 @@ impl App { self } - pub fn handle_batch_external_msgs(mut self, msgs: Vec) -> Result { + pub fn handle_batch_external_msgs( + mut self, + msgs: Vec, + ) -> Result { for task in msgs .into_iter() .map(|msg| Task::new(MsgIn::External(msg), None)) diff --git a/src/lua.rs b/src/lua.rs index e9158f1..02ce325 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -9,7 +9,7 @@ use serde::Deserialize; use std::fs; const DEFAULT_LUA_SCRIPT: &str = include_str!("init.lua"); -const INTERNAL_LUA_SCRIPT: &str = include_str!("__cache__.lua"); +const CACHE_LUA_SCRIPT: &str = include_str!("__cache__.lua"); const UPGRADE_GUIDE_LINK: &str = "https://xplr.dev/en/upgrade-guide.html"; fn parse_version(version: &str) -> Result<(u16, u16, u16, Option)> { @@ -69,7 +69,7 @@ pub fn init(lua: &Lua) -> Result { globals.set("xplr", lua_xplr)?; lua.load(DEFAULT_LUA_SCRIPT).set_name("init")?.exec()?; - lua.load(INTERNAL_LUA_SCRIPT).set_name("internal")?.exec()?; + lua.load(CACHE_LUA_SCRIPT).set_name("internal")?.exec()?; let lua_xplr: mlua::Table = globals.get("xplr")?; let config: Config = lua.from_value(lua_xplr.get("config")?)?; @@ -112,10 +112,7 @@ pub fn call<'lua, R: Deserialize<'lua>>( } /// Used to cache the directory nodes. -pub fn cache_directory_nodes<'lua>( - lua: &'lua Lua, - nodes: &[Node], -) -> Result<()> { +pub fn cache_directory_nodes(lua: &Lua, nodes: &[Node]) -> Result<()> { let func = "xplr.__CACHE__.set_directory_nodes"; let func: mlua::Function = lua.load(func).eval()?; func.call(lua.to_value(nodes)?)?; diff --git a/src/pwd_watcher.rs b/src/pwd_watcher.rs index 0fb2727..3900de8 100644 --- a/src/pwd_watcher.rs +++ b/src/pwd_watcher.rs @@ -17,14 +17,18 @@ pub fn keep_watching( thread::spawn(move || loop { if let Ok(new_pwd) = rx_pwd_watcher.try_recv() { pwd = PathBuf::from(new_pwd); + last_modified = pwd + .metadata() + .and_then(|m| m.modified()) + .unwrap_or(last_modified) } else if let Err(e) = pwd .metadata() .map_err(Error::new) .and_then(|m| m.modified().map_err(Error::new)) .and_then(|modified| { if modified != last_modified { - let msg = MsgIn::External(ExternalMsg::ExplorePwdAsync); last_modified = modified; + let msg = MsgIn::External(ExternalMsg::ExplorePwdAsync); tx_msg_in.send(Task::new(msg, None)).map_err(Error::new) } else { thread::sleep(Duration::from_secs(1)); @@ -48,17 +52,18 @@ mod tests { #[test] fn test_pwd_watcher() { let (tx_msg_in, rx_msg_in) = mpsc::channel(); - let (tx_pwd_watcher, rx_pwd_watcher) = mpsc::channel(); + let (_, rx_pwd_watcher) = mpsc::channel(); - let result = keep_watching("/", tx_msg_in, rx_pwd_watcher); + let result = keep_watching("/tmp", tx_msg_in, rx_pwd_watcher); assert!(result.is_ok()); - tx_pwd_watcher.send("/bin".to_string()).unwrap(); - let task = rx_msg_in.recv().unwrap(); + let file = "/tmp/__xplr_pwd_watcher_test__"; + std::fs::write(file, "test").unwrap(); + std::fs::remove_file(file).unwrap(); + let task = rx_msg_in.recv().unwrap(); let msg = MsgIn::External(ExternalMsg::ExplorePwdAsync); - assert_eq!(task, Task::new(msg, None)); } }