|
|
@ -5,7 +5,6 @@ use std::path::PathBuf;
|
|
|
|
use std::sync::mpsc::{Receiver, Sender};
|
|
|
|
use std::sync::mpsc::{Receiver, Sender};
|
|
|
|
use std::thread;
|
|
|
|
use std::thread;
|
|
|
|
use std::time::Duration;
|
|
|
|
use std::time::Duration;
|
|
|
|
use std::time::SystemTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn keep_watching(
|
|
|
|
pub fn keep_watching(
|
|
|
|
pwd: &str,
|
|
|
|
pwd: &str,
|
|
|
@ -13,20 +12,15 @@ pub fn keep_watching(
|
|
|
|
rx_pwd_watcher: Receiver<String>,
|
|
|
|
rx_pwd_watcher: Receiver<String>,
|
|
|
|
) -> Result<()> {
|
|
|
|
) -> Result<()> {
|
|
|
|
let mut pwd = PathBuf::from(pwd);
|
|
|
|
let mut pwd = PathBuf::from(pwd);
|
|
|
|
let mut last_modified = pwd
|
|
|
|
let mut last_modified = pwd.metadata().and_then(|m| m.modified())?;
|
|
|
|
.metadata()
|
|
|
|
|
|
|
|
.and_then(|m| m.modified())
|
|
|
|
|
|
|
|
.unwrap_or_else(|_| SystemTime::now());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thread::spawn(move || loop {
|
|
|
|
thread::spawn(move || loop {
|
|
|
|
if let Ok(new_pwd) = rx_pwd_watcher.try_recv() {
|
|
|
|
if let Ok(new_pwd) = rx_pwd_watcher.try_recv() {
|
|
|
|
pwd = PathBuf::from(new_pwd);
|
|
|
|
pwd = PathBuf::from(new_pwd);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let modified = pwd
|
|
|
|
pwd.metadata()
|
|
|
|
.metadata()
|
|
|
|
|
|
|
|
.and_then(|m| m.modified())
|
|
|
|
.and_then(|m| m.modified())
|
|
|
|
.unwrap_or_else(|_| SystemTime::now());
|
|
|
|
.map(|modified| {
|
|
|
|
|
|
|
|
|
|
|
|
if modified != last_modified {
|
|
|
|
if modified != last_modified {
|
|
|
|
let msg = MsgIn::External(ExternalMsg::ExplorePwdAsync);
|
|
|
|
let msg = MsgIn::External(ExternalMsg::ExplorePwdAsync);
|
|
|
|
tx_msg_in.send(Task::new(msg, None)).unwrap_or_default();
|
|
|
|
tx_msg_in.send(Task::new(msg, None)).unwrap_or_default();
|
|
|
@ -34,6 +28,12 @@ pub fn keep_watching(
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
thread::sleep(Duration::from_millis(1000));
|
|
|
|
thread::sleep(Duration::from_millis(1000));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.unwrap_or_else(|e| {
|
|
|
|
|
|
|
|
let msg = MsgIn::External(ExternalMsg::LogError(e.to_string()));
|
|
|
|
|
|
|
|
tx_msg_in.send(Task::new(msg, None)).unwrap_or_default();
|
|
|
|
|
|
|
|
thread::sleep(Duration::from_millis(1000));
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|