diff --git a/src/system_tray.cpp b/src/system_tray.cpp
index 8fcdf67caa3..d41b4ecd2e2 100644
--- a/src/system_tray.cpp
+++ b/src/system_tray.cpp
@@ -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"
+ #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"
/**
@@ -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,
+ 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.
*/
@@ -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;
}
@@ -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);
}
@@ -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);
}
@@ -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;
@@ -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");
diff --git a/src_assets/macos/tray/macos-tray-pausing.svg b/src_assets/macos/tray/macos-tray-pausing.svg
new file mode 100644
index 00000000000..d1ebe2fb236
--- /dev/null
+++ b/src_assets/macos/tray/macos-tray-pausing.svg
@@ -0,0 +1,20 @@
+
+
diff --git a/src_assets/macos/tray/macos-tray-playing.svg b/src_assets/macos/tray/macos-tray-playing.svg
new file mode 100644
index 00000000000..a5bbe907cfb
--- /dev/null
+++ b/src_assets/macos/tray/macos-tray-playing.svg
@@ -0,0 +1,18 @@
+
+
diff --git a/src_assets/macos/tray/macos-tray-sunshine.svg b/src_assets/macos/tray/macos-tray-sunshine.svg
new file mode 100644
index 00000000000..4c2940df6b4
--- /dev/null
+++ b/src_assets/macos/tray/macos-tray-sunshine.svg
@@ -0,0 +1,8 @@
+
+
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index fe24bb54e95..94038408738 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -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)
diff --git a/tests/unit/test_system_tray.cpp b/tests/unit/test_system_tray.cpp
index c3043fd05a3..cfe65c80df8 100644
--- a/tests/unit/test_system_tray.cpp
+++ b/tests/unit/test_system_tray.cpp
@@ -13,6 +13,7 @@
#endif
// standard includes
+#include
#include
#include
#include
@@ -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);
}
@@ -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
diff --git a/vite.config.js b/vite.config.js
index eb8ff036f27..7bbeb71d421 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -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({