From f3133dd8dce3682fb8afdc85cd27f9c0cb6fe727 Mon Sep 17 00:00:00 2001 From: ruohki Date: Sun, 1 Mar 2026 11:27:15 +0100 Subject: [PATCH] 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 --- src/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.rs b/src/main.rs index 7dba136..189fb96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 ──────────────────────────────────────────────────────── // Install safety envelope BEFORE terminal init so panics during init are caught. @@ -115,6 +133,7 @@ fn main() { raw_content, initial_link_records, "index.md".to_string(), + file_watcher, ); let shutdown_reason = app_state.run_event_loop(&mut term, &signal_flags);