2017-12-11 18:45:29 +04:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-12-11 18:45:29 +04:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-12-11 18:45:29 +04:00
|
|
|
*/
|
|
|
|
#include "platform/linux/launcher_linux.h"
|
|
|
|
|
2017-12-12 11:52:53 +04:00
|
|
|
#include "core/crash_reports.h"
|
2018-07-12 01:14:44 +03:00
|
|
|
#include "core/update_checker.h"
|
2023-03-19 21:13:56 +04:00
|
|
|
#include "webview/platform/linux/webview_linux_webkitgtk.h"
|
2017-12-12 11:52:53 +04:00
|
|
|
|
2020-10-28 18:15:43 +04:00
|
|
|
#include <QtWidgets/QApplication>
|
2023-08-14 04:57:05 +04:00
|
|
|
#include <glib/glib.hpp>
|
2020-10-28 18:15:43 +04:00
|
|
|
|
2023-08-14 04:57:05 +04:00
|
|
|
using namespace gi::repository;
|
2017-12-12 11:52:53 +04:00
|
|
|
|
2017-12-11 18:45:29 +04:00
|
|
|
namespace Platform {
|
2017-12-12 11:52:53 +04:00
|
|
|
|
2018-06-03 22:52:23 +03:00
|
|
|
Launcher::Launcher(int argc, char *argv[])
|
2023-06-13 06:03:19 +04:00
|
|
|
: Core::Launcher(argc, argv) {
|
2021-06-23 03:20:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int Launcher::exec() {
|
2023-06-13 06:03:19 +04:00
|
|
|
for (auto i = arguments().begin(), e = arguments().end(); i != e; ++i) {
|
|
|
|
if (*i == u"-webviewhelper"_q && std::distance(i, e) > 1) {
|
|
|
|
Webview::WebKitGTK::SetSocketPath((i + 1)->toStdString());
|
2023-03-19 21:13:56 +04:00
|
|
|
return Webview::WebKitGTK::Exec();
|
2021-06-23 03:20:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Core::Launcher::exec();
|
2018-06-03 22:52:23 +03:00
|
|
|
}
|
|
|
|
|
2020-10-28 18:15:43 +04:00
|
|
|
void Launcher::initHook() {
|
2020-12-18 12:43:51 +04:00
|
|
|
QApplication::setAttribute(Qt::AA_DisableSessionManager, true);
|
2020-10-28 18:15:43 +04:00
|
|
|
}
|
|
|
|
|
2017-12-12 11:52:53 +04:00
|
|
|
bool Launcher::launchUpdater(UpdaterLaunch action) {
|
|
|
|
if (cExeName().isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-16 00:01:45 +04:00
|
|
|
const auto justRelaunch = action == UpdaterLaunch::JustRelaunch;
|
|
|
|
|
|
|
|
const auto binaryPath = justRelaunch
|
2023-08-14 04:57:05 +04:00
|
|
|
? (cExeDir() + cExeName()).toStdString()
|
|
|
|
: (cWriteProtected()
|
2022-11-30 00:46:36 +03:00
|
|
|
? (cWorkingDir() + u"tupdates/temp/Updater"_q)
|
2023-08-14 04:57:05 +04:00
|
|
|
: (cExeDir() + u"Updater"_q)).toStdString();
|
2017-12-12 11:52:53 +04:00
|
|
|
|
2023-08-14 04:57:05 +04:00
|
|
|
std::vector<std::string> argumentsList;
|
2023-08-14 15:42:07 +04:00
|
|
|
if (justRelaunch) {
|
2023-08-14 08:45:09 +04:00
|
|
|
argumentsList.push_back(binaryPath);
|
2023-08-14 15:42:07 +04:00
|
|
|
} else if (cWriteProtected()) {
|
|
|
|
argumentsList.push_back("pkexec");
|
2023-08-14 08:45:09 +04:00
|
|
|
}
|
2023-08-14 04:57:05 +04:00
|
|
|
argumentsList.push_back((justRelaunch && !arguments().isEmpty())
|
|
|
|
? arguments().first().toStdString()
|
2023-06-16 00:01:45 +04:00
|
|
|
: binaryPath);
|
2017-12-12 11:52:53 +04:00
|
|
|
|
2018-06-05 16:32:26 +03:00
|
|
|
if (Logs::DebugEnabled()) {
|
2023-08-14 04:57:05 +04:00
|
|
|
argumentsList.push_back("-debug");
|
2017-12-12 11:52:53 +04:00
|
|
|
}
|
|
|
|
|
2023-06-16 00:01:45 +04:00
|
|
|
if (justRelaunch) {
|
2023-08-14 15:42:07 +04:00
|
|
|
if (cLaunchMode() == LaunchModeAutoStart) {
|
|
|
|
argumentsList.push_back("-autostart");
|
|
|
|
}
|
|
|
|
if (cStartInTray()) {
|
|
|
|
argumentsList.push_back("-startintray");
|
|
|
|
}
|
|
|
|
if (cDataFile() != u"data"_q) {
|
|
|
|
argumentsList.push_back("-key");
|
|
|
|
argumentsList.push_back(cDataFile().toStdString());
|
|
|
|
}
|
2023-08-14 04:57:05 +04:00
|
|
|
argumentsList.push_back("-noupdate");
|
|
|
|
argumentsList.push_back("-tosettings");
|
2017-12-12 11:52:53 +04:00
|
|
|
if (customWorkingDir()) {
|
2023-08-14 04:57:05 +04:00
|
|
|
argumentsList.push_back("-workdir");
|
|
|
|
argumentsList.push_back(cWorkingDir().toStdString());
|
2017-12-12 11:52:53 +04:00
|
|
|
}
|
|
|
|
} else {
|
2023-08-14 04:57:05 +04:00
|
|
|
argumentsList.push_back("-workpath");
|
|
|
|
argumentsList.push_back(cWorkingDir().toStdString());
|
|
|
|
argumentsList.push_back("-exename");
|
|
|
|
argumentsList.push_back(cExeName().toStdString());
|
|
|
|
argumentsList.push_back("-exepath");
|
|
|
|
argumentsList.push_back(cExeDir().toStdString());
|
2021-04-27 16:16:20 +04:00
|
|
|
if (cWriteProtected()) {
|
2023-08-14 04:57:05 +04:00
|
|
|
argumentsList.push_back("-writeprotected");
|
2021-04-27 16:16:20 +04:00
|
|
|
}
|
2017-12-12 11:52:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Logs::closeMain();
|
|
|
|
CrashReports::Finish();
|
|
|
|
|
2023-08-14 15:42:07 +04:00
|
|
|
if (justRelaunch) {
|
|
|
|
return GLib::spawn_async(
|
|
|
|
initialWorkingDir().toStdString(),
|
|
|
|
argumentsList,
|
|
|
|
std::nullopt,
|
|
|
|
GLib::SpawnFlags::FILE_AND_ARGV_ZERO_,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
} else {
|
2023-08-14 04:57:05 +04:00
|
|
|
if (!GLib::spawn_sync(
|
|
|
|
argumentsList,
|
|
|
|
std::nullopt,
|
2023-08-14 15:42:07 +04:00
|
|
|
// if the spawn is sync, working directory is not set
|
|
|
|
// and GLib::SpawnFlags::LEAVE_DESCRIPTORS_OPEN_ is set,
|
|
|
|
// it goes through an optimized code path
|
|
|
|
GLib::SpawnFlags::SEARCH_PATH_
|
|
|
|
| GLib::SpawnFlags::LEAVE_DESCRIPTORS_OPEN_,
|
2023-08-14 04:57:05 +04:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr)) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-03 14:21:17 +04:00
|
|
|
return launchUpdater(UpdaterLaunch::JustRelaunch);
|
2021-04-27 16:16:20 +04:00
|
|
|
}
|
2017-12-11 18:45:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|