From 2be4641496f6f5efc7c18c2842ad00ddf51be43c Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 13 Jan 2023 17:58:36 +0400 Subject: [PATCH] Install launcher on every launch on Linux Just like AppUserModelId on Windows This makes the cheat code and having the function outside of private namespace unnecessary --- Telegram/SourceFiles/core/application.cpp | 1 - .../platform/linux/specific_linux.cpp | 72 ++++++++----------- .../SourceFiles/platform/mac/specific_mac.h | 3 - .../SourceFiles/platform/platform_specific.h | 1 - .../SourceFiles/platform/win/specific_win.h | 3 - .../SourceFiles/settings/settings_codes.cpp | 5 -- 6 files changed, 31 insertions(+), 54 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 25124779f..f3e99cd8f 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -240,7 +240,6 @@ void Application::run() { refreshGlobalProxy(); // Depends on app settings being read. if (const auto old = Local::oldSettingsVersion(); old < AppVersion) { - Platform::InstallLauncher(); InvokeQueued(this, [] { RegisterUrlScheme(); }); Platform::NewVersionLaunched(old); } diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index f2ec86a46..6eba0dabb 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -519,6 +519,36 @@ bool GenerateDesktopFile( return true; } + +void InstallLauncher() { + static const auto DisabledByEnv = !qEnvironmentVariableIsEmpty( + "DESKTOPINTEGRATION"); + + // don't update desktop file for alpha version or if updater is disabled + if (cAlphaVersion() || Core::UpdaterDisabled() || DisabledByEnv) { + return; + } + + const auto applicationsPath = QStandardPaths::writableLocation( + QStandardPaths::ApplicationsLocation) + '/'; + + GenerateDesktopFile(applicationsPath); + + const auto icons = QStandardPaths::writableLocation( + QStandardPaths::GenericDataLocation) + u"/icons/"_q; + + if (!QDir(icons).exists()) QDir().mkpath(icons); + + const auto icon = icons + base::IconName() + u".png"_q; + QFile::remove(icon); + if (QFile::copy(u":/gui/art/logo_256.png"_q, icon)) { + DEBUG_LOG(("App Info: Icon copied to '%1'").arg(icon)); + } + + QProcess::execute("update-desktop-database", { + applicationsPath + }); +} #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION } // namespace @@ -753,47 +783,6 @@ void start() { void finish() { } -void InstallLauncher(bool force) { -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION - static const auto DisabledByEnv = !qEnvironmentVariableIsEmpty( - "DESKTOPINTEGRATION"); - - // don't update desktop file for alpha version or if updater is disabled - if ((cAlphaVersion() || Core::UpdaterDisabled() || DisabledByEnv) - && !force) { - return; - } - - const auto applicationsPath = QStandardPaths::writableLocation( - QStandardPaths::ApplicationsLocation) + '/'; - - GenerateDesktopFile(applicationsPath); - - const auto icons = QStandardPaths::writableLocation( - QStandardPaths::GenericDataLocation) + u"/icons/"_q; - - if (!QDir(icons).exists()) QDir().mkpath(icons); - - const auto icon = icons + base::IconName() + u".png"_q; - auto iconExists = QFile::exists(icon); - if (Local::oldSettingsVersion() < 2008012 && iconExists) { - // Icon was changed. - if (QFile::remove(icon)) { - iconExists = false; - } - } - if (!iconExists) { - if (QFile::copy(u":/gui/art/logo_256.png"_q, icon)) { - DEBUG_LOG(("App Info: Icon copied to '%1'").arg(icon)); - } - } - - QProcess::execute("update-desktop-database", { - applicationsPath - }); -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION -} - PermissionStatus GetPermissionStatus(PermissionType type) { return PermissionStatus::Granted; } @@ -871,6 +860,7 @@ void start() { LOG(("Fallback icon theme: %1").arg(QIcon::fallbackThemeName())); #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION + InstallLauncher(); LaunchGApplication(); #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION } diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.h b/Telegram/SourceFiles/platform/mac/specific_mac.h index e2ed5addc..142f4fa57 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.h +++ b/Telegram/SourceFiles/platform/mac/specific_mac.h @@ -33,9 +33,6 @@ inline bool SkipTaskbarSupported() { return false; } -inline void InstallLauncher(bool force) { -} - void ActivateThisProcess(); inline uint64 ActivationWindowId(not_null window) { diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index dc863b179..e36f64e38 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -42,7 +42,6 @@ bool TrayIconSupported(); bool SkipTaskbarSupported(); void WriteCrashDumpDetails(); void NewVersionLaunched(int oldVersion); -void InstallLauncher(bool force = false); [[nodiscard]] std::optional IsDarkMode(); [[nodiscard]] inline bool IsDarkModeSupported() { diff --git a/Telegram/SourceFiles/platform/win/specific_win.h b/Telegram/SourceFiles/platform/win/specific_win.h index 6859a345b..e2a8c1cdf 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.h +++ b/Telegram/SourceFiles/platform/win/specific_win.h @@ -27,9 +27,6 @@ inline bool SkipTaskbarSupported() { return true; } -inline void InstallLauncher(bool force) { -} - inline void ActivateThisProcess() { } diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index 47d49ab30..62fba5c96 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "settings/settings_codes.h" -#include "platform/platform_specific.h" #include "ui/toast/toast.h" #include "mainwidget.h" #include "mainwindow.h" @@ -180,10 +179,6 @@ auto GenerateCodes() { Core::Application::RegisterUrlScheme(); Ui::Toast::Show("Forced custom scheme register."); }); - codes.emplace(u"installlauncher"_q, [](SessionController *window) { - Platform::InstallLauncher(true); - Ui::Toast::Show("Forced launcher installation."); - }); #if defined Q_OS_WIN || defined Q_OS_MAC codes.emplace(u"freetype"_q, [](SessionController *window) {