Skip to content

fix(tray): run tray in main event loop enabling support for macOS #3818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ReenigneArcher
Copy link
Member

@ReenigneArcher ReenigneArcher commented Apr 27, 2025

Description

This PR moves the system tray to run in the main thread, allowing the system tray to function correctly on macOS.

TODO:

  • Sunshine does not exit from the sigterm (ctrl+c for example)
  • Double check cmake files
  • Test tray
    • Windows
    • Linux
    • macOS
  • enable tray in Linux brew spec, need to compile libayatana-appindicator: fix(homebrew): enable system tray for linux #3819
  • Tray icon does not appear on Sunshine's first start in Windows service model

For the future:

Screenshot

Issues Fixed or Closed

May fix the following but needs confirmation:

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

@ReenigneArcher ReenigneArcher force-pushed the fix/tray/run-tray-in-main-event-loop-enabling-support-for-macOS branch from e63227c to 19e67c8 Compare April 27, 2025 17:32
Copy link

codecov bot commented Apr 27, 2025

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 11.52%. Comparing base (3de3c29) to head (42503ca).

Files with missing lines Patch % Lines
src/system_tray.cpp 0.00% 5 Missing and 1 partial ⚠️
src/rtsp.cpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3818      +/-   ##
==========================================
- Coverage   11.52%   11.52%   -0.01%     
==========================================
  Files          92       92              
  Lines       17490    17491       +1     
  Branches     8149     8149              
==========================================
  Hits         2015     2015              
- Misses      12980    12982       +2     
+ Partials     2495     2494       -1     
Flag Coverage Δ
Linux 11.15% <0.00%> (-0.01%) ⬇️
Windows 13.00% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
src/rtsp.h 0.00% <ø> (ø)
src/rtsp.cpp 1.60% <0.00%> (ø)
src/system_tray.cpp 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ReenigneArcher ReenigneArcher force-pushed the fix/tray/run-tray-in-main-event-loop-enabling-support-for-macOS branch 7 times, most recently from 2ebf3e9 to d9dee97 Compare April 28, 2025 20:40
@ReenigneArcher ReenigneArcher marked this pull request as ready for review April 28, 2025 20:44
@ReenigneArcher ReenigneArcher force-pushed the fix/tray/run-tray-in-main-event-loop-enabling-support-for-macOS branch from d9dee97 to bf8decf Compare April 30, 2025 01:38
@ReenigneArcher ReenigneArcher force-pushed the fix/tray/run-tray-in-main-event-loop-enabling-support-for-macOS branch from bf8decf to 42503ca Compare April 30, 2025 18:32
@ReenigneArcher ReenigneArcher requested a review from Copilot April 30, 2025 18:35
Copy link

@Copilot 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 PR enables the system tray to run on macOS by moving tray event processing to the main event loop and adjusting the tray initialization workflow.

  • Renames and refactors system tray functions (init_tray and process_tray_events) to separate initialization from event processing.
  • Updates the RTSP thread function by renaming it from rtpThread to start and adjusts thread handling in main.cpp.
  • Enables tray support in macOS by removing the packaging flag that disabled it.

Reviewed Changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/system_tray.h Updates function names and documentation to reflect new behavior.
src/system_tray.cpp Refactors tray loop processing and function renaming.
src/rtsp.h/rtsp.cpp Renames rtpThread to start for clearer intent.
src/main.cpp Integrates tray event processing into the main thread event loop.
packaging/sunshine.rb Removes macOS tray disabling to allow tray support on macOS.
Files not reviewed (2)
  • cmake/compile_definitions/macos.cmake: Language not supported
  • cmake/prep/options.cmake: Language not supported
Comments suppressed due to low confidence (2)

packaging/sunshine.rb:248

  • [nitpick] Since tray support is now enabled on macOS, adding a comment here to explain the removal of the disabling flag would improve clarity for future maintainers.
args << "-DSUNSHINE_ENABLE_TRAY=OFF" if OS.mac?

src/system_tray.h:57

  • The updated documentation for init_tray specifies that it only initializes the tray without starting the loop. Verify that any assumptions in other parts of the code regarding tray lifecycle management are updated accordingly.
int init_tray();

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
24 New issues
B Maintainability Rating on New Code (required ≥ A)
24 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@ReenigneArcher
Copy link
Member Author

@cgutman I'm wondering if you have some idea how to fix this (as the tray initialization logic is from you).

On Windows, when the sunshine service starts during boot the tray icon is not displayed, even though Sunshine is running fine. Logs don't indicate any errors.

[2025-04-30 16:56:09.359]: Debug: -------------------
[2025-04-30 16:56:09.360]: Info: Found HEVC encoder: hevc_amf [amdvce]
[2025-04-30 16:56:09.360]: Info: Starting system tray
[2025-04-30 16:56:09.380]: Info: Configuration UI available at [https://localhost:47990]
[2025-04-30 16:56:10.151]: Info: Registered Sunshine mDNS service

@ReenigneArcher ReenigneArcher added the help wanted Extra attention is needed label May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sunshine: Tray icon support on macOS must create tray icon in main thread on macOS
1 participant