chore: remove Singleton & replace getIApp with getApp (#5514)

This commit is contained in:
pajlada
2024-07-21 15:09:59 +02:00
committed by GitHub
parent 21186df058
commit 5deec1f02f
145 changed files with 802 additions and 856 deletions
@@ -53,7 +53,7 @@ void BadgeHighlightModel::getRowFromItem(const HighlightBadge &item,
setFilePathItem(row[Column::SoundPath], item.getSoundUrl());
setColorItem(row[Column::Color], *item.getColor());
getIApp()->getTwitchBadges()->getBadgeIcon(
getApp()->getTwitchBadges()->getBadgeIcon(
item.badgeName(), [item, row](QString /*name*/, const QIconPtr pixmap) {
row[Column::Badge]->setData(QVariant(*pixmap), Qt::DecorationRole);
});
@@ -183,7 +183,7 @@ void rebuildReplyThreadHighlight(Settings &settings,
void rebuildMessageHighlights(Settings &settings,
std::vector<HighlightCheck> &checks)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
QString currentUsername = currentUser->getUserName();
if (settings.enableSelfHighlight && !currentUsername.isEmpty() &&
@@ -442,9 +442,11 @@ std::ostream &operator<<(std::ostream &os, const HighlightResult &result)
return os;
}
void HighlightController::initialize(Settings &settings,
const Paths & /*paths*/)
HighlightController::HighlightController(Settings &settings,
AccountController *accounts)
{
assert(accounts != nullptr);
this->rebuildListener_.addSetting(settings.enableSelfHighlight);
this->rebuildListener_.addSetting(settings.enableSelfHighlightSound);
this->rebuildListener_.addSetting(settings.enableSelfHighlightTaskbar);
@@ -507,12 +509,12 @@ void HighlightController::initialize(Settings &settings,
this->rebuildChecks(settings);
});
getIApp()->getAccounts()->twitch.currentUserChanged.connect(
[this, &settings] {
this->bConnections.emplace_back(
accounts->twitch.currentUserChanged.connect([this, &settings] {
qCDebug(chatterinoHighlights)
<< "Rebuild checks because user swapped accounts";
this->rebuildChecks(settings);
});
}));
this->rebuildChecks(settings);
}
@@ -550,7 +552,7 @@ std::pair<bool, HighlightResult> HighlightController::check(
// Access for checking
const auto checks = this->checks_.accessConst();
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
auto self = (senderName == currentUser->getUserName());
for (const auto &check : *checks)
@@ -1,9 +1,10 @@
#pragma once
#include "common/FlagsEnum.hpp"
#include "common/Singleton.hpp"
#include "common/UniqueAccess.hpp"
#include "singletons/Settings.hpp"
#include <boost/signals2/connection.hpp>
#include <pajlada/settings.hpp>
#include <pajlada/settings/settinglistener.hpp>
#include <QColor>
@@ -20,6 +21,7 @@ class Badge;
struct MessageParseArgs;
enum class MessageFlag : int64_t;
using MessageFlags = FlagsEnum<MessageFlag>;
class AccountController;
struct HighlightResult {
HighlightResult(bool _alert, bool _playSound,
@@ -83,10 +85,10 @@ struct HighlightCheck {
Checker cb;
};
class HighlightController final : public Singleton
class HighlightController final
{
public:
void initialize(Settings &settings, const Paths &paths) override;
HighlightController(Settings &settings, AccountController *accounts);
/**
* @brief Checks the given message parameters if it matches our internal checks, and returns a result
@@ -108,6 +110,7 @@ private:
pajlada::SettingListener rebuildListener_;
pajlada::Signals::SignalHolder signalHolder_;
std::vector<boost::signals2::scoped_connection> bConnections;
};
} // namespace chatterino
@@ -519,7 +519,7 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
break;
}
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
}
} // namespace chatterino
@@ -109,7 +109,7 @@ void UserHighlightModel::customRowSetData(
break;
}
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
}
// row into vector item