Make an IApplication interface (#3758)

This commit is contained in:
pajlada 2022-05-22 15:00:18 +02:00 committed by GitHub
parent bd3d2ed82a
commit 35a7780564
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 90 additions and 1 deletions

View file

@ -46,6 +46,12 @@ namespace chatterino {
static std::atomic<bool> 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

View file

@ -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<std::unique_ptr<Singleton>> 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