Fix Desktop Window Lifecycle#52
Conversation
Investigation and phased plan for fixing window close behavior, file watcher crash resilience, and Screen Time/App Nap issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Intercept CloseRequested on macOS to prevent_close + hide the app - Add RunEvent::Reopen handler to show window on dock icon click - Move cleanup (hide quick pane, unregister shortcuts) to RunEvent::Exit so it runs on actual quit (Cmd+Q, menu Quit) to prevent known crashes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The window-state plugin only auto-restores on startup, not after a hide/show cycle. Explicitly call restore_state() when reopening the main window via the dock icon. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use window.hide() instead of app_handle.hide() so the quick pane can be shown independently without triggering a system-level app unhide. Cmd+H still hides the whole app via NSApplication as normal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Document all decisions and fixes from Phase 1 including the window.hide() vs app_handle.hide() choice, RunEvent::Exit cleanup, and window state restore on reopen. Includes behavior summary table for reference when applying the same pattern to other Tauri apps. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Picks up the event deduplication fix (0.7.0) which prevents duplicate vault-changed events from being emitted. notify 9.x FSEvents crash fixes are still in RC — they'll arrive when a future debouncer version picks up stable notify 9.0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Phase 2: Make the vault file watcher resilient to crashes and missed events. - Watcher error callback now emits vault-changed to trigger a refresh, picking up any events that were lost during the error - Add periodic vault rescan (every 5 minutes) as a safety net for silent watcher death, App Nap suspension, or FSEvents coalescing - Export VAULT_CHANGED_EVENT constant for use across modules Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded a periodic background vault rescan, bumped Rust/tooling and a file-watcher dependency, reworked app run-event handling (macOS window close/reopen and cleanup), and exposed Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tdn-desktop/src-tauri/src/lib.rs (1)
236-259: Periodic rescan thread lacks graceful shutdown.The spawned thread runs an infinite loop with no mechanism to stop it on app exit. While this works in practice (the process terminates anyway), it's worth noting:
- If
vault_manager.refresh()holds a lock whileRunEvent::Exitcleanup runs, there could be contention.- Any panic in this thread is silent (no panic handler).
Consider adding an
AtomicBoolshutdown flag checked in the loop, or usingstd::thread::park/unparkfor cleaner shutdown. This is optional given the simplicity of the current approach.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tdn-desktop/src-tauri/src/lib.rs` around lines 236 - 259, The periodic rescan thread spawned by start_periodic_rescan runs an infinite loop and lacks a shutdown mechanism; modify start_periodic_rescan to accept or create a shared AtomicBool shutdown flag (stored in app state) that the loop checks each iteration (and after sleeping) and exit the loop when set, and store the JoinHandle or provide an unpark/unset method on shutdown to set the flag from the main shutdown handler (e.g., RunEvent::Exit) so VaultManager.refresh and event emission (vault::VAULT_CHANGED_EVENT) can finish without contention and the thread can be joined/cleanly terminated; ensure panics are logged by wrapping the thread body in catch_unwind and logging any panic to avoid silent failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tdn-desktop/src-tauri/Cargo.toml`:
- Line 48: The dependency notify-debouncer-full@0.7 requires Rust 1.85 while the
project targets Rust 1.82; either update the crate's Rust toolchain requirement
in Cargo.toml by bumping rust-version to 1.85 or pin the notify-debouncer-full
dependency to a 0.5.x release that supports Rust 1.82; locate the
notify-debouncer-full entry in Cargo.toml and change either the rust-version
field to "1.85" or set notify-debouncer-full = "0.5" to restore compatibility.
---
Nitpick comments:
In `@tdn-desktop/src-tauri/src/lib.rs`:
- Around line 236-259: The periodic rescan thread spawned by
start_periodic_rescan runs an infinite loop and lacks a shutdown mechanism;
modify start_periodic_rescan to accept or create a shared AtomicBool shutdown
flag (stored in app state) that the loop checks each iteration (and after
sleeping) and exit the loop when set, and store the JoinHandle or provide an
unpark/unset method on shutdown to set the flag from the main shutdown handler
(e.g., RunEvent::Exit) so VaultManager.refresh and event emission
(vault::VAULT_CHANGED_EVENT) can finish without contention and the thread can be
joined/cleanly terminated; ensure panics are logged by wrapping the thread body
in catch_unwind and logging any panic to avoid silent failures.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3b2e10e9-227b-4423-942a-79f7043dfd2f
⛔ Files ignored due to path filters (2)
docs/tasks-todo/task-x-desktop-window-lifecycle-and-crash-resilience.mdis excluded by!**/*.mdtdn-desktop/src-tauri/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
tdn-desktop/src-tauri/Cargo.tomltdn-desktop/src-tauri/src/lib.rstdn-desktop/src-tauri/src/vault/manager.rstdn-desktop/src-tauri/src/vault/mod.rs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixes #48
Summary by CodeRabbit
New Features
Bug Fixes