Skip to content

Commit

Permalink
Check autostart enabling success on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Jan 2, 2023
1 parent 2afa2cd commit c56977c
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions Telegram/SourceFiles/platform/linux/specific_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ namespace {
constexpr auto kDesktopFile = ":/misc/org.telegram.desktop.desktop"_cs;

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
void PortalAutostart(bool start, bool silent) {
bool PortalAutostart(bool start, bool silent) {
if (cExeName().isEmpty()) {
return;
return false;
}

auto error = false;

try {
const auto connection = Gio::DBus::Connection::get_sync(
Gio::DBus::BusType::SESSION);
Expand Down Expand Up @@ -182,14 +184,18 @@ void PortalAutostart(bool start, bool silent) {
const auto response = base::Platform::GlibVariantCast<
uint>(parameters.get_child(0));

if (response && !silent) {
LOG(("Portal Autostart Error: Request denied"));
if (response) {
if (!silent) {
LOG(("Portal Autostart Error: Request denied"));
}
error = true;
}
} catch (const std::exception &e) {
if (!silent) {
LOG(("Portal Autostart Error: %1").arg(
QString::fromStdString(e.what())));
}
error = true;
}

loop->quit();
Expand Down Expand Up @@ -227,7 +233,10 @@ void PortalAutostart(bool start, bool silent) {
LOG(("Portal Autostart Error: %1").arg(
QString::fromStdString(e.what())));
}
error = true;
}

return !error;
}

void LaunchGApplication() {
Expand Down Expand Up @@ -620,25 +629,31 @@ bool AutostartSupported() {

void AutostartToggle(bool enabled, Fn<void(bool)> done) {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
const auto guard = gsl::finally([&] {
if (done) {
done(enabled);
const auto success = [&] {
const auto silent = !done;

if (KSandbox::isFlatpak()) {
return PortalAutostart(enabled, silent);
}
});

const auto silent = !done;
if (KSandbox::isFlatpak()) {
PortalAutostart(enabled, silent);
} else {
const auto autostart = QStandardPaths::writableLocation(
QStandardPaths::GenericConfigLocation)
+ u"/autostart/"_q;

if (enabled) {
GenerateDesktopFile(autostart, { u"-autostart"_q }, true, silent);
} else {
QFile::remove(autostart + QGuiApplication::desktopFileName());
if (!enabled) {
return QFile::remove(
autostart + QGuiApplication::desktopFileName());
}

return GenerateDesktopFile(
autostart,
{ u"-autostart"_q },
true,
silent);
}();

if (done) {
done(enabled && success);
}
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
}
Expand Down

0 comments on commit c56977c

Please sign in to comment.