refactor: Un-singletonize Paths & Updates (#5092)

This commit is contained in:
pajlada
2024-01-16 21:56:43 +01:00
committed by GitHub
parent 7f935665f9
commit 718696db53
60 changed files with 237 additions and 165 deletions
+6 -7
View File
@@ -66,7 +66,7 @@ QStringList extractCommandLine(
namespace chatterino {
Args::Args(const QApplication &app)
Args::Args(const QApplication &app, const Paths &paths)
{
QCommandLineParser parser;
parser.setApplicationDescription("Chatterino 2 Client for Twitch Chat");
@@ -132,7 +132,7 @@ Args::Args(const QApplication &app)
if (parser.isSet(channelLayout))
{
this->applyCustomChannelLayout(parser.value(channelLayout));
this->applyCustomChannelLayout(parser.value(channelLayout), paths);
}
this->verbose = parser.isSet(verboseOption);
@@ -175,7 +175,7 @@ QStringList Args::currentArguments() const
return this->currentArguments_;
}
void Args::applyCustomChannelLayout(const QString &argValue)
void Args::applyCustomChannelLayout(const QString &argValue, const Paths &paths)
{
WindowLayout layout;
WindowDescriptor window;
@@ -187,10 +187,9 @@ void Args::applyCustomChannelLayout(const QString &argValue)
window.type_ = WindowType::Main;
// Load main window layout from config file so we can use the same geometry
const QRect configMainLayout = [] {
const QString windowLayoutFile =
combinePath(getPaths()->settingsDirectory,
WindowManager::WINDOW_LAYOUT_FILENAME);
const QRect configMainLayout = [paths] {
const QString windowLayoutFile = combinePath(
paths.settingsDirectory, WindowManager::WINDOW_LAYOUT_FILENAME);
const WindowLayout configLayout =
WindowLayout::loadFromFile(windowLayoutFile);
+4 -2
View File
@@ -8,6 +8,8 @@
namespace chatterino {
class Paths;
/// Command line arguments passed to Chatterino.
///
/// All accepted arguments:
@@ -31,7 +33,7 @@ class Args
{
public:
Args() = default;
Args(const QApplication &app);
Args(const QApplication &app, const Paths &paths);
bool printVersion{};
@@ -56,7 +58,7 @@ public:
QStringList currentArguments() const;
private:
void applyCustomChannelLayout(const QString &argValue);
void applyCustomChannelLayout(const QString &argValue, const Paths &paths);
QStringList currentArguments_;
};
+4 -2
View File
@@ -1,5 +1,6 @@
#include "common/Credentials.hpp"
#include "Application.hpp"
#include "debug/AssertInGuiThread.hpp"
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
@@ -40,7 +41,7 @@ bool useKeyring()
#ifdef NO_QTKEYCHAIN
return false;
#endif
if (getPaths()->isPortable())
if (getIApp()->getPaths().isPortable())
{
return false;
}
@@ -55,7 +56,8 @@ bool useKeyring()
// Insecure storage:
QString insecurePath()
{
return combinePath(getPaths()->settingsDirectory, "credentials.json");
return combinePath(getIApp()->getPaths().settingsDirectory,
"credentials.json");
}
QJsonDocument loadInsecure()
+1 -1
View File
@@ -17,7 +17,7 @@ public:
Singleton(Singleton &&) = delete;
Singleton &operator=(Singleton &&) = delete;
virtual void initialize(Settings &settings, Paths &paths)
virtual void initialize(Settings &settings, const Paths &paths)
{
(void)(settings);
(void)(paths);
+3 -1
View File
@@ -1,5 +1,6 @@
#include "common/network/NetworkPrivate.hpp"
#include "Application.hpp"
#include "common/network/NetworkManager.hpp"
#include "common/network/NetworkResult.hpp"
#include "common/network/NetworkTask.hpp"
@@ -57,7 +58,8 @@ void loadUncached(std::shared_ptr<NetworkData> &&data)
void loadCached(std::shared_ptr<NetworkData> &&data)
{
QFile cachedFile(getPaths()->cacheDirectory() + "/" + data->getHash());
QFile cachedFile(getIApp()->getPaths().cacheDirectory() + "/" +
data->getHash());
if (!cachedFile.exists() || !cachedFile.open(QIODevice::ReadOnly))
{
+3 -1
View File
@@ -1,5 +1,6 @@
#include "common/network/NetworkTask.hpp"
#include "Application.hpp"
#include "common/network/NetworkManager.hpp"
#include "common/network/NetworkPrivate.hpp"
#include "common/network/NetworkResult.hpp"
@@ -117,7 +118,8 @@ void NetworkTask::logReply()
void NetworkTask::writeToCache(const QByteArray &bytes) const
{
std::ignore = QtConcurrent::run([data = this->data_, bytes] {
QFile cachedFile(getPaths()->cacheDirectory() + "/" + data->getHash());
QFile cachedFile(getIApp()->getPaths().cacheDirectory() + "/" +
data->getHash());
if (cachedFile.open(QIODevice::WriteOnly))
{