mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-04-21 21:52:03 +02:00
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: ababi <albert.babi@savoirfairelinux.com> Gitlab: #262 Change-Id: I07896be8195c336833bcd4a84b918276eddbe159
This commit is contained in:
parent
bb19af3194
commit
e93854e137
2 changed files with 44 additions and 35 deletions
|
@ -207,8 +207,7 @@ add_executable(${PROJECT_NAME}
|
|||
${QML_RESOURCES_QML}
|
||||
${LRC_SRC_PATH}/webresource.qrc)
|
||||
|
||||
target_compile_definitions(jami-qt PRIVATE
|
||||
JAMI_DATA_DIR="${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
|
||||
set(JAMI_DATA_PATH "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
|
||||
|
||||
find_library(ringclient ringclient ${LRCLIBDIR} NO_DEFAULT_PATH)
|
||||
find_library(qrencode qrencode)
|
||||
|
@ -238,7 +237,7 @@ install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
|
|||
# autostart dir by the client
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
|
||||
DESTINATION
|
||||
${CMAKE_INSTALL_PREFIX}/share/jami-qt
|
||||
${JAMI_DATA_PATH}
|
||||
PERMISSIONS
|
||||
WORLD_READ
|
||||
OWNER_WRITE
|
||||
|
@ -246,6 +245,17 @@ install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
|
|||
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
|
||||
install(FILES images/jami.svg
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps)
|
||||
|
|
|
@ -69,7 +69,6 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
|
|||
|
||||
return Utils::CreateLink(programPath.c_str(), linkPath.c_str());
|
||||
#else
|
||||
|
||||
QString desktopPath;
|
||||
/* cmake should set JAMI_DATA_DIR, otherwise it checks the following dirs
|
||||
* - /usr/<data dir>
|
||||
|
@ -79,13 +78,13 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
|
|||
|
||||
#ifdef JAMI_DATA_DIR
|
||||
desktopPath = JAMI_DATA_DIR;
|
||||
desktopPath = desktopPath + "/jami-qt.desktop";
|
||||
desktopPath += "/jami-qt.desktop";
|
||||
#else
|
||||
QString dataDir = "share/jami-qt/";
|
||||
QStringList paths = { "/usr/" + dataDir + "jami-qt.desktop",
|
||||
"/usr/local/" + dataDir + "jami-qt.desktop",
|
||||
QDir::currentPath() + "/../../install/"
|
||||
+ dataDir + "jami-qt/jami-qt.desktop" };
|
||||
desktopPath = "share/jami-qt/jami-qt.desktop";
|
||||
QStringList paths = {
|
||||
"/usr/" + desktopPath,
|
||||
"/usr/local/" + desktopPath,
|
||||
QDir::currentPath() + "/../../install/client-qt/" + desktopPath };
|
||||
for (QString filename : paths) {
|
||||
if (QFile::exists(filename)) {
|
||||
desktopPath = filename;
|
||||
|
@ -95,23 +94,23 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
|
|||
#endif
|
||||
|
||||
if (desktopPath.isEmpty() || !(QFile::exists(desktopPath))) {
|
||||
qDebug() << "Cannot locate .desktop file";
|
||||
qDebug() << "Could not locate .desktop file at" << desktopPath;
|
||||
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");
|
||||
if (!symlink.isEmpty()) {
|
||||
QFileInfo symlinkInfo(symlink);
|
||||
if (!desktopFile.isEmpty()) {
|
||||
QFileInfo symlinkInfo(desktopFile);
|
||||
if (symlinkInfo.isSymLink()) {
|
||||
if (symlinkInfo.symLinkTarget() == desktopPath) {
|
||||
qDebug() << symlink << "already points to" << desktopPath;
|
||||
qDebug() << desktopFile << "already points to" << desktopPath;
|
||||
return true;
|
||||
} else {
|
||||
qDebug() << symlink << "exists but does not point to " << desktopPath;
|
||||
QFile::remove(symlink);
|
||||
qDebug() << desktopFile << "exists but does not point to" << desktopPath;
|
||||
QFile::remove(desktopFile);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -122,18 +121,18 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
|
|||
if (QDir().mkdir(autoStartDir)) {
|
||||
qDebug() << "Created autostart directory:" << autoStartDir;
|
||||
} else {
|
||||
qWarning() << "Cannot create autostart directory: " << autoStartDir;
|
||||
qWarning() << "Could not create autostart directory:" << autoStartDir;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
symlink = autoStartDir + "/jami-qt.desktop";
|
||||
desktopFile = autoStartDir + "/jami-qt.desktop";
|
||||
}
|
||||
|
||||
QFile srcFile(desktopPath);
|
||||
|
||||
bool result = srcFile.link(symlink);
|
||||
qDebug() << symlink << (result ? "->" + desktopPath + " created successfully"
|
||||
: "cannot be created");
|
||||
bool result = srcFile.link(desktopFile);
|
||||
qDebug() << desktopFile << (result
|
||||
? "-> " + desktopPath + " successfully created"
|
||||
: "could not be created");
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
@ -183,17 +182,17 @@ Utils::DeleteStartupLink(const std::wstring& wstrAppName)
|
|||
DeleteFile(linkPath.c_str());
|
||||
|
||||
#else
|
||||
QString symlink = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
QString desktopFile = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
"autostart/jami-qt.desktop");
|
||||
if (!symlink.isEmpty()) {
|
||||
if (!desktopFile.isEmpty()) {
|
||||
try {
|
||||
QFile::remove(symlink);
|
||||
qDebug() << "Autostart disabled," << symlink << "removed";
|
||||
QFile::remove(desktopFile);
|
||||
qDebug() << "Autostart disabled," << desktopFile << "removed";
|
||||
} catch (...) {
|
||||
qDebug() << "Could not remove" << symlink;
|
||||
qDebug() << "Could not remove" << desktopFile;
|
||||
}
|
||||
} else {
|
||||
qDebug() << "jami-qt.desktop symlink does not exist";
|
||||
qDebug() << desktopFile << "does not exist";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue