11use std:: { collections:: { HashMap , HashSet } , time:: Duration } ;
22
33use anyhow:: Result ;
4- use notify_fork:: { RecommendedWatcher , RecursiveMode , Watcher as _Watcher} ;
4+ use notify_fork:: { PollWatcher , RecommendedWatcher , RecursiveMode , Watcher as _Watcher} ;
55use parking_lot:: RwLock ;
66use tokio:: { fs, pin, sync:: { mpsc:: { self , UnboundedReceiver } , watch} } ;
77use tokio_stream:: { wrappers:: UnboundedReceiverStream , StreamExt } ;
@@ -27,20 +27,23 @@ impl Watcher {
2727 let ( out_tx, out_rx) = mpsc:: unbounded_channel ( ) ;
2828
2929 let out_tx_ = out_tx. clone ( ) ;
30- let watcher = RecommendedWatcher :: new (
31- move |res : Result < notify_fork:: Event , notify_fork:: Error > | {
32- let Ok ( event) = res else { return } ;
33- if event. kind . is_access ( ) {
34- return ;
35- }
36- for path in event. paths {
37- out_tx_. send ( Url :: from ( path) ) . ok ( ) ;
38- }
39- } ,
40- Default :: default ( ) ,
41- ) ;
30+ let handler = move |res : Result < notify_fork:: Event , notify_fork:: Error > | {
31+ let Ok ( event) = res else { return } ;
32+ if event. kind . is_access ( ) {
33+ return ;
34+ }
35+ for path in event. paths {
36+ out_tx_. send ( Url :: from ( path) ) . ok ( ) ;
37+ }
38+ } ;
39+
40+ let config = notify_fork:: Config :: default ( ) . with_poll_interval ( Duration :: from_millis ( 500 ) ) ;
41+ if * yazi_adapter:: WSL {
42+ tokio:: spawn ( Self :: fan_in ( in_rx, PollWatcher :: new ( handler, config) . unwrap ( ) ) ) ;
43+ } else {
44+ tokio:: spawn ( Self :: fan_in ( in_rx, RecommendedWatcher :: new ( handler, config) . unwrap ( ) ) ) ;
45+ }
4246
43- tokio:: spawn ( Self :: fan_in ( in_rx, watcher. unwrap ( ) ) ) ;
4447 tokio:: spawn ( Self :: fan_out ( out_rx) ) ;
4548 Self { in_tx, out_tx }
4649 }
@@ -76,7 +79,7 @@ impl Watcher {
7679 } ) ;
7780 }
7881
79- async fn fan_in ( mut rx : watch:: Receiver < HashSet < Url > > , mut watcher : RecommendedWatcher ) {
82+ async fn fan_in ( mut rx : watch:: Receiver < HashSet < Url > > , mut watcher : impl notify_fork :: Watcher ) {
8083 loop {
8184 let ( mut to_unwatch, mut to_watch) : ( HashSet < _ > , HashSet < _ > ) = {
8285 let ( new, old) = ( & * rx. borrow_and_update ( ) , & * WATCHED . read ( ) ) ;
0 commit comments