 17d84e8811
			
		
	
	
		17d84e8811
		
	
	
	
	
		
			
			# Objective - Update notify dependency to 5.0.0 stable - Fix breaking changes - Closes #5861 ## Solution - RecommendedWatcher now takes a Config argument. Giving it the default Config should be the same behavior as before (check every 30 seconds)
		
			
				
	
	
		
			34 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use crossbeam_channel::Receiver;
 | |
| use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Result, Watcher};
 | |
| use std::path::Path;
 | |
| 
 | |
| /// Watches for changes to files on the local filesystem.
 | |
| ///
 | |
| /// When hot-reloading is enabled, the [`AssetServer`](crate::AssetServer) uses this to reload
 | |
| /// assets when their source files are modified.
 | |
| pub struct FilesystemWatcher {
 | |
|     pub watcher: RecommendedWatcher,
 | |
|     pub receiver: Receiver<Result<Event>>,
 | |
| }
 | |
| 
 | |
| impl Default for FilesystemWatcher {
 | |
|     fn default() -> Self {
 | |
|         let (sender, receiver) = crossbeam_channel::unbounded();
 | |
|         let watcher: RecommendedWatcher = RecommendedWatcher::new(
 | |
|             move |res| {
 | |
|                 sender.send(res).expect("Watch event send failure.");
 | |
|             },
 | |
|             Config::default(),
 | |
|         )
 | |
|         .expect("Failed to create filesystem watcher.");
 | |
|         FilesystemWatcher { watcher, receiver }
 | |
|     }
 | |
| }
 | |
| 
 | |
| impl FilesystemWatcher {
 | |
|     /// Watch for changes recursively at the provided path.
 | |
|     pub fn watch<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
 | |
|         self.watcher.watch(path.as_ref(), RecursiveMode::Recursive)
 | |
|     }
 | |
| }
 |