2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Use KSandbox to check flatpak/snap environment

This commit is contained in:
Ilya Fedin
2022-09-19 06:17:37 +04:00
committed by John Preston
parent 89879e355d
commit 5132fd5010
5 changed files with 16 additions and 31 deletions

View File

@@ -36,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtCore/QStandardPaths>
#include <QtCore/QProcess>
#include <KShell>
#include <KSandbox>
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include <glibmm.h>
@@ -264,22 +265,12 @@ void SetApplicationIcon(const QIcon &icon) {
QApplication::setWindowIcon(icon);
}
bool InFlatpak() {
static const auto Result = QFileInfo::exists(qsl("/.flatpak-info"));
return Result;
}
bool InSnap() {
static const auto Result = qEnvironmentVariableIsSet("SNAP");
return Result;
}
QString AppRuntimeDirectory() {
static const auto Result = [&] {
auto runtimeDir = QStandardPaths::writableLocation(
QStandardPaths::RuntimeLocation);
if (InFlatpak()) {
if (KSandbox::isFlatpak()) {
runtimeDir += qsl("/app/") + FlatpakID();
}
@@ -311,7 +302,7 @@ QString SingleInstanceLocalServerName(const QString &hash) {
}
QString GetIconName() {
static const auto Result = InFlatpak()
static const auto Result = KSandbox::isFlatpak()
? FlatpakID()
: kIconName.utf16();
return Result;
@@ -363,7 +354,7 @@ bool AutostartSupported() {
// in folders with names started with a dot
// and doesn't provide any api to add an app to autostart
// thus, autostart isn't supported in snap
return !InSnap();
return !KSandbox::isSnap();
}
void AutostartToggle(bool enabled, Fn<void(bool)> done) {
@@ -374,7 +365,7 @@ void AutostartToggle(bool enabled, Fn<void(bool)> done) {
});
const auto silent = !done;
if (InFlatpak()) {
if (KSandbox::isFlatpak()) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
PortalAutostart(enabled, silent);
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION

View File

@@ -15,9 +15,6 @@ class LocationPoint;
namespace Platform {
bool InFlatpak();
bool InSnap();
QString AppRuntimeDirectory();
QString GetIconName();