feat(app): deal with autostart on flatpak

This commit is contained in:
Ronan Abhamon 2019-01-21 15:06:19 +01:00
parent b8405e24bd
commit 7d9ead5b7f
4 changed files with 21 additions and 12 deletions

View file

@ -1,4 +1,5 @@
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")

View file

@ -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>

View file

@ -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);

View file

@ -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}"