feat(04-03): initialize FileWatcher in main.rs and wire App constructor
- Create FileWatcher watching index.md's parent directory before App::new() - Pass file_watcher Option to App::new() as seventh argument - Watcher failure is non-fatal: prints warning and passes None to App
This commit is contained in:
+19
@@ -77,6 +77,24 @@ fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 3c. Initialize filesystem watcher for live content refresh.
|
||||||
|
// Watch the parent directory of index.md (or vault root if index.md is at root).
|
||||||
|
// Watcher must be created before App::new() so it can be passed in.
|
||||||
|
let file_watcher = {
|
||||||
|
let watch_dir = app_config.vault_path.join("index.md")
|
||||||
|
.parent()
|
||||||
|
.map(|p| p.to_path_buf())
|
||||||
|
.unwrap_or_else(|| app_config.vault_path.clone());
|
||||||
|
match app::FileWatcher::new(&watch_dir) {
|
||||||
|
Ok(w) => Some(w),
|
||||||
|
Err(e) => {
|
||||||
|
// Non-fatal: live reload won't work but app is still usable
|
||||||
|
eprintln!("Warning: filesystem watcher unavailable: {}", e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// ── TERMINAL PHASE ────────────────────────────────────────────────────────
|
// ── TERMINAL PHASE ────────────────────────────────────────────────────────
|
||||||
// Install safety envelope BEFORE terminal init so panics during init are caught.
|
// Install safety envelope BEFORE terminal init so panics during init are caught.
|
||||||
|
|
||||||
@@ -115,6 +133,7 @@ fn main() {
|
|||||||
raw_content,
|
raw_content,
|
||||||
initial_link_records,
|
initial_link_records,
|
||||||
"index.md".to_string(),
|
"index.md".to_string(),
|
||||||
|
file_watcher,
|
||||||
);
|
);
|
||||||
let shutdown_reason = app_state.run_event_loop(&mut term, &signal_flags);
|
let shutdown_reason = app_state.run_event_loop(&mut term, &signal_flags);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user