mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-09 00:27:09 +00:00
Split launcher filename detection to a function
This commit is contained in:
parent
e6cec49646
commit
a831c1703a
@ -249,7 +249,7 @@ void Launcher::init() {
|
||||
QApplication::setApplicationName(qsl("TelegramDesktop"));
|
||||
|
||||
#if defined(Q_OS_LINUX) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
|
||||
QApplication::setDesktopFileName(qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME)) + ".desktop");
|
||||
QApplication::setDesktopFileName(Platform::GetLauncherFilename());
|
||||
#endif
|
||||
|
||||
#ifndef OS_MAC_OLD
|
||||
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
#include "styles/style_window.h"
|
||||
#include "platform/linux/linux_libs.h"
|
||||
#include "platform/linux/specific_linux.h"
|
||||
#include "platform/linux/linux_desktop_environment.h"
|
||||
#include "platform/platform_notifications_manager.h"
|
||||
#include "history/history.h"
|
||||
@ -29,8 +30,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
namespace Platform {
|
||||
namespace {
|
||||
|
||||
constexpr auto kLauncherBasename = MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME) ".desktop"_cs;
|
||||
|
||||
bool noQtTrayIcon = false, tryAppIndicator = false;
|
||||
bool useGtkBase = false, useAppIndicator = false, useStatusIcon = false, trayIconChecked = false, useUnityCount = false;
|
||||
|
||||
@ -556,32 +555,21 @@ void MainWindow::psFirstShow() {
|
||||
|
||||
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
|
||||
if (QDBusInterface("com.canonical.Unity", "/").isValid()) {
|
||||
auto snapName = QString::fromLatin1(qgetenv("SNAP_NAME"));
|
||||
if (snapName.isEmpty()) {
|
||||
std::vector<QString> possibleDesktopFiles = {
|
||||
kLauncherBasename.utf16(),
|
||||
"Telegram.desktop"
|
||||
};
|
||||
std::vector<QString> possibleDesktopFiles = {
|
||||
GetLauncherFilename(),
|
||||
"Telegram.desktop"
|
||||
};
|
||||
|
||||
for (auto it = possibleDesktopFiles.begin(); it != possibleDesktopFiles.end(); it++) {
|
||||
if (!QStandardPaths::locate(QStandardPaths::ApplicationsLocation, *it).isEmpty()) {
|
||||
_desktopFile = *it;
|
||||
LOG(("Found Unity Launcher entry %1!").arg(_desktopFile));
|
||||
useUnityCount = true;
|
||||
break;
|
||||
}
|
||||
for (auto it = possibleDesktopFiles.begin(); it != possibleDesktopFiles.end(); it++) {
|
||||
if (!QStandardPaths::locate(QStandardPaths::ApplicationsLocation, *it).isEmpty()) {
|
||||
_desktopFile = *it;
|
||||
LOG(("Found Unity Launcher entry %1!").arg(_desktopFile));
|
||||
useUnityCount = true;
|
||||
break;
|
||||
}
|
||||
if (!useUnityCount) {
|
||||
LOG(("Could not get Unity Launcher entry!"));
|
||||
}
|
||||
} else {
|
||||
LOG(("SNAP Environment detected, setting Launcher entry to %1_%2.desktop!")
|
||||
.arg(snapName)
|
||||
.arg(kLauncherBasename.utf16()));
|
||||
_desktopFile = snapName
|
||||
+ '_'
|
||||
+ kLauncherBasename.utf16();
|
||||
useUnityCount=true;
|
||||
}
|
||||
if (!useUnityCount) {
|
||||
LOG(("Could not get Unity Launcher entry!"));
|
||||
}
|
||||
_dbusPath = "/com/canonical/unity/launcherentry/" + QString::number(djbStringHash("application://" + _desktopFile));
|
||||
} else {
|
||||
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "platform/linux/notifications_manager_linux.h"
|
||||
|
||||
#include "platform/linux/specific_linux.h"
|
||||
#include "history/history.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "facades.h"
|
||||
@ -157,8 +158,7 @@ NotificationData::NotificationData(
|
||||
|
||||
_hints["category"] = qsl("im.received");
|
||||
|
||||
_hints["desktop-entry"] =
|
||||
qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME));
|
||||
_hints["desktop-entry"] = GetLauncherBasename();
|
||||
|
||||
_notificationInterface->connection().connect(
|
||||
kService.utf16(),
|
||||
|
@ -116,8 +116,7 @@ bool GenerateDesktopFile(const QString &targetPath, const QString &args) {
|
||||
DEBUG_LOG(("App Info: placing .desktop file to %1").arg(targetPath));
|
||||
if (!QDir(targetPath).exists()) QDir().mkpath(targetPath);
|
||||
|
||||
const auto targetFile = targetPath
|
||||
+ qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME) ".desktop");
|
||||
const auto targetFile = targetPath + GetLauncherFilename();
|
||||
|
||||
QString fileText;
|
||||
|
||||
@ -182,6 +181,11 @@ bool InSandbox() {
|
||||
return Sandbox;
|
||||
}
|
||||
|
||||
bool InSnap() {
|
||||
static const auto Snap = qEnvironmentVariableIsSet("SNAP");
|
||||
return Snap;
|
||||
}
|
||||
|
||||
QString CurrentExecutablePath(int argc, char *argv[]) {
|
||||
constexpr auto kMaxPath = 1024;
|
||||
char result[kMaxPath] = { 0 };
|
||||
@ -200,17 +204,15 @@ QString CurrentExecutablePath(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
QString SingleInstanceLocalServerName(const QString &hash) {
|
||||
const auto isSnap = !qgetenv("SNAP").isEmpty();
|
||||
|
||||
const auto runtimeDir = QStandardPaths::writableLocation(
|
||||
QStandardPaths::RuntimeLocation);
|
||||
|
||||
if (InSandbox()) {
|
||||
return runtimeDir
|
||||
+ qsl("/app/")
|
||||
+ QString::fromUtf8(qgetenv("FLATPAK_ID"))
|
||||
+ QString::fromLatin1(qgetenv("FLATPAK_ID"))
|
||||
+ '/' + hash;
|
||||
} else if (QFileInfo::exists(runtimeDir) && isSnap) {
|
||||
} else if (QFileInfo::exists(runtimeDir) && InSnap()) {
|
||||
return runtimeDir + '/' + hash;
|
||||
} else if (QFileInfo::exists(runtimeDir)) {
|
||||
return runtimeDir + '/' + hash + '-' + cGUIDStr();
|
||||
@ -220,6 +222,35 @@ QString SingleInstanceLocalServerName(const QString &hash) {
|
||||
}
|
||||
}
|
||||
|
||||
QString GetLauncherBasename() {
|
||||
static const auto LauncherBasename = [&] {
|
||||
QString launcherBasename;
|
||||
|
||||
if (InSnap()) {
|
||||
launcherBasename = qsl("%1_%2")
|
||||
.arg(QString::fromLatin1(qgetenv("SNAP_NAME")))
|
||||
.arg(qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME)));
|
||||
|
||||
LOG(("SNAP Environment detected, "
|
||||
"launcher filename is %1.desktop")
|
||||
.arg(launcherBasename));
|
||||
} else {
|
||||
launcherBasename =
|
||||
qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME));
|
||||
}
|
||||
|
||||
return launcherBasename;
|
||||
}();
|
||||
|
||||
return LauncherBasename;
|
||||
}
|
||||
|
||||
QString GetLauncherFilename() {
|
||||
static const auto LauncherFilename = GetLauncherBasename()
|
||||
+ qsl(".desktop");
|
||||
return LauncherFilename;
|
||||
}
|
||||
|
||||
} // namespace Platform
|
||||
|
||||
namespace {
|
||||
@ -379,8 +410,8 @@ void RegisterCustomScheme() {
|
||||
+ EscapeShell(QFile::encodeName(applicationsPath)));
|
||||
|
||||
RunShellCommand("xdg-mime default "
|
||||
MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME)
|
||||
".desktop x-scheme-handler/tg");
|
||||
+ GetLauncherFilename().toLatin1()
|
||||
+ " x-scheme-handler/tg");
|
||||
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
||||
}
|
||||
|
||||
@ -459,9 +490,7 @@ void psAutoStart(bool start, bool silent) {
|
||||
if (start) {
|
||||
GenerateDesktopFile(autostart, qsl("-autostart"));
|
||||
} else {
|
||||
QFile::remove(autostart
|
||||
+ qsl(MACRO_TO_STRING(TDESKTOP_LAUNCHER_BASENAME)
|
||||
".desktop"));
|
||||
QFile::remove(autostart + GetLauncherFilename());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,15 @@ inline void SetWatchingMediaKeys(bool watching) {
|
||||
}
|
||||
|
||||
bool InSandbox();
|
||||
bool InSnap();
|
||||
|
||||
QString CurrentExecutablePath(int argc, char *argv[]);
|
||||
|
||||
QString SingleInstanceLocalServerName(const QString &hash);
|
||||
|
||||
QString GetLauncherBasename();
|
||||
QString GetLauncherFilename();
|
||||
|
||||
inline std::optional<crl::time> LastUserInputTime() {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user