From ecd217a79fcbfb1ce9ffcc3117f9145dcaffe52d Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 19 Nov 2022 05:12:41 +0400 Subject: [PATCH] Implement autostart in snap --- .../platform/linux/specific_linux.cpp | 21 +++++++++++++------ snap/snapcraft.yaml | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 0a6f400cd3..b1f1f8884c 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -416,6 +416,7 @@ void LaunchGApplication() { bool GenerateDesktopFile( const QString &targetPath, const QStringList &args = {}, + bool onlyMainGroup = false, bool silent = false) { if (targetPath.isEmpty() || cExeName().isEmpty()) { return false; @@ -450,6 +451,11 @@ bool GenerateDesktopFile( | Glib::KeyFile::Flags::KEEP_TRANSLATIONS); for (const auto &group : target->get_groups()) { + if (onlyMainGroup && group != "Desktop Entry") { + target->remove_group(group); + continue; + } + if (target->has_key(group, "TryExec")) { target->set_string( group, @@ -507,6 +513,13 @@ bool GenerateDesktopFile( return false; } + QFile::setPermissions( + targetFile, + QFile::permissions(targetFile) + | QFileDevice::ExeOwner + | QFileDevice::ExeGroup + | QFileDevice::ExeOther); + if (!Core::UpdaterDisabled()) { DEBUG_LOG(("App Info: removing old .desktop files")); QFile::remove(u"%1telegram.desktop"_q.arg(targetPath)); @@ -598,11 +611,7 @@ std::optional IsDarkMode() { bool AutostartSupported() { #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION - // snap sandbox doesn't allow creating files - // 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 !KSandbox::isSnap(); + return true; #else // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION return false; #endif // DESKTOP_APP_DISABLE_DBUS_INTEGRATION @@ -625,7 +634,7 @@ void AutostartToggle(bool enabled, Fn done) { + u"/autostart/"_q; if (enabled) { - GenerateDesktopFile(autostart, { u"-autostart"_q }, silent); + GenerateDesktopFile(autostart, { u"-autostart"_q }, true, silent); } else { QFile::remove(autostart + QGuiApplication::desktopFileName()); } diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 688de85b6d..6d5fa22b53 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -20,6 +20,7 @@ apps: - bin/desktop-launch common-id: org.telegram.desktop desktop: usr/share/applications/org.telegram.desktop.desktop + autostart: telegram-desktop_telegram-desktop.desktop environment: # Tell glib to use portals on file associations handling. GTK_USE_PORTAL: 1