fix: only use IApplication::instance instead of Application::instance (#5540)

This commit is contained in:
pajlada 2024-08-11 14:03:47 +02:00 committed by GitHub
parent 1ccdaea8ee
commit 832e70e314
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 21 deletions

View file

@ -124,18 +124,23 @@ SeventvEventAPI *makeSeventvEventAPI(Settings &settings)
const QString TWITCH_PUBSUB_URL = "wss://pubsub-edge.twitch.tv"; const QString TWITCH_PUBSUB_URL = "wss://pubsub-edge.twitch.tv";
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
IApplication *INSTANCE = nullptr;
} // namespace } // namespace
namespace chatterino { namespace chatterino {
static std::atomic<bool> isAppInitialized{false}; static std::atomic<bool> isAppInitialized{false};
Application *Application::instance = nullptr;
IApplication *IApplication::instance = nullptr;
IApplication::IApplication() IApplication::IApplication()
{ {
IApplication::instance = this; INSTANCE = this;
}
IApplication::~IApplication()
{
INSTANCE = nullptr;
} }
// this class is responsible for handling the workflow of Chatterino // this class is responsible for handling the workflow of Chatterino
@ -182,8 +187,6 @@ Application::Application(Settings &_settings, const Paths &paths,
#endif #endif
, updates(_updates) , updates(_updates)
{ {
Application::instance = this;
// We can safely ignore this signal's connection since the Application will always // We can safely ignore this signal's connection since the Application will always
// be destroyed after fonts // be destroyed after fonts
std::ignore = this->fonts->fontChanged.connect([this]() { std::ignore = this->fonts->fontChanged.connect([this]() {
@ -193,7 +196,8 @@ Application::Application(Settings &_settings, const Paths &paths,
Application::~Application() Application::~Application()
{ {
Application::instance = nullptr; // we do this early to ensure getApp isn't used in any dtors
INSTANCE = nullptr;
} }
void Application::initialize(Settings &settings, const Paths &paths) void Application::initialize(Settings &settings, const Paths &paths)
@ -528,6 +532,13 @@ PluginController *Application::getPlugins()
} }
#endif #endif
Updates &Application::getUpdates()
{
assertInGuiThread();
return this->updates;
}
ITwitchIrcServer *Application::getTwitch() ITwitchIrcServer *Application::getTwitch()
{ {
assertInGuiThread(); assertInGuiThread();
@ -1180,9 +1191,9 @@ void Application::initSeventvEventAPI()
IApplication *getApp() IApplication *getApp()
{ {
assert(IApplication::instance != nullptr); assert(INSTANCE != nullptr);
return IApplication::instance; return INSTANCE;
} }
} // namespace chatterino } // namespace chatterino

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "debug/AssertInGuiThread.hpp"
#include "singletons/NativeMessaging.hpp" #include "singletons/NativeMessaging.hpp"
#include <QApplication> #include <QApplication>
@ -62,9 +61,12 @@ class IApplication
{ {
public: public:
IApplication(); IApplication();
virtual ~IApplication() = default; virtual ~IApplication();
static IApplication *instance; IApplication(const IApplication &) = delete;
IApplication(IApplication &&) = delete;
IApplication &operator=(const IApplication &) = delete;
IApplication &operator=(IApplication &&) = delete;
virtual bool isTest() const = 0; virtual bool isTest() const = 0;
@ -115,8 +117,6 @@ class Application : public IApplication
char **argv_{}; char **argv_{};
public: public:
static Application *instance;
Application(Settings &_settings, const Paths &paths, const Args &_args, Application(Settings &_settings, const Paths &paths, const Args &_args,
Updates &_updates); Updates &_updates);
~Application() override; ~Application() override;
@ -210,12 +210,7 @@ public:
#ifdef CHATTERINO_HAVE_PLUGINS #ifdef CHATTERINO_HAVE_PLUGINS
PluginController *getPlugins() override; PluginController *getPlugins() override;
#endif #endif
Updates &getUpdates() override Updates &getUpdates() override;
{
assertInGuiThread();
return this->updates;
}
BttvEmotes *getBttvEmotes() override; BttvEmotes *getBttvEmotes() override;
BttvLiveUpdates *getBttvLiveUpdates() override; BttvLiveUpdates *getBttvLiveUpdates() override;
@ -232,7 +227,7 @@ private:
void initSeventvEventAPI(); void initSeventvEventAPI();
void initNm(const Paths &paths); void initNm(const Paths &paths);
NativeMessagingServer nmServer{}; NativeMessagingServer nmServer;
Updates &updates; Updates &updates;
}; };