Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions src/system_tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,32 @@
* @def TRAY_ICON
* @brief Path to the default system tray icon.
*/
#define TRAY_ICON WEB_DIR "images/logo-sunshine.svg"
#ifdef __APPLE__
#define TRAY_ICON WEB_DIR "images/macos-tray-sunshine.svg"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Enable macOS template rendering before selecting white-only icons

On a light menu bar (for example, Light appearance with Reduce Transparency enabled), this unconditionally replaces the visible colored icon with white artwork. The pinned tray backend's QtTrayMenu::lookupIcon() returns an ordinary QIcon and never calls setIsMask(true). Qt's Cocoa tray implementation sets the native image's template flag from icon.isMask(), so AppKit keeps these icons white. All four SVGs produced isMask=false and exclusively white visible pixels in a Qt 6.11.2 probe; compositing them over a light background leaves almost no contrast. The limitation noted in the PR description therefore regresses icon and streaming-state visibility for light-menu-bar users.

Please ship template handling together with this asset switch, covering both tray initialization and updates. For example, this scoped change in the file-backed branch of QtTrayMenu::lookupIcon() in third-party/tray/src/QtTrayMenu.cpp marks these assets as templates:

    if (auto result = QIcon(icon); !result.isNull()) {
#if defined(__APPLE__)
      if (icon.section('/', -1).startsWith("macos-tray-")) {
        result.setIsMask(true);
      }
#endif
      return result;
    }

A tray dependency change also needs the corresponding submodule revision update here. The flag-setting expression was compiled and verified in the focused Qt probe; the full Sunshine application was not built. Please validate light and dark menu bars after initialization and after a streaming-state change; the new path-string test cannot catch this rendering regression.

