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:
+1
-15
@@ -1,4 +1,4 @@
|
||||
#include "Args.hpp"
|
||||
#include "common/Args.hpp"
|
||||
|
||||
#include "common/QLogging.hpp"
|
||||
#include "debug/AssertInGuiThread.hpp"
|
||||
@@ -248,18 +248,4 @@ void Args::applyCustomChannelLayout(const QString &argValue)
|
||||
}
|
||||
}
|
||||
|
||||
static Args *instance = nullptr;
|
||||
|
||||
void initArgs(const QApplication &app)
|
||||
{
|
||||
instance = new Args(app);
|
||||
}
|
||||
|
||||
const Args &getArgs()
|
||||
{
|
||||
assert(instance);
|
||||
|
||||
return *instance;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
+1
-3
@@ -30,6 +30,7 @@ namespace chatterino {
|
||||
class Args
|
||||
{
|
||||
public:
|
||||
Args() = default;
|
||||
Args(const QApplication &app);
|
||||
|
||||
bool printVersion{};
|
||||
@@ -60,7 +61,4 @@ private:
|
||||
QStringList currentArguments_;
|
||||
};
|
||||
|
||||
void initArgs(const QApplication &app);
|
||||
const Args &getArgs();
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user