mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
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:
parent
9b66b76bac
commit
2f0d14bd35
7 changed files with 48 additions and 15 deletions
|
@ -1446,7 +1446,9 @@ void Application::startShortcuts() {
|
||||||
void Application::RegisterUrlScheme() {
|
void Application::RegisterUrlScheme() {
|
||||||
base::Platform::RegisterUrlScheme(base::Platform::UrlSchemeDescriptor{
|
base::Platform::RegisterUrlScheme(base::Platform::UrlSchemeDescriptor{
|
||||||
.executable = cExeDir() + cExeName(),
|
.executable = cExeDir() + cExeName(),
|
||||||
.arguments = qsl("-workdir \"%1\"").arg(cWorkingDir()),
|
.arguments = Sandbox::Instance().customWorkingDir()
|
||||||
|
? qsl("-workdir \"%1\"").arg(cWorkingDir())
|
||||||
|
: QString(),
|
||||||
.protocol = qsl("tg"),
|
.protocol = qsl("tg"),
|
||||||
.protocolName = qsl("Telegram Link"),
|
.protocolName = qsl("Telegram Link"),
|
||||||
.shortAppName = qsl("tdesktop"),
|
.shortAppName = qsl("tdesktop"),
|
||||||
|
|
|
@ -511,6 +511,10 @@ void Sandbox::refreshGlobalProxy() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Sandbox::customWorkingDir() const {
|
||||||
|
return _launcher->customWorkingDir();
|
||||||
|
}
|
||||||
|
|
||||||
uint64 Sandbox::installationTag() const {
|
uint64 Sandbox::installationTag() const {
|
||||||
return _launcher->installationTag();
|
return _launcher->installationTag();
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
int start();
|
int start();
|
||||||
|
|
||||||
void refreshGlobalProxy();
|
void refreshGlobalProxy();
|
||||||
|
bool customWorkingDir() const;
|
||||||
uint64 installationTag() const;
|
uint64 installationTag() const;
|
||||||
|
|
||||||
void postponeCall(FnMut<void()> &&callable);
|
void postponeCall(FnMut<void()> &&callable);
|
||||||
|
|
|
@ -24,6 +24,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
Launcher *LauncherInstance = nullptr;
|
||||||
|
|
||||||
class Arguments {
|
class Arguments {
|
||||||
public:
|
public:
|
||||||
void push(QByteArray argument) {
|
void push(QByteArray argument) {
|
||||||
|
@ -48,6 +50,15 @@ private:
|
||||||
Launcher::Launcher(int argc, char *argv[])
|
Launcher::Launcher(int argc, char *argv[])
|
||||||
: Core::Launcher(argc, argv)
|
: Core::Launcher(argc, argv)
|
||||||
, _arguments(argv, argv + argc) {
|
, _arguments(argv, argv + argc) {
|
||||||
|
Expects(LauncherInstance == nullptr);
|
||||||
|
|
||||||
|
LauncherInstance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Launcher &Launcher::Instance() {
|
||||||
|
Expects(LauncherInstance != nullptr);
|
||||||
|
|
||||||
|
return *LauncherInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Launcher::exec() {
|
int Launcher::exec() {
|
||||||
|
|
|
@ -15,6 +15,8 @@ class Launcher : public Core::Launcher {
|
||||||
public:
|
public:
|
||||||
Launcher(int argc, char *argv[]);
|
Launcher(int argc, char *argv[]);
|
||||||
|
|
||||||
|
static Launcher &Instance();
|
||||||
|
|
||||||
int exec() override;
|
int exec() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
#include "platform/linux/linux_desktop_environment.h"
|
#include "platform/linux/linux_desktop_environment.h"
|
||||||
#include "platform/linux/linux_wayland_integration.h"
|
#include "platform/linux/linux_wayland_integration.h"
|
||||||
|
#include "platform/platform_launcher.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "storage/localstorage.h"
|
#include "storage/localstorage.h"
|
||||||
|
@ -139,20 +140,21 @@ void PortalAutostart(bool start, bool silent) {
|
||||||
const auto handleToken = Glib::ustring("tdesktop")
|
const auto handleToken = Glib::ustring("tdesktop")
|
||||||
+ std::to_string(base::RandomValue<uint>());
|
+ 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;
|
std::map<Glib::ustring, Glib::VariantBase> options;
|
||||||
options["handle_token"] = Glib::Variant<Glib::ustring>::create(
|
options["handle_token"] = Glib::Variant<Glib::ustring>::create(
|
||||||
handleToken);
|
handleToken);
|
||||||
options["reason"] = Glib::Variant<Glib::ustring>::create(
|
options["reason"] = Glib::Variant<Glib::ustring>::create(
|
||||||
tr::lng_settings_auto_start(tr::now).toStdString());
|
tr::lng_settings_auto_start(tr::now).toStdString());
|
||||||
options["autostart"] = Glib::Variant<bool>::create(start);
|
options["autostart"] = Glib::Variant<bool>::create(start);
|
||||||
options["commandline"] = Glib::Variant<std::vector<
|
options["commandline"] = base::Platform::MakeGlibVariant(commandline);
|
||||||
Glib::ustring
|
|
||||||
>>::create({
|
|
||||||
cExeName().toStdString(),
|
|
||||||
"-workdir",
|
|
||||||
cWorkingDir().toStdString(),
|
|
||||||
"-autostart",
|
|
||||||
});
|
|
||||||
options["dbus-activatable"] = Glib::Variant<bool>::create(false);
|
options["dbus-activatable"] = Glib::Variant<bool>::create(false);
|
||||||
|
|
||||||
auto uniqueName = connection->get_unique_name();
|
auto uniqueName = connection->get_unique_name();
|
||||||
|
@ -443,11 +445,11 @@ bool GenerateDesktopFile(
|
||||||
qsl("^Exec=telegram-desktop(.*)$"),
|
qsl("^Exec=telegram-desktop(.*)$"),
|
||||||
QRegularExpression::MultilineOption),
|
QRegularExpression::MultilineOption),
|
||||||
qsl("Exec=%1\\1").arg(
|
qsl("Exec=%1\\1").arg(
|
||||||
KShell::joinArgs({
|
KShell::joinArgs(QStringList{
|
||||||
cExeDir() + cExeName(),
|
cExeDir() + cExeName(),
|
||||||
"-workdir",
|
} + (Core::Sandbox::Instance().customWorkingDir()
|
||||||
cWorkingDir(),
|
? QStringList{ "-workdir", cWorkingDir() }
|
||||||
}).replace('\\', "\\\\")));
|
: QStringList{})).replace('\\', "\\\\")));
|
||||||
|
|
||||||
fileText = fileText.replace(
|
fileText = fileText.replace(
|
||||||
QRegularExpression(
|
QRegularExpression(
|
||||||
|
@ -661,7 +663,18 @@ void start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Core::UpdaterDisabled()) {
|
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");
|
return qsl("org.telegram.desktop.desktop");
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit d3f9e826197c6ed42f8ef2d021d8eb74b2d390cc
|
Subproject commit e1e4c68c91b2a56fd4d61cd843bb3bb5d4d99498
|
Loading…
Add table
Reference in a new issue