Skip to content
Snippets Groups Projects
Commit e93854e1 authored by Amin Bandali's avatar Amin Bandali
Browse files

autostart: revision for snap packaging


Adjust JAMI_DATA_PATH (and in turn JAMI_DATA_DIR) for snap after any
cmake 'install' command definitions that refer to it, so that the
version compiled into the package using target_compile_definitions
will have the right value for our snap package.  With this particular
configuration, we don't have to check for JAMI_DATA_DIR during runtime
since it will have the right value set at build time, and the path it
points to (/snap/jami/current/...) is actually stable across updates,
so we don't have to worry about correcting the autostart desktop file
symlink after each upgrade.

Note: as the comments in CMakeLists.txt mention, it is crucial that
JAMI_DATA_PATH is only adjusted after all 'install' commands that
refer to it, because its snap-specific value isn't meant to be used
during build time as an install destination.  Also, that the call to
target_compile_definitions must come after the JAMI_DATA_PATH change
described earlier.

Co-authored-by: default avatarababi <albert.babi@savoirfairelinux.com>

Gitlab: #262
Change-Id: I07896be8195c336833bcd4a84b918276eddbe159
parent bb19af31
No related branches found
No related tags found
No related merge requests found
...@@ -207,8 +207,7 @@ add_executable(${PROJECT_NAME} ...@@ -207,8 +207,7 @@ add_executable(${PROJECT_NAME}
${QML_RESOURCES_QML} ${QML_RESOURCES_QML}
${LRC_SRC_PATH}/webresource.qrc) ${LRC_SRC_PATH}/webresource.qrc)
target_compile_definitions(jami-qt PRIVATE set(JAMI_DATA_PATH "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
JAMI_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
find_library(ringclient ringclient ${LRCLIBDIR} NO_DEFAULT_PATH) find_library(ringclient ringclient ${LRCLIBDIR} NO_DEFAULT_PATH)
find_library(qrencode qrencode) find_library(qrencode qrencode)
...@@ -228,7 +227,7 @@ endif() ...@@ -228,7 +227,7 @@ endif()
# Installation rules # Installation rules
install(TARGETS jami-qt install(TARGETS jami-qt
RUNTIME DESTINATION bin) RUNTIME DESTINATION bin)
# install .desktop in XDG desktop dir so that it is recognized by the system # install .desktop in XDG desktop dir so that it is recognized by the system
install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
...@@ -238,7 +237,7 @@ install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop ...@@ -238,7 +237,7 @@ install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
# autostart dir by the client # autostart dir by the client
install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
DESTINATION DESTINATION
${CMAKE_INSTALL_PREFIX}/share/jami-qt ${JAMI_DATA_PATH}
PERMISSIONS PERMISSIONS
WORLD_READ WORLD_READ
OWNER_WRITE OWNER_WRITE
...@@ -246,6 +245,17 @@ install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop ...@@ -246,6 +245,17 @@ install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
GROUP_READ GROUP_READ
) )
# adjust JAMI_DATA_PATH for snap package
# (this must come after all 'install' commands that refer to
# JAMI_DATA_PATH; the following value is not meant to be used for
# any install destinations)
if(DEFINED ENV{SNAPCRAFT_PROJECT_NAME})
set(JAMI_DATA_PATH "/snap/$ENV{SNAPCRAFT_PROJECT_NAME}/current/usr/share/${PROJECT_NAME}")
endif()
# (this must come after the above adjustment to JAMI_DATA_PATH)
target_compile_definitions(jami-qt PRIVATE JAMI_DATA_DIR="${JAMI_DATA_PATH}")
# logos # logos
install(FILES images/jami.svg install(FILES images/jami.svg
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps) DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps)
......
...@@ -69,7 +69,6 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName) ...@@ -69,7 +69,6 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
return Utils::CreateLink(programPath.c_str(), linkPath.c_str()); return Utils::CreateLink(programPath.c_str(), linkPath.c_str());
#else #else
QString desktopPath; QString desktopPath;
/* cmake should set JAMI_DATA_DIR, otherwise it checks the following dirs /* cmake should set JAMI_DATA_DIR, otherwise it checks the following dirs
* - /usr/<data dir> * - /usr/<data dir>
...@@ -79,13 +78,13 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName) ...@@ -79,13 +78,13 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
#ifdef JAMI_DATA_DIR #ifdef JAMI_DATA_DIR
desktopPath = JAMI_DATA_DIR; desktopPath = JAMI_DATA_DIR;
desktopPath = desktopPath + "/jami-qt.desktop"; desktopPath += "/jami-qt.desktop";
#else #else
QString dataDir = "share/jami-qt/"; desktopPath = "share/jami-qt/jami-qt.desktop";
QStringList paths = { "/usr/" + dataDir + "jami-qt.desktop", QStringList paths = {
"/usr/local/" + dataDir + "jami-qt.desktop", "/usr/" + desktopPath,
QDir::currentPath() + "/../../install/" "/usr/local/" + desktopPath,
+ dataDir + "jami-qt/jami-qt.desktop" }; QDir::currentPath() + "/../../install/client-qt/" + desktopPath };
for (QString filename : paths) { for (QString filename : paths) {
if (QFile::exists(filename)) { if (QFile::exists(filename)) {
desktopPath = filename; desktopPath = filename;
...@@ -95,23 +94,23 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName) ...@@ -95,23 +94,23 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
#endif #endif
if (desktopPath.isEmpty() || !(QFile::exists(desktopPath))) { if (desktopPath.isEmpty() || !(QFile::exists(desktopPath))) {
qDebug() << "Cannot locate .desktop file"; qDebug() << "Could not locate .desktop file at" << desktopPath;
return false; return false;
} }
qDebug() << "Setting autostart link from " << desktopPath; qDebug() << "Linking autostart file from" << desktopPath;
QString symlink = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString desktopFile = QStandardPaths::locate(QStandardPaths::ConfigLocation,
"autostart/jami-qt.desktop"); "autostart/jami-qt.desktop");
if (!symlink.isEmpty()) { if (!desktopFile.isEmpty()) {
QFileInfo symlinkInfo(symlink); QFileInfo symlinkInfo(desktopFile);
if (symlinkInfo.isSymLink()) { if (symlinkInfo.isSymLink()) {
if (symlinkInfo.symLinkTarget() == desktopPath) { if (symlinkInfo.symLinkTarget() == desktopPath) {
qDebug() << symlink << "already points to" << desktopPath; qDebug() << desktopFile << "already points to" << desktopPath;
return true; return true;
} else { } else {
qDebug() << symlink << "exists but does not point to " << desktopPath; qDebug() << desktopFile << "exists but does not point to" << desktopPath;
QFile::remove(symlink); QFile::remove(desktopFile);
} }
} }
} else { } else {
...@@ -120,20 +119,20 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName) ...@@ -120,20 +119,20 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
if (!QDir(autoStartDir).exists()) { if (!QDir(autoStartDir).exists()) {
if (QDir().mkdir(autoStartDir)) { if (QDir().mkdir(autoStartDir)) {
qDebug() << "Created autostart directory: " << autoStartDir; qDebug() << "Created autostart directory:" << autoStartDir;
} else { } else {
qWarning() << "Cannot create autostart directory: " << autoStartDir; qWarning() << "Could not create autostart directory:" << autoStartDir;
return false; return false;
} }
} }
symlink = autoStartDir + "/jami-qt.desktop"; desktopFile = autoStartDir + "/jami-qt.desktop";
} }
QFile srcFile (desktopPath); QFile srcFile(desktopPath);
bool result = srcFile.link(desktopFile);
bool result = srcFile.link(symlink); qDebug() << desktopFile << (result
qDebug() << symlink << (result ? "->" + desktopPath + " created successfully" ? "-> " + desktopPath + " successfully created"
: "cannot be created"); : "could not be created");
return result; return result;
#endif #endif
} }
...@@ -183,17 +182,17 @@ Utils::DeleteStartupLink(const std::wstring& wstrAppName) ...@@ -183,17 +182,17 @@ Utils::DeleteStartupLink(const std::wstring& wstrAppName)
DeleteFile(linkPath.c_str()); DeleteFile(linkPath.c_str());
#else #else
QString symlink = QStandardPaths::locate(QStandardPaths::ConfigLocation, QString desktopFile = QStandardPaths::locate(QStandardPaths::ConfigLocation,
"autostart/jami-qt.desktop"); "autostart/jami-qt.desktop");
if (!symlink.isEmpty()) { if (!desktopFile.isEmpty()) {
try { try {
QFile::remove(symlink); QFile::remove(desktopFile);
qDebug() << "Autostart disabled," << symlink << "removed"; qDebug() << "Autostart disabled," << desktopFile << "removed";
} catch (...) { } catch (...) {
qDebug() << "Could not remove" << symlink; qDebug() << "Could not remove" << desktopFile;
} }
} else { } else {
qDebug() << "jami-qt.desktop symlink does not exist"; qDebug() << desktopFile << "does not exist";
} }
#endif #endif
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment