From f5b923c4067c4bda6b952cacb61b93f0f92ea227 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:15:23 -0500 Subject: [PATCH] fix(flatpak): fix broken desktop file, icons, and service (#3561) --- cmake/compile_definitions/linux.cmake | 8 ++++ cmake/packaging/linux.cmake | 43 +++++++++++-------- cmake/prep/init.cmake | 4 +- .../prep/special_package_configuration.cmake | 6 +-- packaging/linux/flatpak/scripts/sunshine.sh | 11 +++++ packaging/linux/flatpak/sunshine.desktop | 21 +++------ packaging/linux/flatpak/sunshine_kms.desktop | 6 --- src/system_tray.cpp | 8 ++-- 8 files changed, 58 insertions(+), 49 deletions(-) create mode 100644 packaging/linux/flatpak/scripts/sunshine.sh delete mode 100644 packaging/linux/flatpak/sunshine_kms.desktop diff --git a/cmake/compile_definitions/linux.cmake b/cmake/compile_definitions/linux.cmake index a7ad4bc8e5f..62ca61a64d5 100644 --- a/cmake/compile_definitions/linux.cmake +++ b/cmake/compile_definitions/linux.cmake @@ -198,6 +198,14 @@ if(${SUNSHINE_ENABLE_TRAY}) list(APPEND PLATFORM_TARGET_FILES "${CMAKE_SOURCE_DIR}/third-party/tray/src/tray_linux.c") list(APPEND SUNSHINE_EXTERNAL_LIBRARIES ${APPINDICATOR_LIBRARIES} ${LIBNOTIFY_LIBRARIES}) endif() + + # flatpak icons must be prefixed with the app id or they will not be included in the flatpak + if(${SUNSHINE_BUILD_FLATPAK}) + set(SUNSHINE_TRAY_PREFIX "${PROJECT_FQDN}") + else() + set(SUNSHINE_TRAY_PREFIX "sunshine") + endif() + list(APPEND SUNSHINE_DEFINITIONS SUNSHINE_TRAY_PREFIX="${SUNSHINE_TRAY_PREFIX}") else() set(SUNSHINE_TRAY 0) message(STATUS "Tray icon disabled") diff --git a/cmake/packaging/linux.cmake b/cmake/packaging/linux.cmake index 14b89ead8d1..6f4ebbe3c6a 100644 --- a/cmake/packaging/linux.cmake +++ b/cmake/packaging/linux.cmake @@ -100,15 +100,31 @@ endif() # tray icon if(${SUNSHINE_TRAY} STREQUAL 1) - install(FILES "${CMAKE_SOURCE_DIR}/sunshine.svg" - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status" - RENAME "sunshine-tray.svg") - install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/web/public/images/sunshine-playing.svg" - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status") - install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/web/public/images/sunshine-pausing.svg" - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status") - install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/web/public/images/sunshine-locked.svg" - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status") + if(NOT ${SUNSHINE_BUILD_FLATPAK}) + install(FILES "${CMAKE_SOURCE_DIR}/sunshine.svg" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status" + RENAME "sunshine-tray.svg") + install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/web/public/images/sunshine-playing.svg" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status") + install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/web/public/images/sunshine-pausing.svg" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status") + install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/web/public/images/sunshine-locked.svg" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status") + else() + # flatpak icons must be prefixed with the app id or they will not be included in the flatpak + install(FILES "${CMAKE_SOURCE_DIR}/sunshine.svg" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status" + RENAME "${PROJECT_FQDN}-tray.svg") + install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/web/public/images/sunshine-playing.svg" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status" + RENAME "${PROJECT_FQDN}-playing.svg") + install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/web/public/images/sunshine-pausing.svg" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status" + RENAME "${PROJECT_FQDN}-pausing.svg") + install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/common/assets/web/public/images/sunshine-locked.svg" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/status" + RENAME "${PROJECT_FQDN}-locked.svg") + endif() set(CPACK_DEBIAN_PACKAGE_DEPENDS "\ ${CPACK_DEBIAN_PACKAGE_DEPENDS}, \ @@ -128,15 +144,8 @@ else() install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sunshine.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" RENAME "${PROJECT_FQDN}.desktop") - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sunshine_kms.desktop" - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" - RENAME "${PROJECT_FQDN}_kms.desktop") endif() -if(${SUNSHINE_BUILD_FLATPAK}) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sunshine_terminal.desktop" - DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" - RENAME "${PROJECT_FQDN}_terminal.desktop") -elseif(NOT ${SUNSHINE_BUILD_APPIMAGE}) +if(NOT ${SUNSHINE_BUILD_APPIMAGE} AND NOT ${SUNSHINE_BUILD_FLATPAK}) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sunshine_terminal.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications") endif() diff --git a/cmake/prep/init.cmake b/cmake/prep/init.cmake index ae15d9f2673..4c03ecfb946 100644 --- a/cmake/prep/init.cmake +++ b/cmake/prep/init.cmake @@ -8,10 +8,10 @@ elseif (UNIX) endif() if(SUNSHINE_BUILD_FLATPAK) - set(SUNSHINE_SERVICE_START_COMMAND "ExecStart=${PROJECT_FQDN}") + set(SUNSHINE_SERVICE_START_COMMAND "ExecStart=flatpak run --command=sunshine ${PROJECT_FQDN}") set(SUNSHINE_SERVICE_STOP_COMMAND "ExecStop=flatpak kill ${PROJECT_FQDN}") else() set(SUNSHINE_SERVICE_START_COMMAND "ExecStart=${SUNSHINE_EXECUTABLE_PATH}") set(SUNSHINE_SERVICE_STOP_COMMAND "") endif() -endif () +endif() diff --git a/cmake/prep/special_package_configuration.cmake b/cmake/prep/special_package_configuration.cmake index df1bbb36a6b..298c0226faf 100644 --- a/cmake/prep/special_package_configuration.cmake +++ b/cmake/prep/special_package_configuration.cmake @@ -10,14 +10,12 @@ if(APPLE) endif() elseif(UNIX) # configure the .desktop file - set(SUNSHINE_DESKTOP_ICON "sunshine.svg") + set(SUNSHINE_DESKTOP_ICON "sunshine") if(${SUNSHINE_BUILD_APPIMAGE}) configure_file(packaging/linux/AppImage/sunshine.desktop sunshine.desktop @ONLY) elseif(${SUNSHINE_BUILD_FLATPAK}) - set(SUNSHINE_DESKTOP_ICON "${PROJECT_FQDN}.svg") + set(SUNSHINE_DESKTOP_ICON "${PROJECT_FQDN}") configure_file(packaging/linux/flatpak/sunshine.desktop sunshine.desktop @ONLY) - configure_file(packaging/linux/flatpak/sunshine_kms.desktop sunshine_kms.desktop @ONLY) - configure_file(packaging/linux/sunshine_terminal.desktop sunshine_terminal.desktop @ONLY) configure_file(packaging/linux/flatpak/${PROJECT_FQDN}.metainfo.xml ${PROJECT_FQDN}.metainfo.xml @ONLY) else() diff --git a/packaging/linux/flatpak/scripts/sunshine.sh b/packaging/linux/flatpak/scripts/sunshine.sh new file mode 100644 index 00000000000..6fb51457f84 --- /dev/null +++ b/packaging/linux/flatpak/scripts/sunshine.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +PORT=47990 + +if ! curl -k https://localhost:$PORT > /dev/null 2>&1; then + (sleep 3 && xdg-open https://localhost:$PORT) & + exec sunshine "$@" +else + echo "Sunshine is already running, opening the web interface..." + xdg-open https://localhost:$PORT +fi diff --git a/packaging/linux/flatpak/sunshine.desktop b/packaging/linux/flatpak/sunshine.desktop index f1753c9cdc3..eca745ef478 100644 --- a/packaging/linux/flatpak/sunshine.desktop +++ b/packaging/linux/flatpak/sunshine.desktop @@ -1,20 +1,9 @@ [Desktop Entry] -Type=Application -Name=@PROJECT_NAME@ -Exec=@PROJECT_FQDN@ -Version=1.0 +Categories=AudioVideo;Network;RemoteAccess; Comment=@PROJECT_DESCRIPTION@ +Exec=sunshine.sh Icon=@SUNSHINE_DESKTOP_ICON@ Keywords=gamestream;stream;moonlight;remote play; -Categories=AudioVideo;Network;RemoteAccess; -Actions=RunInTerminal;KMS; - -[Desktop Action RunInTerminal] -Name=Run in Terminal -Icon=application-x-executable -Exec=gio launch @CMAKE_INSTALL_FULL_DATAROOTDIR@/applications/@PROJECT_FQDN@_terminal.desktop - -[Desktop Action KMS] -Name=Run in Terminal (KMS) -Icon=application-x-executable -Exec=gio launch @CMAKE_INSTALL_FULL_DATAROOTDIR@/applications/@PROJECT_FQDN@_kms.desktop +Name=@PROJECT_NAME@ +Type=Application +Version=1.0 diff --git a/packaging/linux/flatpak/sunshine_kms.desktop b/packaging/linux/flatpak/sunshine_kms.desktop deleted file mode 100644 index 59d35d7168c..00000000000 --- a/packaging/linux/flatpak/sunshine_kms.desktop +++ /dev/null @@ -1,6 +0,0 @@ -[Desktop Entry] -Name=@PROJECT_NAME@ (KMS) -Exec=sudo -i PULSE_SERVER=unix:$(pactl info | awk '/Server String/{print$3}') flatpak run @PROJECT_FQDN@ -Terminal=true -Type=Application -NoDisplay=true diff --git a/src/system_tray.cpp b/src/system_tray.cpp index 981ddfc5c84..621a809c0b8 100644 --- a/src/system_tray.cpp +++ b/src/system_tray.cpp @@ -14,10 +14,10 @@ #define TRAY_ICON_PAUSING WEB_DIR "images/sunshine-pausing.ico" #define TRAY_ICON_LOCKED WEB_DIR "images/sunshine-locked.ico" #elif defined(__linux__) || defined(linux) || defined(__linux) - #define TRAY_ICON "sunshine-tray" - #define TRAY_ICON_PLAYING "sunshine-playing" - #define TRAY_ICON_PAUSING "sunshine-pausing" - #define TRAY_ICON_LOCKED "sunshine-locked" + #define TRAY_ICON SUNSHINE_TRAY_PREFIX "-tray" + #define TRAY_ICON_PLAYING SUNSHINE_TRAY_PREFIX "-playing" + #define TRAY_ICON_PAUSING SUNSHINE_TRAY_PREFIX "-pausing" + #define TRAY_ICON_LOCKED SUNSHINE_TRAY_PREFIX "-locked" #elif defined(__APPLE__) || defined(__MACH__) #define TRAY_ICON WEB_DIR "images/logo-sunshine-16.png" #define TRAY_ICON_PLAYING WEB_DIR "images/sunshine-playing-16.png"