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(
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<bool> 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<void(bool)> 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());
}

View file

@ -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