Review completed by Codex | Model: gpt-6.1-sol | Thinking: xhigh

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the detailed guidance!

  • Template image handling has been submitted to LizardByte/tray in fix(macos): enable template rendering for monochrome tray icons LizardByte/tray#218, adding result.setIsMask(true) for macos-tray-* assets.
  • The third-party/tray submodule revision in this PR has been updated to point to that commit.
  • Verified on macOS that all four states (idle, streaming, paused, pairing) render in dark/black with crisp contrast on light/white menu bars and in white on dark menu bars. Individual screenshots for both light and dark appearances have been added to the updated PR description using the official template.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rechecked at c5132946. The updated gitlink points to tray ba93bc3b (LizardByte/tray#218), where lookupIcon() sets isMask for the macOS-specific filenames before both initial tray construction and subsequent icon updates. That addresses the missing-template mechanism identified here. I also inspected the eight supplied screenshots: all four states are visible as dark icons on the light background and white icons on the darker background.

My independent checks: all 217 web tests passed, the Linux web build passed, and git diff --check passed for this revision. The added native test checks the four selected asset paths; it does not itself verify Cocoa template rendering. I don't have a macOS environment here, so the live appearance/state-transition evidence remains the contributor's testing, not an independent native validation.

Please merge the tray dependency first and, if its merged commit differs (for example after squash), update this gitlink to that upstream commit. CI, lint and CodeQL for both current heads still await workflow approval. I found no additional concrete blocker in this focused re-review.

Review completed by Codex | Model: unavailable | Thinking: unavailable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correction to my proposed implementation and follow-up: the contrast problem is real, but I was too prescriptive in suggesting a Sunshine filename-prefix rule inside the shared tray library, and then asking for that dependency to be merged. Please don't treat that particular library change as required by this review.

Tray #218 does not force template rendering for every consumer: it affects only file-backed icons on macOS whose basename starts with macos-tray-. However, that still makes Sunshine's asset naming convention shared-library policy, and the same lookup function also handles notification icons. The existing tray API doesn't expose a template flag for Sunshine to set directly.

The requirement here is to preserve icon/state visibility on both light and dark menu bars, not to mandate a dependency feature. Retaining the existing artwork avoids introducing this regression without changing tray. If adaptive monochrome artwork is retained, an explicit opt-in with unchanged defaults for other consumers is one possible design, subject to the tray maintainer's agreement, rather than a required scope expansion. My prior verification establishes the current fix's mechanism and the supplied screenshots' contrast, not that its shared-library API design should be accepted.

Review completed by Codex | Model: unavailable | Thinking: unavailable

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I opened LizardByte/tray#219 for the explicit opt-in and updated this PR to use it on the macOS menu bar. The new regression checks cover the active template flag after initialization and state changes, along with colored notification artwork.

#else
#define TRAY_ICON WEB_DIR "images/logo-sunshine.svg"
#endif
/**
* @def TRAY_ICON_PLAYING
* @brief Path to the system tray icon used while streaming.
*/
#define TRAY_ICON_PLAYING WEB_DIR "images/sunshine-playing.svg"
#ifdef __APPLE__
#define TRAY_ICON_PLAYING WEB_DIR "images/macos-tray-playing.svg"
#else
#define TRAY_ICON_PLAYING WEB_DIR "images/sunshine-playing.svg"
#endif
/**
* @def TRAY_ICON_PAUSING
* @brief Path to the system tray icon used while streaming is paused.
*/
#define TRAY_ICON_PAUSING WEB_DIR "images/sunshine-pausing.svg"
#ifdef __APPLE__
#define TRAY_ICON_PAUSING WEB_DIR "images/macos-tray-pausing.svg"
#else
#define TRAY_ICON_PAUSING WEB_DIR "images/sunshine-pausing.svg"
#endif
/**
* @def TRAY_ICON_LOCKED
* @brief Path to the system tray icon used for pairing requests.
* @brief Path to the notification icon used for pairing requests.
*/
#define TRAY_ICON_LOCKED WEB_DIR "images/sunshine-locked.svg"
/**
Expand Down Expand Up @@ -675,6 +687,25 @@ namespace system_tray {
#endif
}

/**
* @brief Get the colored artwork for a tray state notification.
* @param icon_index Index of the state in the tray icon paths.
* @return Path to the notification artwork.
*/
static const char *notification_icon_path(const std::size_t icon_index) {
#ifdef __APPLE__
constexpr std::array notification_icons {
WEB_DIR "images/logo-sunshine.svg",
TRAY_ICON_LOCKED,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How come this one icon doesn't have a macOS version?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point! appears to be used only for the system notification popup when a pairing request arrives, rather than as a menu bar icon.

Since it's used for notifications, the existing colored artwork remains highly visible and doesn't suffer from the contrast issues we see on the menu bar. Given the goal of this PR was specifically to improve the menu bar icon visibility using template rendering, I omitted this one.

Would you prefer I add a monochrome version for this notification icon as well to maintain consistency?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That makes sense. We should probably add the monochrome version with this PR just in case we decide to use it in the tray in the future.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That makes sense. I agree that keeping it consistent is better for future-proofing. I'll add the monochrome version of the locked icon in this PR and update the macOS pathing accordingly.

WEB_DIR "images/sunshine-playing.svg",
WEB_DIR "images/sunshine-pausing.svg",
};
return GetResourcePath(notification_icons[icon_index]);
#else
return tray.allIconPaths[icon_index];
#endif
}

/**
* @brief Resolve tray icons against the current executable or application bundle.
*/
Expand Down Expand Up @@ -793,7 +824,12 @@ namespace system_tray {
if (stop_token.stop_requested()) {
return 1;
}
if (tray_init(&tray) < 0) {
#ifdef __APPLE__
const int result = tray_init_with_options(&tray, TRAY_OPTION_TEMPLATE_ICON);
#else
const int result = tray_init(&tray);
#endif
if (result < 0) {
BOOST_LOG(warning) << "Failed to create system tray"sv;
return 1;
}
Expand Down Expand Up @@ -865,7 +901,7 @@ namespace system_tray {
static std::string msg = std::format("Streaming started for {}", app_name);
tray.notification_text = msg.c_str();
tray.tooltip = msg.c_str();
tray.notification_icon = tray.allIconPaths[2];
tray.notification_icon = notification_icon_path(2);
tray_update(&tray);
}

Expand All @@ -887,7 +923,7 @@ namespace system_tray {
tray.notification_title = "Stream Paused";
tray.notification_text = msg.c_str();
tray.tooltip = msg.c_str();
tray.notification_icon = tray.allIconPaths[3];
tray.notification_icon = notification_icon_path(3);
tray_update(&tray);
}

Expand All @@ -906,7 +942,7 @@ namespace system_tray {

static std::string msg = std::format("Application {} successfully stopped", app_name);
tray.icon = tray.allIconPaths[0];
tray.notification_icon = tray.allIconPaths[0];
tray.notification_icon = notification_icon_path(0);
tray.notification_title = "Application Stopped";
tray.notification_text = msg.c_str();
tray.tooltip = PROJECT_NAME;
Expand All @@ -928,7 +964,7 @@ namespace system_tray {
tray.icon = tray.allIconPaths[0];
tray.notification_title = "Incoming Pairing Request";
tray.notification_text = "Click here to complete the pairing process";
tray.notification_icon = tray.allIconPaths[1];
tray.notification_icon = notification_icon_path(1);
tray.tooltip = PROJECT_NAME;
tray.notification_cb = []() {
launch_ui("/pin");
Expand Down
20 changes: 20 additions & 0 deletions src_assets/macos/tray/macos-tray-pausing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src_assets/macos/tray/macos-tray-playing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src_assets/macos/tray/macos-tray-sunshine.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ if(SUNSHINE_ENABLE_TRAY AND (WIN32 OR APPLE OR CMAKE_SYSTEM_NAME STREQUAL "Linux
COPYONLY)
endforeach()

if(APPLE)
foreach(icon IN ITEMS sunshine playing pausing)
configure_file(
"${CMAKE_SOURCE_DIR}/src_assets/macos/tray/macos-tray-${icon}.svg"
"${SUNSHINE_TRAY_TEST_ICON_DESTINATION_DIR}/macos-tray-${icon}.svg"
COPYONLY)
endforeach()
endif()

add_library(sunshine_tray_test_helpers STATIC
${CMAKE_SOURCE_DIR}/third-party/tray/tests/notification_utils.cpp
${CMAKE_SOURCE_DIR}/third-party/tray/tests/screenshot_utils.cpp)
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/test_system_tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#endif

// standard includes
#include <array>
#include <atomic>
#include <chrono>
#include <cstdlib>
Expand Down Expand Up @@ -213,8 +214,24 @@ namespace {
EXPECT_STREQ(tray_data.tooltip, tooltip);
EXPECT_STREQ(tray_data.notification_title, notification_title);
EXPECT_STREQ(tray_data.notification_text, notification_text);
#ifdef __APPLE__
EXPECT_EQ(tray_icon_is_template(), 1);
#endif
if (notification_icon_index.has_value()) {
#ifdef __APPLE__
constexpr std::array colored_icon_names {
"logo-sunshine.svg",
"sunshine-locked.svg",
"sunshine-playing.svg",
"sunshine-pausing.svg",
};
ASSERT_NE(tray_data.notification_icon, nullptr);
const std::filesystem::path notification_icon {tray_data.notification_icon};
EXPECT_EQ(notification_icon.filename(), colored_icon_names[*notification_icon_index]);
EXPECT_TRUE(std::filesystem::is_regular_file(notification_icon));
#else
EXPECT_STREQ(tray_data.notification_icon, tray_data.allIconPaths[*notification_icon_index]);
#endif
} else {
EXPECT_EQ(tray_data.notification_icon, nullptr);
}
Expand Down Expand Up @@ -351,6 +368,18 @@ TEST_F(SystemTrayTest, LeftClickUsesNativeMacOSMenu) {
EXPECT_STREQ(tray_data.menu[0].text, "Open Sunshine");
EXPECT_FALSE(system_tray::tray_initialized_for_testing());
}

/**
* @brief Verify that the menu bar states use macOS artwork and pairing uses the colored lock.
*/
TEST_F(SystemTrayTest, UsesMonochromeMacOSMenuBarArtwork) {
const auto &tray_data = system_tray::tray_data_for_testing();
ASSERT_EQ(tray_data.iconPathCount, 5);
EXPECT_EQ(std::filesystem::path {tray_data.allIconPaths[0]}.filename(), "macos-tray-sunshine.svg");
EXPECT_EQ(std::filesystem::path {tray_data.allIconPaths[1]}.filename(), "sunshine-locked.svg");
EXPECT_EQ(std::filesystem::path {tray_data.allIconPaths[2]}.filename(), "macos-tray-playing.svg");
EXPECT_EQ(std::filesystem::path {tray_data.allIconPaths[3]}.filename(), "macos-tray-pausing.svg");
}
#endif

#ifdef _WIN32
Expand Down
11 changes: 11 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ const emitTrayIconsPlugin = {
source: fs.readFileSync(resolve(projectRoot, 'sunshine.svg')),
});

if (process.platform === 'darwin') {
for (const name of ['sunshine', 'playing', 'pausing']) {
const fileName = `macos-tray-${name}.svg`;
this.emitFile({
type: 'asset',
fileName: `images/${fileName}`,
source: fs.readFileSync(resolve(projectRoot, 'src_assets/macos/tray', fileName)),
});
}
}

const virtualHidIcon = resolve(projectRoot, 'third-party/libvirtualhid/libvirtualhid.svg');
if ((process.platform === 'win32' || process.platform === 'darwin') && fs.existsSync(virtualHidIcon)) {
this.emitFile({
Expand Down