refactor: Make Args less of a singleton (#5041)

This means it's no longer a singleton, and its lifetime is bound to our application.
This felt like a good small experiment to see how its changes would look
if we did this.
As a shortcut, `getApp` that is already a mega singleton keeps a
reference to Args, this means places that are a bit more difficult to
inject into call `getApp()->getArgs()` just like other things are
accessed.
This commit is contained in:
pajlada
2023-12-29 15:40:31 +01:00
committed by GitHub
parent c65ebd26bd
commit d085ab578f
20 changed files with 78 additions and 69 deletions
+8 -1
View File
@@ -11,6 +11,7 @@
namespace chatterino {
class Args;
class TwitchIrcServer;
class ITwitchIrcServer;
class PubSub;
@@ -54,6 +55,7 @@ public:
static IApplication *instance;
virtual const Args &getArgs() = 0;
virtual Theme *getThemes() = 0;
virtual Fonts *getFonts() = 0;
virtual IEmotes *getEmotes() = 0;
@@ -78,6 +80,7 @@ public:
class Application : public IApplication
{
const Args &args_;
std::vector<std::unique_ptr<Singleton>> singletons_;
int argc_{};
char **argv_{};
@@ -85,7 +88,7 @@ class Application : public IApplication
public:
static Application *instance;
Application(Settings &settings, Paths &paths);
Application(Settings &_settings, Paths &_paths, const Args &_args);
void initialize(Settings &settings, Paths &paths);
void load();
@@ -126,6 +129,10 @@ public:
/*[[deprecated]]*/ Logging *const logging{};
const Args &getArgs() override
{
return this->args_;
}
Theme *getThemes() override
{
return this->themes;