From c56977cbc1ac6a1935eaeb6cdae6ab35125f8603 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 2 Jan 2023 12:50:33 +0400 Subject: [PATCH] Check autostart enabling success on Linux --- .../platform/linux/specific_linux.cpp | 49 ++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 1638e83c7..980bdcd43 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -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); @@ -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(); @@ -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() { @@ -620,25 +629,31 @@ bool AutostartSupported() { void AutostartToggle(bool enabled, Fn 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 }