Skip to content

fix(macOS): System tray icon disappears when restarting Sunshine - #5504

Merged
ReenigneArcher merged 5 commits into
LizardByte:masterfrom
eduardomozart:fix/mac-restart
Aug 20, 2026
Merged

fix(macOS): System tray icon disappears when restarting Sunshine#5504
ReenigneArcher merged 5 commits into
LizardByte:masterfrom
eduardomozart:fix/mac-restart

Conversation

@eduardomozart

@eduardomozart eduardomozart commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes an issue on macOS where restarting Sunshine (e.g. from the system tray or Web UI) causes the system tray icon to completely disappear for the newly restarted instance.

macOS WindowServer strictly associates GUI state (including the tray icon and activation policies) with the Process ID (PID). Sunshine previously used execv() to restart itself. execv() replaces the process image but retains the exact same PID. When the new instance starts, WindowServer retains the stale state of the old process and silently refuses to initialize the new system tray icon.

  1. execv with an artificial delay: We initially tried passing an environment variable (SUNSHINE_IS_RESTARTING) and delaying the startup of the new instance by 500ms to give the OS time to clean up. Result: Failed. Since the PID remains identical, a delay does not clear WindowServer's cache.
  2. NSTask / fork (Fire and Forget): We tried replacing execv with an NSTask launch (which forks a new process and yields a fresh PID), then letting the original parent process exit immediately. Result: This successfully fixed the system tray icon! However, it severely broke the terminal experience. Because the parent process exited immediately, the shell (zsh/bash) reclaimed the terminal foreground. The new Sunshine instance continued running in the background, dumping logs over the user's shell prompt, and completely breaking Ctrl+C termination.

To satisfy both WindowServer (which demands a new PID) and the user's shell (which demands the original process stays alive to maintain terminal control), we implemented a Supervisor Pattern in src/platform/macos/misc.mm:

  1. The parent process forks a child and calls execv on the new Sunshine instance. The child gets a completely fresh PID, allowing the system tray icon to initialize perfectly.
  2. The child places itself in a new process group (setpgid(0,0)).
  3. The parent process does not exit. Instead, it acts as a transparent supervisor, blocking on waitpid(). Because the parent stays alive, the shell never reclaims the terminal, preventing logs from interleaving with the shell prompt.
  4. The parent catches termination signals (SIGINT, SIGTERM, SIGHUP) and forwards them directly to the child. This means Ctrl+C in the terminal gracefully kills the new instance.

Screenshot

Gravacao.de.Tela.2026-08-14.as.18.15.43.mov

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

See our AI usage policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@eduardomozart eduardomozart changed the title fix(macos): macOS restart by keeping parent process as a supervisor fix(macos): System tray icon disappears when restarting Sunshine Aug 14, 2026
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.00000% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.43%. Comparing base (0a1c365) to head (da88bce).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/macos/misc.mm 16.00% 21 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5504      +/-   ##
==========================================
+ Coverage   32.31%   32.43%   +0.12%     
==========================================
  Files         102      104       +2     
  Lines       24400    24993     +593     
  Branches    10820    11078     +258     
==========================================
+ Hits         7885     8107     +222     
+ Misses      15076    14766     -310     
- Partials     1439     2120     +681     
Flag Coverage Δ
Archlinux 0.00% <ø> (ø)
FreeBSD-amd64 18.28% <ø> (-0.01%) ⬇️
Homebrew-macos-14 28.07% <0.00%> (-0.06%) ⬇️
Homebrew-macos-15 28.78% <0.00%> (-0.06%) ⬇️
Homebrew-macos-26 28.90% <0.00%> (-0.08%) ⬇️
Homebrew-ubuntu-24.04 18.95% <ø> (ø)
Linux-AppImage 18.37% <ø> (ø)
Windows-AMD64 23.76% <ø> (ø)
Windows-ARM64 20.49% <ø> (?)
macOS-arm64 25.33% <0.00%> (-0.05%) ⬇️
macOS-x86_64 25.98% <0.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/macos/misc.mm 23.11% <16.00%> (-0.86%) ⬇️

... and 63 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a1c365...da88bce. Read the comment docs.

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
Last Updated 2026-08-20 15:06:21 UTC
Source Run CI Run #5047
Commit da88bcebcbfebf6e5cf5ecc454b89142c0b1343b

Screenshot Comparison

PR #5504 screenshots vs screenshots baseline.

Matrix: AppImage

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-AMD64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-ARM64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-arm64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-x86_64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher ReenigneArcher changed the title fix(macos): System tray icon disappears when restarting Sunshine fix(macOS): System tray icon disappears when restarting Sunshine Aug 20, 2026
@ReenigneArcher
ReenigneArcher merged commit f0a46d7 into LizardByte:master Aug 20, 2026
69 of 70 checks passed
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.

macOS: System tray icon disappears when restarting Sunshine

2 participants