mirror of
https://github.com/savoirfairelinux/jami-client-qt.git
synced 2026-01-03 10:35:05 +08: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:
@@ -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,
|
||||
"autostart/jami-qt.desktop");
|
||||
if (!symlink.isEmpty()) {
|
||||
QFileInfo symlinkInfo(symlink);
|
||||
QString desktopFile = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
"autostart/jami-qt.desktop");
|
||||
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 {
|
||||
@@ -120,20 +119,20 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
|
||||
|
||||
if (!QDir(autoStartDir).exists()) {
|
||||
if (QDir().mkdir(autoStartDir)) {
|
||||
qDebug() << "Created autostart directory: " << 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");
|
||||
QFile srcFile(desktopPath);
|
||||
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,
|
||||
"autostart/jami-qt.desktop");
|
||||
if (!symlink.isEmpty()) {
|
||||
QString desktopFile = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
"autostart/jami-qt.desktop");
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user