Skip to content

Comments

fix: idiomatic async shutdown of system tray#49

Merged
ruffsl merged 6 commits intomainfrom
tray-drop-exit
Jan 11, 2026
Merged

fix: idiomatic async shutdown of system tray#49
ruffsl merged 6 commits intomainfrom
tray-drop-exit

Conversation

@ruffsl
Copy link
Owner

@ruffsl ruffsl commented Jan 11, 2026

No description provided.

Refactor tray shutdown to use a single tokio::sync::watch channel for unified async signaling between the tray and Ctrl+C handler.
Remove all polling, atomic flags, and boxed closures for shutdown.
Tray and CLI shutdown now both trigger the same event-driven cleanup path.
Retain mpsc for operation thread signaling, keeping thread code simple and idiomatic.
No sleeping or spin loops; all shutdown is event-driven and efficient.
Improves maintainability, clarity, and Rust idiomaticity for hybrid async/threaded code.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request replaces the blocking shutdown mechanism (using std::thread::park()) with an idiomatic async shutdown implementation using tokio watch channels and signal handling. The changes enable graceful shutdown of the system tray application through either Ctrl+C or the Exit menu button.

Changes:

  • Introduced tokio watch channels for shutdown signaling between the tray and the async runtime
  • Added async Ctrl+C signal handling with graceful shutdown
  • Replaced blocking std::thread::park() with tokio::select! to wait for shutdown events
  • Enhanced cleanup flow with explicit operation stopping and tray shutdown

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/tray/mod.rs Implements async shutdown with tokio::select!, watches for Exit button or Ctrl+C, and performs graceful cleanup
src/tray/app.rs Adds shutdown signaling via watch channel, changes new() to return receiver, adds shutdown() method, and implements Drop for safety
Cargo.toml Adds tokio "signal" feature for Ctrl+C handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ruffsl and others added 3 commits January 11, 2026 13:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Move shutdown and cleanup actions directly into the `tokio::select!` arms for clarity and simplicity.
- Each shutdown path (Exit button or Ctrl+C) is now handled in-place, making the code easier to read and maintain.
- No redundant cleanup; shutdown logic is linear and idiomatic.
@ruffsl ruffsl marked this pull request as ready for review January 11, 2026 20:29
@ruffsl ruffsl merged commit 1735094 into main Jan 11, 2026
1 check passed
@ruffsl ruffsl deleted the tray-drop-exit branch January 11, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant