mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Have a global Core::Launcher accessor
This allows to use Launcher in code executing before Sandbox is created
This commit is contained in:
parent
63ccf1bed4
commit
a7bd097b2f
13 changed files with 50 additions and 70 deletions
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -24,8 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace Platform {
|
||||
namespace {
|
||||
|
||||
Launcher *LauncherInstance = nullptr;
|
||||
|
||||
class Arguments {
|
||||
public:
|
||||
void push(QByteArray argument) {
|
||||
|
@ -50,15 +48,6 @@ 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() {
|
||||
|
|
|
@ -15,8 +15,6 @@ class Launcher : public Core::Launcher {
|
|||
public:
|
||||
Launcher(int argc, char *argv[]);
|
||||
|
||||
static Launcher &Instance();
|
||||
|
||||
int exec() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -15,10 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "base/platform/linux/base_linux_xdp_utilities.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"
|
||||
#include "core/launcher.h"
|
||||
#include "core/sandbox.h"
|
||||
#include "core/application.h"
|
||||
#include "core/local_url_handlers.h"
|
||||
|
@ -138,7 +138,7 @@ bool PortalAutostart(bool start, bool silent) {
|
|||
|
||||
std::vector<Glib::ustring> commandline;
|
||||
commandline.push_back(cExeName().toStdString());
|
||||
if (Core::Sandbox::Instance().customWorkingDir()) {
|
||||
if (Core::Launcher::Instance().customWorkingDir()) {
|
||||
commandline.push_back("-workdir");
|
||||
commandline.push_back(cWorkingDir().toStdString());
|
||||
}
|
||||
|
@ -403,7 +403,7 @@ bool GenerateDesktopFile(
|
|||
exec.append(!Core::UpdaterDisabled()
|
||||
? (cExeDir() + cExeName())
|
||||
: cExeName());
|
||||
if (Core::Sandbox::Instance().customWorkingDir()) {
|
||||
if (Core::Launcher::Instance().customWorkingDir()) {
|
||||
exec.append(u"-workdir"_q);
|
||||
exec.append(cWorkingDir());
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ bool GenerateDesktopFile(
|
|||
exec[0] = !Core::UpdaterDisabled()
|
||||
? (cExeDir() + cExeName())
|
||||
: cExeName();
|
||||
if (Core::Sandbox::Instance().customWorkingDir()) {
|
||||
if (Core::Launcher::Instance().customWorkingDir()) {
|
||||
exec.insert(1, u"-workdir"_q);
|
||||
exec.insert(2, cWorkingDir());
|
||||
}
|
||||
|
@ -479,7 +479,7 @@ bool GenerateDesktopFile(
|
|||
const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath());
|
||||
hashMd5Hex(d.constData(), d.size(), md5Hash);
|
||||
|
||||
if (!Core::Sandbox::Instance().customWorkingDir()) {
|
||||
if (!Core::Launcher::Instance().customWorkingDir()) {
|
||||
const auto exePath = QFile::encodeName(
|
||||
cExeDir() + cExeName());
|
||||
hashMd5Hex(exePath.constData(), exePath.size(), md5Hash);
|
||||
|
@ -676,7 +676,7 @@ void start() {
|
|||
|
||||
if (!Core::UpdaterDisabled()) {
|
||||
QByteArray md5Hash(h);
|
||||
if (!Launcher::Instance().customWorkingDir()) {
|
||||
if (!Core::Launcher::Instance().customWorkingDir()) {
|
||||
const auto exePath = QFile::encodeName(
|
||||
cExeDir() + cExeName());
|
||||
|
||||
|
@ -726,6 +726,8 @@ void start() {
|
|||
h,
|
||||
cGUIDStr(),
|
||||
u"%1"_q).toStdString());
|
||||
|
||||
InstallLauncher();
|
||||
}
|
||||
|
||||
void finish() {
|
||||
|
@ -805,7 +807,6 @@ void start() {
|
|||
"except various functionality to not to work.");
|
||||
}
|
||||
|
||||
InstallLauncher();
|
||||
LaunchGApplication();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "window/window_session_controller.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "core/update_checker.h"
|
||||
#include "core/launcher.h"
|
||||
#include "core/application.h"
|
||||
#include "tray.h"
|
||||
#include "storage/localstorage.h"
|
||||
|
@ -224,7 +225,7 @@ void SetupUpdate(
|
|||
return (toggled != cInstallBetaVersion());
|
||||
}) | rpl::start_with_next([=](bool toggled) {
|
||||
cSetInstallBetaVersion(toggled);
|
||||
Core::App().writeInstallBetaVersionsSetting();
|
||||
Core::Launcher::Instance().writeInstallBetaVersionsSetting();
|
||||
|
||||
Core::UpdateChecker checker;
|
||||
checker.stop();
|
||||
|
|
|
@ -28,7 +28,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "window/window_session_controller.h"
|
||||
#include "storage/storage_media_prepare.h"
|
||||
#include "storage/localimageloader.h"
|
||||
#include "core/sandbox.h"
|
||||
#include "core/launcher.h"
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "main/main_session.h"
|
||||
|
@ -138,7 +138,7 @@ void EditInfoBox::setInnerFocus() {
|
|||
}
|
||||
|
||||
uint32 OccupationTag() {
|
||||
return uint32(Core::Sandbox::Instance().installationTag() & 0xFFFFFFFF);
|
||||
return uint32(Core::Launcher::Instance().installationTag() & 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
QString NormalizeName(QString name) {
|
||||
|
@ -268,7 +268,7 @@ Helper::Helper(not_null<Main::Session*> session)
|
|||
}).fail([=] {
|
||||
setSupportName(
|
||||
u"[rand^"_q
|
||||
+ QString::number(Core::Sandbox::Instance().installationTag())
|
||||
+ QString::number(Core::Launcher::Instance().installationTag())
|
||||
+ ']');
|
||||
}).send();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue