Skip to content

Take SIGHUP in tray mode so closing the terminal still runs OnStop [patch] - #55

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/tray-sighup
Oct 30, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/tray-sighup

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #54

What changed

  • ShutdownSignals now registers PosixSignal.SIGHUP with the same OnTermination handler as SIGTERM. It cancels the default action only once a tray host exists, and is disposed alongside the SIGTERM registration. The summary and remarks now say "Ctrl+C, SIGTERM and SIGHUP".
  • ShutdownSignalsTests:
    • HangupOnceTheTrayExists_IsTakenAndShutsTheTrayDown sends a real SIGHUP to the test host with kill -HUP (Linux/macOS only) and asserts that it reaches the tray and posts the shutdown. A guard PosixSignalRegistration cancels the signal, so a regression fails the assertion instead of killing the test host.
    • HangupBeforeTheTrayExists_IsLeftToEndTheProcess mirrors the existing SIGTERM case.
  • scripts/check-tray-signals.sh now also sends HUP. CLAUDE.md is updated to match.

The console-mode SIGHUP gap (#30) is not touched here. The README's "Ctrl+C and SIGTERM" wording covers both modes, so it stays as is until #30 lands.

Verification

  • Full suite: 160 passed, 1 skipped. The skipped test is the existing off-Linux DesktopSession case.
  • With the ShutdownSignals.cs change reverted, HangupOnceTheTrayExists_IsTakenAndShutsTheTrayDown fails with "SIGHUP did not reach the tray", and the test host survives.
  • I couldn't run scripts/check-tray-signals.sh end to end in this container. The demo's tray icon never registered with the test watcher, for the SIGTERM case as well, with and without this change, so the cause is the environment and not this diff.

Generated by Claude Code

ShutdownSignals registered Ctrl+C and SIGTERM only, so a tray tool started
from a terminal died with exit 129 when that terminal or SSH session closed:
OnStop never ran and a toggle clicked inside the debounce window was lost.
SIGHUP now goes through the same handler as SIGTERM, cancelled only once a
tray host exists.

The new test sends a real SIGHUP to the test host, with a guard registration
that keeps the process alive, so a regression fails the assertion instead of
crashing the run.

Fixes #54

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4o1SWh5jxZ3HQXYvx
@sonarqubecloud

Copy link
Copy Markdown

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.

Tray mode still dies on SIGHUP without running OnStop or flushing preferences: the #21 fix (ShutdownSignals) takes only Ctrl+C and SIGTERM

2 participants