mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-04 06:45:45 +02:00
misc: add start on login support for linux
Gitlab: #160 Change-Id: I166988985e4a2c9b1d06d21ba0a1394159478172
This commit is contained in:
parent
69db8684a1
commit
8caf659bb8
2 changed files with 96 additions and 3 deletions
|
@ -13,7 +13,8 @@ set(CMAKE_AUTOUIC ON)
|
|||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}
|
||||
-DJAMI_DATA_DIR='"'${CMAKE_INSTALL_PREFIX}/share/jami-qt'"')
|
||||
|
||||
set(QML_RESOURCES ${PROJECT_SOURCE_DIR}/resources.qrc)
|
||||
set(QML_RESOURCES_QML ${PROJECT_SOURCE_DIR}/qml.qrc)
|
||||
|
@ -230,6 +231,18 @@ install(TARGETS jami-qt
|
|||
install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
|
||||
|
||||
# install .desktop in the jami-qt data dir, so that it can be copied to the
|
||||
# autostart dir by the client
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
|
||||
DESTINATION
|
||||
${CMAKE_INSTALL_PREFIX}/share/jami-qt
|
||||
PERMISSIONS
|
||||
WORLD_READ
|
||||
OWNER_WRITE
|
||||
OWNER_READ
|
||||
GROUP_READ
|
||||
)
|
||||
|
||||
# logos
|
||||
install(FILES images/jami.svg
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps)
|
||||
|
|
|
@ -69,7 +69,72 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
|
|||
|
||||
return Utils::CreateLink(programPath.c_str(), linkPath.c_str());
|
||||
#else
|
||||
return true;
|
||||
|
||||
QString desktopPath;
|
||||
/* cmake should set JAMI_DATA_DIR, otherwise it checks the following dirs
|
||||
* - /usr/<data dir>
|
||||
* - /usr/local/<data dir>
|
||||
* - default install data dir
|
||||
*/
|
||||
|
||||
#ifdef JAMI_DATA_DIR
|
||||
desktopPath = JAMI_DATA_DIR;
|
||||
desktopPath = 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" };
|
||||
for (QString filename : paths) {
|
||||
if (QFile::exists(filename)) {
|
||||
desktopPath = filename;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (desktopPath.isEmpty() || !(QFile::exists(desktopPath))) {
|
||||
qDebug() << "Cannot locate .desktop file";
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "Setting autostart link from " << desktopPath;
|
||||
|
||||
QString symlink = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
"autostart/jami-qt.desktop");
|
||||
if (!symlink.isEmpty()) {
|
||||
QFileInfo symlinkInfo(symlink);
|
||||
if (symlinkInfo.isSymLink()) {
|
||||
if (symlinkInfo.symLinkTarget() == desktopPath) {
|
||||
qDebug() << symlink << "already points to" << desktopPath;
|
||||
return true;
|
||||
} else {
|
||||
qDebug() << symlink << "exists but does not point to " << desktopPath;
|
||||
QFile::remove(symlink);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
QString autoStartDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)
|
||||
+ "/autostart";
|
||||
|
||||
if (!QDir(autoStartDir).exists()) {
|
||||
if (QDir().mkdir(autoStartDir)) {
|
||||
qDebug() << "Created autostart directory: " << autoStartDir;
|
||||
} else {
|
||||
qWarning() << "Cannot create autostart directory: " << autoStartDir;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
symlink = autoStartDir + "/jami-qt.desktop";
|
||||
}
|
||||
|
||||
QFile srcFile (desktopPath);
|
||||
|
||||
bool result = srcFile.link(symlink);
|
||||
qDebug() << symlink << (result ? "->" + desktopPath + " created successfully"
|
||||
: "cannot be created");
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -116,6 +181,20 @@ Utils::DeleteStartupLink(const std::wstring& wstrAppName)
|
|||
linkPath += std::wstring(TEXT("\\") + wstrAppName + TEXT(".lnk"));
|
||||
|
||||
DeleteFile(linkPath.c_str());
|
||||
|
||||
#else
|
||||
QString symlink = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
"autostart/jami-qt.desktop");
|
||||
if (!symlink.isEmpty()) {
|
||||
try {
|
||||
QFile::remove(symlink);
|
||||
qDebug() << "Autostart disabled," << symlink << "removed";
|
||||
} catch (...) {
|
||||
qDebug() << "Could not remove" << symlink;
|
||||
}
|
||||
} else {
|
||||
qDebug() << "jami-qt.desktop symlink does not exist";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -130,7 +209,8 @@ Utils::CheckStartupLink(const std::wstring& wstrAppName)
|
|||
linkPath += std::wstring(TEXT("\\") + wstrAppName + TEXT(".lnk"));
|
||||
return PathFileExists(linkPath.c_str());
|
||||
#else
|
||||
return true;
|
||||
return (!QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
"autostart/jami-qt.desktop").isEmpty());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue