Use customWorkingDir() outside of Core::Launcher

This allows to add -workdir to shortcuts only if the process was launched with -workdir
This commit is contained in:
Ilya Fedin 2022-11-21 08:38:14 +04:00 committed by John Preston
parent 9b66b76bac
commit 2f0d14bd35
7 changed files with 48 additions and 15 deletions

View file

@ -1446,7 +1446,9 @@ void Application::startShortcuts() {
void Application::RegisterUrlScheme() {
base::Platform::RegisterUrlScheme(base::Platform::UrlSchemeDescriptor{
.executable = cExeDir() + cExeName(),
.arguments = qsl("-workdir \"%1\"").arg(cWorkingDir()),
.arguments = Sandbox::Instance().customWorkingDir()
? qsl("-workdir \"%1\"").arg(cWorkingDir())
: QString(),
.protocol = qsl("tg"),
.protocolName = qsl("Telegram Link"),
.shortAppName = qsl("tdesktop"),

View file

@ -511,6 +511,10 @@ void Sandbox::refreshGlobalProxy() {
}
}
bool Sandbox::customWorkingDir() const {
return _launcher->customWorkingDir();
}
uint64 Sandbox::installationTag() const {
return _launcher->installationTag();
}

View file

@ -41,6 +41,7 @@ public:
int start();
void refreshGlobalProxy();
bool customWorkingDir() const;
uint64 installationTag() const;
void postponeCall(FnMut<void()> &&callable);

View file

@ -24,6 +24,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Platform {
namespace {
Launcher *LauncherInstance = nullptr;
class Arguments {
public:
void push(QByteArray argument) {
@ -48,6 +50,15 @@ private:
Launcher::Launcher(int argc, char *argv[])
: Core::Launcher(argc, argv)
, _arguments(argv, argv + argc) {
Expects(LauncherInstance == nullptr);
LauncherInstance = this;
}
Launcher &Launcher::Instance() {
Expects(LauncherInstance != nullptr);
return *LauncherInstance;
}
int Launcher::exec() {

View file

@ -15,6 +15,8 @@ class Launcher : public Core::Launcher {
public:
Launcher(int argc, char *argv[]);
static Launcher &Instance();
int exec() override;
private:

View file

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h"
#include "platform/linux/linux_desktop_environment.h"
#include "platform/linux/linux_wayland_integration.h"
#include "platform/platform_launcher.h"
#include "lang/lang_keys.h"
#include "mainwindow.h"
#include "storage/localstorage.h"
@ -139,20 +140,21 @@ void PortalAutostart(bool start, bool silent) {
const auto handleToken = Glib::ustring("tdesktop")
+ std::to_string(base::RandomValue<uint>());
std::vector<Glib::ustring> commandline;
commandline.push_back(cExeName().toStdString());
if (Core::Sandbox::Instance().customWorkingDir()) {
commandline.push_back("-workdir");
commandline.push_back(cWorkingDir().toStdString());
}
commandline.push_back("-autostart");
std::map<Glib::ustring, Glib::VariantBase> options;
options["handle_token"] = Glib::Variant<Glib::ustring>::create(
handleToken);
options["reason"] = Glib::Variant<Glib::ustring>::create(
tr::lng_settings_auto_start(tr::now).toStdString());
options["autostart"] = Glib::Variant<bool>::create(start);
options["commandline"] = Glib::Variant<std::vector<
Glib::ustring
>>::create({
cExeName().toStdString(),
"-workdir",
cWorkingDir().toStdString(),
"-autostart",
});
options["commandline"] = base::Platform::MakeGlibVariant(commandline);
options["dbus-activatable"] = Glib::Variant<bool>::create(false);
auto uniqueName = connection->get_unique_name();
@ -443,11 +445,11 @@ bool GenerateDesktopFile(
qsl("^Exec=telegram-desktop(.*)$"),
QRegularExpression::MultilineOption),
qsl("Exec=%1\\1").arg(
KShell::joinArgs({
KShell::joinArgs(QStringList{
cExeDir() + cExeName(),
"-workdir",
cWorkingDir(),
}).replace('\\', "\\\\")));
} + (Core::Sandbox::Instance().customWorkingDir()
? QStringList{ "-workdir", cWorkingDir() }
: QStringList{})).replace('\\', "\\\\")));
fileText = fileText.replace(
QRegularExpression(
@ -661,7 +663,18 @@ void start() {
}
if (!Core::UpdaterDisabled()) {
return qsl("org.telegram.desktop.%1.desktop").arg(h);
QByteArray md5Hash(h);
if (!Launcher::Instance().customWorkingDir()) {
const auto exePath = QFile::encodeName(
cExeDir() + cExeName());
hashMd5Hex(
exePath.constData(),
exePath.size(),
md5Hash.data());
}
return qsl("org.telegram.desktop.%1.desktop").arg(md5Hash);
}
return qsl("org.telegram.desktop.desktop");

@ -1 +1 @@
Subproject commit d3f9e826197c6ed42f8ef2d021d8eb74b2d390cc
Subproject commit e1e4c68c91b2a56fd4d61cd843bb3bb5d4d99498