autostart: Linux: Exec= filename not absolute path

Systems like NixOS install software under unique paths, so persisting
the absolute file path in the generated .desktop file when enabling
autostart will eventually point at an outdated or nonexistent program.

Another possible issue with using Qt's `applicationFilePath()` is that
the final program's basename (`argv[0]`) might not be the same as what
the user initially executed to start KeePassXC.

Use the file name and thus rely on `PATH` lookup just like the static
.desktop file does to lift those issues and defer execution logic
(`PATH` lookup, wrapper scripts, etc.) to the operating system.
This commit is contained in:
Klemens Nanni 2022-06-24 18:59:06 +04:00 committed by Jonathan White
parent e05f6a4c5b
commit 14f12b0a25

View File

@ -128,15 +128,15 @@ void NixUtils::setLaunchAtStartup(bool enable)
const QString appImagePath = QString::fromLocal8Bit(qgetenv("APPIMAGE")); const QString appImagePath = QString::fromLocal8Bit(qgetenv("APPIMAGE"));
const bool isAppImage = !appImagePath.isNull() && QFile::exists(appImagePath); const bool isAppImage = !appImagePath.isNull() && QFile::exists(appImagePath);
const QString executeablePath = isAppImage ? appImagePath : QApplication::applicationFilePath(); const QString executeablePathOrName = isAppImage ? appImagePath : QApplication::applicationName().toLower();
QTextStream stream(&desktopFile); QTextStream stream(&desktopFile);
stream.setCodec("UTF-8"); stream.setCodec("UTF-8");
stream << QStringLiteral("[Desktop Entry]") << '\n' stream << QStringLiteral("[Desktop Entry]") << '\n'
<< QStringLiteral("Name=") << QApplication::applicationDisplayName() << '\n' << QStringLiteral("Name=") << QApplication::applicationDisplayName() << '\n'
<< QStringLiteral("GenericName=") << tr("Password Manager") << '\n' << QStringLiteral("GenericName=") << tr("Password Manager") << '\n'
<< QStringLiteral("Exec=") << executeablePath << '\n' << QStringLiteral("Exec=") << executeablePathOrName << '\n'
<< QStringLiteral("TryExec=") << executeablePath << '\n' << QStringLiteral("TryExec=") << executeablePathOrName << '\n'
<< QStringLiteral("Icon=") << QApplication::applicationName().toLower() << '\n' << QStringLiteral("Icon=") << QApplication::applicationName().toLower() << '\n'
<< QStringLiteral("StartupWMClass=keepassxc") << '\n' << QStringLiteral("StartupWMClass=keepassxc") << '\n'
<< QStringLiteral("StartupNotify=true") << '\n' << QStringLiteral("StartupNotify=true") << '\n'