From 35a7780564adb5317b6fdd6277d046af49226a39 Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 22 May 2022 15:00:18 +0200 Subject: [PATCH] Make an IApplication interface (#3758) --- src/Application.cpp | 15 +++++++++ src/Application.hpp | 76 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/Application.cpp b/src/Application.cpp index 083514ef8..234d3d7c2 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -46,6 +46,12 @@ namespace chatterino { static std::atomic isAppInitialized{false}; Application *Application::instance = nullptr; +IApplication *IApplication::instance = nullptr; + +IApplication::IApplication() +{ + IApplication::instance = this; +} // this class is responsible for handling the workflow of Chatterino // It will create the instances of the major classes, and connect their signals @@ -526,4 +532,13 @@ Application *getApp() return Application::instance; } +IApplication *getIApp() +{ + assert(IApplication::instance != nullptr); + + assertInGuiThread(); + + return IApplication::instance; +} + } // namespace chatterino diff --git a/src/Application.hpp b/src/Application.hpp index 846b8231d..f0dca9874 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -29,7 +29,29 @@ class Toasts; class ChatterinoBadges; class FfzBadges; -class Application +class IApplication +{ +public: + IApplication(); + virtual ~IApplication() = default; + + static IApplication *instance; + + virtual Theme *getThemes() = 0; + virtual Fonts *getFonts() = 0; + virtual Emotes *getEmotes() = 0; + virtual AccountController *getAccounts() = 0; + virtual HotkeyController *getHotkeys() = 0; + virtual WindowManager *getWindows() = 0; + virtual Toasts *getToasts() = 0; + virtual CommandController *getCommands() = 0; + virtual NotificationController *getNotifications() = 0; + virtual TwitchIrcServer *getTwitch() = 0; + virtual ChatterinoBadges *getChatterinoBadges() = 0; + virtual FfzBadges *getFfzBadges() = 0; +}; + +class Application : public IApplication { std::vector> singletons_; int argc_; @@ -64,6 +86,55 @@ public: /*[[deprecated]]*/ Logging *const logging{}; + Theme *getThemes() override + { + return this->themes; + } + Fonts *getFonts() override + { + return this->fonts; + } + Emotes *getEmotes() override + { + return this->emotes; + } + AccountController *getAccounts() override + { + return this->accounts; + } + HotkeyController *getHotkeys() override + { + return this->hotkeys; + } + WindowManager *getWindows() override + { + return this->windows; + } + Toasts *getToasts() override + { + return this->toasts; + } + CommandController *getCommands() override + { + return this->commands; + } + NotificationController *getNotifications() override + { + return this->notifications; + } + TwitchIrcServer *getTwitch() override + { + return this->twitch; + } + ChatterinoBadges *getChatterinoBadges() override + { + return this->chatterinoBadges; + } + FfzBadges *getFfzBadges() override + { + return this->ffzBadges; + } + private: void addSingleton(Singleton *singleton); void initPubSub(); @@ -83,4 +154,7 @@ private: Application *getApp(); +// Get an interface version of the Application class - should be preferred when possible for new code +IApplication *getIApp(); + } // namespace chatterino