From 272d2da04af1e5a98b63cdebae52ea0e5a060407 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 22 Jul 2023 01:07:47 +0400 Subject: [PATCH] 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. --- .../platform/linux/specific_linux.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index e53ac78b03..81ff88729f 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -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,