From 3225f90ce87f2285f1860bff57f4aebc3590641d Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Fri, 12 Apr 2024 17:21:40 -0400
Subject: [PATCH] misc: deploy and use ringtones on macOS

Gitlab: #1619
Change-Id: I7c19dfa4556f4f9dae827a1d0c967c9ebce7cc86
---
 CMakeLists.txt                              | 15 +++++++++++----
 src/libclient/qtwrapper/instancemanager.cpp | 16 ++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3f0baa97f..3fb265b36 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -819,12 +819,20 @@ else()
     "-framework Security"
       compression
       resolv
-    )
+  )
+
+  set(APP_CONTAINER "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents")
+
+  # ringtones. Copy the entire directory to the app bundle.
+  # daemon/ringtones -> Jami.app/Contents/Resources/ringtones
+  execute_process(
+    COMMAND ${CMAKE_COMMAND} -E copy_directory
+    ${DAEMON_DIR}/ringtones
+    ${APP_CONTAINER}/Resources/ringtones
+  )
 
   # translations
   if(Qt${QT_VERSION_MAJOR}LinguistTools_FOUND)
-    set(APP_CONTAINER
-      "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app/Contents")
     file(GLOB TS_FILES ${PROJECT_SOURCE_DIR}/translations/*.ts)
 
     # Generate lproj folders.
@@ -864,7 +872,6 @@ else()
           XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME TRUE)
   endif()
   if(DEPLOY)
-    message("Qt deploying in dir " ${QML_SRC_DIR})
     execute_process(COMMAND
       "${CMAKE_PREFIX_PATH}/bin/macdeployqt"
       "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app"
diff --git a/src/libclient/qtwrapper/instancemanager.cpp b/src/libclient/qtwrapper/instancemanager.cpp
index da9dd021c..58983c189 100644
--- a/src/libclient/qtwrapper/instancemanager.cpp
+++ b/src/libclient/qtwrapper/instancemanager.cpp
@@ -24,11 +24,27 @@
 #ifdef ENABLE_VIDEO
 #include "videomanager.h"
 #endif // ENABLE_VIDEO
+#include <QDir>
 
 static int ringFlags = 0;
 
 InstanceManagerInterface::InstanceManagerInterface(bool muteDaemon)
 {
+    // The following code is used to set the resource directory for libjami, and is required
+    // for the ringtones to work properly on platforms where the resource directory path is not
+    // fixed (e.g. macOS).
+#if defined(Q_OS_WIN)
+    // On Windows, the resource directory is set to the application's directory.
+    libjami::setResourceDirPath(QCoreApplication::applicationDirPath().toStdString());
+#elif defined(Q_OS_MAC)
+    // On macOS, the resource directory is set to the application bundle's path + "/Resources".
+    // The application bundle's path is the application's directory.
+    QDir execDir(qApp->applicationDirPath()); // executable directory points to the app bundle + /Contents/MacOS/
+    execDir.cdUp(); // navigate up to add resources to /Contents
+    auto resourceDir = execDir.absolutePath() + QDir::separator() + "Resources";
+    libjami::setResourceDirPath(resourceDir.toStdString());
+#endif
+
     using namespace std::placeholders;
 
     using std::bind;
-- 
GitLab