Stabilize app id on Linux when -workdir is set to the default workdir

Currently the app id hash is generated from workdir path only when it's set explicitly and that's for a good reason: the default workdir could be changed (e.g. by creating a TelegramForcePortable) and app id would change what would result in a duplicate .desktop created.

The current code has the possibility of having duplicate .desktop files, too, as it happened, but by specifying -workdir to the same directory as the default one.

There's now a check that ensures the specified workdir is really custom so those duplicate launchers could be removed what should really stabilize the hash.
This commit is contained in:
Ilya Fedin 2023-07-22 01:07:47 +04:00 committed by John Preston
parent cd7539c001
commit 272d2da04a
1 changed files with 17 additions and 1 deletions

View File

@ -309,6 +309,10 @@ bool GenerateDesktopFile(
hashMd5Hex(d.constData(), d.size(), md5Hash);
if (!Core::Launcher::Instance().customWorkingDir()) {
QFile::remove(u"%1org.telegram.desktop._%2.desktop"_q.arg(
targetPath,
md5Hash));
const auto exePath = QFile::encodeName(
cExeDir() + cExeName());
hashMd5Hex(exePath.constData(), exePath.size(), md5Hash);
@ -335,7 +339,7 @@ bool GenerateServiceFile(bool silent = false) {
+ QGuiApplication::desktopFileName()
+ u".service"_q;
DEBUG_LOG(("App Info: placing .service file to %1").arg(targetPath));
DEBUG_LOG(("App Info: placing D-Bus service file to %1").arg(targetPath));
if (!QDir(targetPath).exists()) QDir().mkpath(targetPath);
const auto target = Glib::KeyFile::create();
@ -366,6 +370,18 @@ bool GenerateServiceFile(bool silent = false) {
return false;
}
if (!Core::UpdaterDisabled() && !Core::Launcher::Instance().customWorkingDir()) {
DEBUG_LOG(("App Info: removing old D-Bus service files"));
char md5Hash[33] = { 0 };
const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath());
hashMd5Hex(d.constData(), d.size(), md5Hash);
QFile::remove(u"%1org.telegram.desktop._%2.service"_q.arg(
targetPath,
md5Hash));
}
QProcess::execute(u"systemctl"_q, {
u"--user"_q,
u"reload"_q,