mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Fix single instance socket path for compatibility with flatpak
This commit is contained in:
@@ -95,6 +95,13 @@ void SetApplicationIcon(const QIcon &icon) {
|
||||
QApplication::setWindowIcon(icon);
|
||||
}
|
||||
|
||||
bool InSandbox() {
|
||||
static const auto Sandbox = QFileInfo::exists(
|
||||
QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation)
|
||||
+ qsl("/flatpak-info"));
|
||||
return Sandbox;
|
||||
}
|
||||
|
||||
QString CurrentExecutablePath(int argc, char *argv[]) {
|
||||
constexpr auto kMaxPath = 1024;
|
||||
char result[kMaxPath] = { 0 };
|
||||
@@ -112,6 +119,23 @@ QString CurrentExecutablePath(int argc, char *argv[]) {
|
||||
return argc ? QFile::decodeName(argv[0]) : QString();
|
||||
}
|
||||
|
||||
QString SingleInstanceLocalServerName(const QString &hash) {
|
||||
const auto runtimeDir = QStandardPaths::writableLocation(
|
||||
QStandardPaths::RuntimeLocation);
|
||||
|
||||
if (InSandbox()) {
|
||||
return runtimeDir
|
||||
+ qsl("/app/")
|
||||
+ QString::fromUtf8(qgetenv("FLATPAK_ID"))
|
||||
+ '/' + hash;
|
||||
} else if (QFileInfo::exists(runtimeDir)) {
|
||||
return runtimeDir + '/' + hash + '-' + cGUIDStr();
|
||||
} else { // non-systemd distros
|
||||
return QStandardPaths::writableLocation(QStandardPaths::TempLocation)
|
||||
+ '/' + hash + '-' + cGUIDStr();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Platform
|
||||
|
||||
namespace {
|
||||
|
@@ -20,8 +20,12 @@ namespace Platform {
|
||||
inline void SetWatchingMediaKeys(bool watching) {
|
||||
}
|
||||
|
||||
bool InSandbox();
|
||||
|
||||
QString CurrentExecutablePath(int argc, char *argv[]);
|
||||
|
||||
QString SingleInstanceLocalServerName(const QString &hash);
|
||||
|
||||
inline std::optional<crl::time> LastUserInputTime() {
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -31,9 +35,6 @@ inline void IgnoreApplicationActivationRightNow() {
|
||||
|
||||
} // namespace Platform
|
||||
|
||||
inline QString psServerPrefix() {
|
||||
return qsl("/tmp/");
|
||||
}
|
||||
inline void psCheckLocalSocket(const QString &serverName) {
|
||||
QFile address(serverName);
|
||||
if (address.exists()) {
|
||||
|
Reference in New Issue
Block a user