2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Have a global Core::Launcher accessor

This allows to use Launcher in code executing before Sandbox is created
This commit is contained in:
Ilya Fedin
2023-06-13 04:34:27 +04:00
committed by John Preston
parent 63ccf1bed4
commit a7bd097b2f
13 changed files with 50 additions and 70 deletions

View File

@@ -143,9 +143,8 @@ struct Application::Private {
Settings settings;
};
Application::Application(not_null<Launcher*> launcher)
Application::Application()
: QObject()
, _launcher(launcher)
, _private(std::make_unique<Private>())
, _platformIntegration(Platform::Integration::Create())
, _batterySaving(std::make_unique<base::BatterySaving>())
@@ -945,11 +944,11 @@ rpl::producer<> Application::materializeLocalDraftsRequests() const {
void Application::switchDebugMode() {
if (Logs::DebugEnabled()) {
Logs::SetDebugEnabled(false);
_launcher->writeDebugModeSetting();
Launcher::Instance().writeDebugModeSetting();
Restart();
} else {
Logs::SetDebugEnabled(true);
_launcher->writeDebugModeSetting();
Launcher::Instance().writeDebugModeSetting();
DEBUG_LOG(("Debug logs started."));
if (_lastActivePrimaryWindow) {
_lastActivePrimaryWindow->hideLayer();
@@ -957,10 +956,6 @@ void Application::switchDebugMode() {
}
}
void Application::writeInstallBetaVersionsSetting() {
_launcher->writeInstallBetaVersionsSetting();
}
Main::Account &Application::activeAccount() const {
return _domain->active();
}
@@ -1770,7 +1765,7 @@ void Application::RegisterUrlScheme() {
.executable = (!Platform::IsLinux() || !Core::UpdaterDisabled())
? (cExeDir() + cExeName())
: cExeName(),
.arguments = Sandbox::Instance().customWorkingDir()
.arguments = Launcher::Instance().customWorkingDir()
? u"-workdir \"%1\""_q.arg(cWorkingDir())
: QString(),
.protocol = u"tg"_q,

View File

@@ -103,7 +103,6 @@ class Instance;
namespace Core {
class Launcher;
struct LocalUrlHandler;
class Settings;
class Tray;
@@ -126,16 +125,13 @@ public:
MTP::ProxyData now;
};
Application(not_null<Launcher*> launcher);
Application();
Application(const Application &other) = delete;
Application &operator=(const Application &other) = delete;
~Application();
void run();
[[nodiscard]] Launcher &launcher() const {
return *_launcher;
}
[[nodiscard]] Platform::Integration &platformIntegration() const {
return *_platformIntegration;
}
@@ -319,7 +315,6 @@ public:
[[nodiscard]] rpl::producer<> materializeLocalDraftsRequests() const;
void switchDebugMode();
void writeInstallBetaVersionsSetting();
void preventOrInvoke(Fn<void()> &&callback);
@@ -381,7 +376,6 @@ private:
};
InstanceSetter _setter = { this };
const not_null<Launcher*> _launcher;
rpl::event_stream<ProxyChange> _proxyChanges;
// Some fields are just moved from the declaration.

View File

@@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/crash_reports.h"
#include "core/application.h"
#include "core/launcher.h"
#include "core/sandbox.h"
#include "core/update_checker.h"
#include "core/ui_integration.h"
@@ -250,7 +249,6 @@ LastCrashedWindow::UpdaterData::UpdaterData(QWidget *buttonParent)
}
LastCrashedWindow::LastCrashedWindow(
not_null<Core::Launcher*> launcher,
const QByteArray &crashdump,
Fn<void()> launch)
: _dumpraw(crashdump)

View File

@@ -94,10 +94,7 @@ private:
class LastCrashedWindow : public PreLaunchWindow {
public:
LastCrashedWindow(
not_null<Core::Launcher*> launcher,
const QByteArray &crashdump,
Fn<void()> launch);
LastCrashedWindow(const QByteArray &crashdump, Fn<void()> launch);
rpl::producer<MTP::ProxyData> proxyChanges() const;

View File

@@ -281,6 +281,8 @@ base::options::toggle OptionFractionalScalingEnabled({
const char kOptionFractionalScalingEnabled[] = "fractional-scaling-enabled";
const char kOptionFreeType[] = "freetype";
Launcher *Launcher::InstanceSetter::Instance = nullptr;
std::unique_ptr<Launcher> Launcher::Create(int argc, char *argv[]) {
return std::make_unique<Platform::Launcher>(argc, argv);
}
@@ -294,6 +296,10 @@ Launcher::Launcher(int argc, char *argv[])
base::Integration::Set(&_baseIntegration);
}
Launcher::~Launcher() {
InstanceSetter::Instance = nullptr;
}
void Launcher::init() {
_arguments = readArguments(_argc, _argv);
@@ -558,7 +564,7 @@ void Launcher::processArguments() {
int Launcher::executeApplication() {
FilteredCommandLineArguments arguments(_argc, _argv);
Sandbox sandbox(this, arguments.count(), arguments.values());
Sandbox sandbox(arguments.count(), arguments.values());
Ui::MainQueueProcessor processor;
base::ConcurrentTimerEnvironment environment;
return sandbox.start();

View File

@@ -20,6 +20,12 @@ public:
static std::unique_ptr<Launcher> Create(int argc, char *argv[]);
static Launcher &Instance() {
Expects(InstanceSetter::Instance != nullptr);
return *InstanceSetter::Instance;
}
virtual int exec();
QString argumentsString() const;
@@ -32,7 +38,7 @@ public:
void writeDebugModeSetting();
void writeInstallBetaVersionsSetting();
virtual ~Launcher() = default;
virtual ~Launcher();
protected:
enum class UpdaterLaunch {
@@ -61,6 +67,17 @@ private:
int executeApplication();
struct InstanceSetter {
InstanceSetter(not_null<Launcher*> instance) {
Expects(Instance == nullptr);
Instance = instance;
}
static Launcher *Instance;
};
InstanceSetter _setter = { this };
int _argc;
char **_argv;
QStringList _arguments;

View File

@@ -78,13 +78,9 @@ QString _escapeFrom7bit(const QString &str) {
bool Sandbox::QuitOnStartRequested = false;
Sandbox::Sandbox(
not_null<Core::Launcher*> launcher,
int &argc,
char **argv)
Sandbox::Sandbox(int &argc, char **argv)
: QApplication(argc, argv)
, _mainThreadId(QThread::currentThreadId())
, _launcher(launcher) {
, _mainThreadId(QThread::currentThreadId()) {
setQuitOnLastWindowClosed(false);
}
@@ -107,7 +103,8 @@ int Sandbox::start() {
hashMd5Hex(d.constData(), d.size(), h.data());
_lockFile = std::make_unique<QLockFile>(QDir::tempPath() + '/' + h + '-' + cGUIDStr());
_lockFile->setStaleLockTime(0);
if (!_lockFile->tryLock() && _launcher->customWorkingDir()) {
if (!_lockFile->tryLock()
&& Launcher::Instance().customWorkingDir()) {
// On Windows, QLockFile has problems detecting a stale lock
// if the machine's hostname contains characters outside the US-ASCII character set.
if constexpr (Platform::IsWindows()) {
@@ -200,7 +197,7 @@ void Sandbox::launchApplication() {
}
setupScreenScale();
_application = std::make_unique<Application>(_launcher);
_application = std::make_unique<Application>();
// Ideally this should go to constructor.
// But we want to catch all native events and Application installs
@@ -401,7 +398,6 @@ void Sandbox::singleInstanceChecked() {
}
_lastCrashDump = crashdump;
auto window = new LastCrashedWindow(
_launcher,
_lastCrashDump,
[=] { launchApplication(); });
window->proxyChanges(
@@ -529,14 +525,6 @@ void Sandbox::refreshGlobalProxy() {
}
}
bool Sandbox::customWorkingDir() const {
return _launcher->customWorkingDir();
}
uint64 Sandbox::installationTag() const {
return _launcher->installationTag();
}
void Sandbox::checkForEmptyLoopNestingLevel() {
// _loopNestingLevel == _eventNestingLevel means that we had a
// native event in a nesting loop that didn't get a notify() call

View File

@@ -19,7 +19,6 @@ class QLockFile;
namespace Core {
class Launcher;
class UpdateChecker;
class Application;
@@ -33,7 +32,7 @@ private:
}
public:
Sandbox(not_null<Launcher*> launcher, int &argc, char **argv);
Sandbox(int &argc, char **argv);
Sandbox(const Sandbox &other) = delete;
Sandbox &operator=(const Sandbox &other) = delete;
@@ -41,8 +40,6 @@ public:
int start();
void refreshGlobalProxy();
bool customWorkingDir() const;
uint64 installationTag() const;
void postponeCall(FnMut<void()> &&callable);
bool notify(QObject *receiver, QEvent *e) override;
@@ -116,7 +113,6 @@ private:
std::vector<int> _previousLoopNestingLevels;
std::vector<PostponedCall> _postponedCalls;
not_null<Launcher*> _launcher;
std::unique_ptr<Application> _application;
QString _localServerName, _localSocketReadData;