Commit 7d9ead5b authored by Ronan's avatar Ronan

feat(app): deal with autostart on flatpak

parent b8405e24
Pipeline #2146 passed with stages
in 31 minutes and 23 seconds
set(APPLICATION_DESCRIPTION "A libre SIP client")
set(APPLICATION_ID "com.belledonnecommunications.linphone")
set(APPLICATION_NAME Linphone)
set(APPLICATION_URL "https://www.linphone.org")
set(APPLICATION_VENDOR "Belledonne Communications")
......
......@@ -36,7 +36,7 @@
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.belledonnecommunications.linphone</string>
<string>@APPLICATION_ID@</string>
<key>CFBundleURLSchemes</key>
<array>
<string>sip</string>
......
......@@ -76,13 +76,13 @@ namespace {
constexpr char AssistantViewName[] = "Assistant";
#ifdef Q_OS_LINUX
QString AutoStartDirectory(
QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).at(0) + QLatin1String("/autostart/")
);
const QString AutoStartDirectory(QDir::homePath().append(QStringLiteral("/.config/autostart/")));
#elif defined(Q_OS_MACOS)
QString OsascriptExecutable("osascript");
const QString OsascriptExecutable(QStringLiteral("osascript"));
#else
QString AutoStartSettingsFilePath("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
const QString AutoStartSettingsFilePath(
QStringLiteral("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run")
);
#endif // ifdef Q_OS_LINUX
}
......@@ -673,7 +673,9 @@ void App::setAutoStart (bool enabled) {
return;
}
QFile file(AutoStartDirectory + EXECUTABLE_NAME ".desktop");
const QString confPath(AutoStartDirectory + EXECUTABLE_NAME ".desktop");
qInfo() << QStringLiteral("Updating `%1`...").arg(confPath);
QFile file(confPath);
if (!enabled) {
if (file.exists() && !file.remove()) {
......@@ -691,20 +693,25 @@ void App::setAutoStart (bool enabled) {
return;
}
QString fileContent(
const QString binPath(applicationFilePath());
const QString exec(
binPath.startsWith("/app")
? QStringLiteral("flatpak run " APPLICATION_ID)
: binPath
);
QTextStream(&file) << QString(
"[Desktop Entry]\n"
"Name=" APPLICATION_NAME "\n"
"GenericName=SIP Phone\n"
"Comment=" APPLICATION_DESCRIPTION "\n"
"Type=Application\n"
"Exec=" + applicationFilePath() + "\n"
"Exec=" + exec + "\n"
"Icon=\n"
"Terminal=false\n"
"Categories=Network;Telephony;\n"
"MimeType=x-scheme-handler/sip-linphone;x-scheme-handler/sip;x-scheme-handler/sips-linphone;x-scheme-handler/sips;\n"
);
QTextStream out(&file);
out << fileContent;
mAutoStart = enabled;
emit autoStartChanged(enabled);
......
......@@ -20,8 +20,9 @@
*
*******************************************************************************/
#cmakedefine APPLICATION_NAME "${APPLICATION_NAME}"
#cmakedefine APPLICATION_DESCRIPTION "${APPLICATION_DESCRIPTION}"
#cmakedefine APPLICATION_ID "${APPLICATION_ID}"
#cmakedefine APPLICATION_NAME "${APPLICATION_NAME}"
#cmakedefine ENABLE_UPDATE_CHECK 1
#cmakedefine EXECUTABLE_NAME "${EXECUTABLE_NAME}"
#cmakedefine MSPLUGINS_DIR "${MSPLUGINS_DIR}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment