Implement autostart in snap

This commit is contained in:
Ilya Fedin 2022-11-19 05:12:41 +04:00 committed by John Preston
parent 4aa9c1fea3
commit ecd217a79f
2 changed files with 16 additions and 6 deletions

View File

@ -416,6 +416,7 @@ void LaunchGApplication() {
bool GenerateDesktopFile( bool GenerateDesktopFile(
const QString &targetPath, const QString &targetPath,
const QStringList &args = {}, const QStringList &args = {},
bool onlyMainGroup = false,
bool silent = false) { bool silent = false) {
if (targetPath.isEmpty() || cExeName().isEmpty()) { if (targetPath.isEmpty() || cExeName().isEmpty()) {
return false; return false;
@ -450,6 +451,11 @@ bool GenerateDesktopFile(
| Glib::KeyFile::Flags::KEEP_TRANSLATIONS); | Glib::KeyFile::Flags::KEEP_TRANSLATIONS);
for (const auto &group : target->get_groups()) { for (const auto &group : target->get_groups()) {
if (onlyMainGroup && group != "Desktop Entry") {
target->remove_group(group);
continue;
}
if (target->has_key(group, "TryExec")) { if (target->has_key(group, "TryExec")) {
target->set_string( target->set_string(
group, group,
@ -507,6 +513,13 @@ bool GenerateDesktopFile(
return false; return false;
} }
QFile::setPermissions(
targetFile,
QFile::permissions(targetFile)
| QFileDevice::ExeOwner
| QFileDevice::ExeGroup
| QFileDevice::ExeOther);
if (!Core::UpdaterDisabled()) { if (!Core::UpdaterDisabled()) {
DEBUG_LOG(("App Info: removing old .desktop files")); DEBUG_LOG(("App Info: removing old .desktop files"));
QFile::remove(u"%1telegram.desktop"_q.arg(targetPath)); QFile::remove(u"%1telegram.desktop"_q.arg(targetPath));
@ -598,11 +611,7 @@ std::optional<bool> IsDarkMode() {
bool AutostartSupported() { bool AutostartSupported() {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
// snap sandbox doesn't allow creating files return true;
// 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();
#else // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION #else // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
return false; return false;
#endif // DESKTOP_APP_DISABLE_DBUS_INTEGRATION #endif // DESKTOP_APP_DISABLE_DBUS_INTEGRATION
@ -625,7 +634,7 @@ void AutostartToggle(bool enabled, Fn<void(bool)> done) {
+ u"/autostart/"_q; + u"/autostart/"_q;
if (enabled) { if (enabled) {
GenerateDesktopFile(autostart, { u"-autostart"_q }, silent); GenerateDesktopFile(autostart, { u"-autostart"_q }, true, silent);
} else { } else {
QFile::remove(autostart + QGuiApplication::desktopFileName()); QFile::remove(autostart + QGuiApplication::desktopFileName());
} }

View File

@ -20,6 +20,7 @@ apps:
- bin/desktop-launch - bin/desktop-launch
common-id: org.telegram.desktop common-id: org.telegram.desktop
desktop: usr/share/applications/org.telegram.desktop.desktop desktop: usr/share/applications/org.telegram.desktop.desktop
autostart: telegram-desktop_telegram-desktop.desktop
environment: environment:
# Tell glib to use portals on file associations handling. # Tell glib to use portals on file associations handling.
GTK_USE_PORTAL: 1 GTK_USE_PORTAL: 1