From 1d234ea9908151872b842082c6b0cf6088b5a8e6 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 16 Jun 2023 00:15:23 +0400 Subject: [PATCH] Use argv0 for shortcuts when updater is disabled --- Telegram/SourceFiles/core/application.cpp | 4 +-- .../platform/linux/specific_linux.cpp | 29 ++++++++++++------- .../SourceFiles/platform/mac/specific_mac.h | 4 +++ .../SourceFiles/platform/platform_specific.h | 3 +- .../SourceFiles/platform/win/specific_win.h | 4 +++ 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 533ad5c77..4fb01d12b 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -1762,9 +1762,7 @@ void Application::startShortcuts() { void Application::RegisterUrlScheme() { base::Platform::RegisterUrlScheme(base::Platform::UrlSchemeDescriptor{ - .executable = (!Platform::IsLinux() || !Core::UpdaterDisabled()) - ? (cExeDir() + cExeName()) - : cExeName(), + .executable = Platform::ExecutablePathForShortcuts(), .arguments = Launcher::Instance().customWorkingDir() ? u"-workdir \"%1\""_q.arg(cWorkingDir()) : QString(), diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 5ecf4229a..64b6b0ff0 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -191,6 +191,7 @@ bool GenerateDesktopFile( const auto sourceFile = kDesktopFile.utf16(); const auto targetFile = targetPath + QGuiApplication::desktopFileName(); + const auto executable = ExecutablePathForShortcuts(); const auto sourceText = [&] { QFile source(sourceFile); @@ -224,11 +225,7 @@ bool GenerateDesktopFile( target->set_string( group, "TryExec", - KShell::joinArgs({ - !Core::UpdaterDisabled() - ? (cExeDir() + cExeName()) - : cExeName() - }).replace( + KShell::joinArgs({ executable }).replace( '\\', qstr("\\\\")).toStdString()); } @@ -236,9 +233,7 @@ bool GenerateDesktopFile( if (target->has_key(group, "Exec")) { if (group == "Desktop Entry" && !args.isEmpty()) { QStringList exec; - exec.append(!Core::UpdaterDisabled() - ? (cExeDir() + cExeName()) - : cExeName()); + exec.append(executable); if (Core::Launcher::Instance().customWorkingDir()) { exec.append(u"-workdir"_q); exec.append(cWorkingDir()); @@ -259,9 +254,7 @@ bool GenerateDesktopFile( qstr("\\"))); if (!exec.isEmpty()) { - exec[0] = !Core::UpdaterDisabled() - ? (cExeDir() + cExeName()) - : cExeName(); + exec[0] = executable; if (Core::Launcher::Instance().customWorkingDir()) { exec.insert(1, u"-workdir"_q); exec.insert(2, cWorkingDir()); @@ -451,6 +444,20 @@ bool SkipTaskbarSupported() { return false; } +QString ExecutablePathForShortcuts() { + if (Core::UpdaterDisabled()) { + const auto &arguments = Core::Launcher::Instance().arguments(); + if (!arguments.isEmpty()) { + const auto result = QFileInfo(arguments.first()).fileName(); + if (!result.isEmpty()) { + return result; + } + } + return cExeName(); + } + return cExeDir() + cExeName(); +} + } // namespace Platform QString psAppDataPath() { diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.h b/Telegram/SourceFiles/platform/mac/specific_mac.h index fb63752c1..12cc59024 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.h +++ b/Telegram/SourceFiles/platform/mac/specific_mac.h @@ -40,6 +40,10 @@ inline uint64 ActivationWindowId(not_null window) { inline void ActivateOtherProcess(uint64 processId, uint64 windowId) { } +inline QString ExecutablePathForShortcuts() { + return cExeDir() + cExeName(); +} + namespace ThirdParty { inline void start() { diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index 2056b8c87..604676615 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -46,10 +46,9 @@ bool TrayIconSupported(); bool SkipTaskbarSupported(); void WriteCrashDumpDetails(); void NewVersionLaunched(int oldVersion); - [[nodiscard]] QImage DefaultApplicationIcon(); - [[nodiscard]] bool PreventsQuit(Core::QuitReason reason); +[[nodiscard]] QString ExecutablePathForShortcuts(); #if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) [[nodiscard]] std::optional IsDarkMode(); diff --git a/Telegram/SourceFiles/platform/win/specific_win.h b/Telegram/SourceFiles/platform/win/specific_win.h index db10b458e..0b0945dd5 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.h +++ b/Telegram/SourceFiles/platform/win/specific_win.h @@ -42,6 +42,10 @@ void SetWindowPriority(not_null window, uint32 priority); // Activate window with windowId (if found) or the largest priority. void ActivateOtherProcess(uint64 processId, uint64 windowId); +inline QString ExecutablePathForShortcuts() { + return cExeDir() + cExeName(); +} + namespace ThirdParty { void start();