Finish up singleton refactoring into one giant class
This commit is contained in:
@@ -7,10 +7,9 @@ namespace singletons {
|
||||
|
||||
class AccountManager
|
||||
{
|
||||
AccountManager() = default;
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
AccountManager() = default;
|
||||
|
||||
~AccountManager() = delete;
|
||||
|
||||
void load();
|
||||
|
||||
@@ -151,11 +151,12 @@ QString CommandManager::execCommand(const QString &text, ChannelPtr channel, boo
|
||||
return "";
|
||||
}
|
||||
|
||||
auto app = getApp();
|
||||
|
||||
messages::MessageBuilder b;
|
||||
|
||||
b.emplace<messages::TextElement>(
|
||||
getApp()->accounts->Twitch.getCurrent()->getUserName(),
|
||||
messages::MessageElement::Text);
|
||||
b.emplace<messages::TextElement>(app->accounts->Twitch.getCurrent()->getUserName(),
|
||||
messages::MessageElement::Text);
|
||||
b.emplace<messages::TextElement>("->", messages::MessageElement::Text);
|
||||
b.emplace<messages::TextElement>(words[1], messages::MessageElement::Text);
|
||||
|
||||
@@ -167,7 +168,7 @@ QString CommandManager::execCommand(const QString &text, ChannelPtr channel, boo
|
||||
|
||||
b.emplace<messages::TextElement>(rest, messages::MessageElement::Text);
|
||||
|
||||
TwitchServer::getInstance().whispersChannel->addMessage(b.getMessage());
|
||||
app->twitch.server->whispersChannel->addMessage(b.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,9 @@ namespace singletons {
|
||||
|
||||
class CommandManager
|
||||
{
|
||||
CommandManager() = default;
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
CommandManager() = default;
|
||||
|
||||
QString execCommand(const QString &text, std::shared_ptr<Channel> channel, bool dryRun);
|
||||
|
||||
void loadCommands();
|
||||
|
||||
@@ -22,10 +22,9 @@ namespace singletons {
|
||||
|
||||
class EmoteManager
|
||||
{
|
||||
EmoteManager();
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
EmoteManager();
|
||||
|
||||
~EmoteManager() = delete;
|
||||
|
||||
void initialize();
|
||||
|
||||
@@ -32,6 +32,7 @@ FontManager::FontManager()
|
||||
this->currentFontByScale.clear();
|
||||
this->fontChanged.invoke();
|
||||
});
|
||||
|
||||
this->currentFontSize.connect([this](const int &newValue, auto) {
|
||||
this->incGeneration();
|
||||
// this->currentFont.setSize(newValue);
|
||||
@@ -40,12 +41,6 @@ FontManager::FontManager()
|
||||
});
|
||||
}
|
||||
|
||||
FontManager &FontManager::getInstance()
|
||||
{
|
||||
static FontManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
QFont &FontManager::getFont(FontManager::Type type, float scale)
|
||||
{
|
||||
// return this->currentFont.getFont(type);
|
||||
|
||||
@@ -11,11 +11,13 @@ namespace singletons {
|
||||
|
||||
class FontManager
|
||||
{
|
||||
FontManager(const FontManager &) = delete;
|
||||
FontManager(FontManager &&) = delete;
|
||||
public:
|
||||
FontManager();
|
||||
|
||||
public:
|
||||
FontManager(const FontManager &) = delete;
|
||||
FontManager(FontManager &&) = delete;
|
||||
~FontManager() = delete;
|
||||
|
||||
enum Type : uint8_t {
|
||||
Tiny,
|
||||
Small,
|
||||
@@ -27,9 +29,6 @@ public:
|
||||
VeryLarge,
|
||||
};
|
||||
|
||||
// FontManager is initialized only once, on first use
|
||||
static FontManager &getInstance();
|
||||
|
||||
QFont &getFont(Type type, float scale);
|
||||
QFontMetrics &getFontMetrics(Type type, float scale);
|
||||
|
||||
|
||||
@@ -12,12 +12,11 @@ class PathManager;
|
||||
|
||||
class LoggingManager
|
||||
{
|
||||
LoggingManager() = default;
|
||||
friend class Application;
|
||||
|
||||
PathManager *pathManager = nullptr;
|
||||
|
||||
public:
|
||||
LoggingManager() = default;
|
||||
|
||||
~LoggingManager() = delete;
|
||||
|
||||
void initialize();
|
||||
|
||||
@@ -130,6 +130,8 @@ void NativeMessagingManager::ReceiverThread::run()
|
||||
|
||||
void NativeMessagingManager::ReceiverThread::handleMessage(const QJsonObject &root)
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
QString action = root.value("action").toString();
|
||||
|
||||
if (action.isNull()) {
|
||||
@@ -151,16 +153,15 @@ void NativeMessagingManager::ReceiverThread::handleMessage(const QJsonObject &ro
|
||||
}
|
||||
|
||||
if (_type == "twitch") {
|
||||
util::postToThread([name, attach, winId, yOffset] {
|
||||
auto &ts = providers::twitch::TwitchServer::getInstance();
|
||||
|
||||
ts.watchingChannel.update(ts.getOrAddChannel(name));
|
||||
util::postToThread([name, attach, winId, yOffset, app] {
|
||||
app->twitch.server->watchingChannel.update(
|
||||
app->twitch.server->getOrAddChannel(name));
|
||||
|
||||
if (attach) {
|
||||
#ifdef USEWINSDK
|
||||
auto *window =
|
||||
widgets::AttachedWindow::get(::GetForegroundWindow(), winId, yOffset);
|
||||
window->setChannel(ts.getOrAddChannel(name));
|
||||
window->setChannel(app->twitch.server->getOrAddChannel(name));
|
||||
window->show();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -7,10 +7,9 @@ namespace singletons {
|
||||
|
||||
class NativeMessagingManager
|
||||
{
|
||||
NativeMessagingManager();
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
NativeMessagingManager();
|
||||
|
||||
~NativeMessagingManager() = delete;
|
||||
|
||||
class ReceiverThread : public QThread
|
||||
|
||||
@@ -7,10 +7,9 @@ namespace singletons {
|
||||
|
||||
class PathManager
|
||||
{
|
||||
PathManager(int argc, char **argv);
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
PathManager(int argc, char **argv);
|
||||
|
||||
// %APPDATA%/chatterino or ExecutablePath for portable mode
|
||||
QString settingsFolderPath;
|
||||
|
||||
|
||||
@@ -68,9 +68,6 @@ private:
|
||||
|
||||
class PubSubManager
|
||||
{
|
||||
PubSubManager();
|
||||
friend class Application;
|
||||
|
||||
using WebsocketMessagePtr = websocketpp::config::asio_tls_client::message_type::ptr;
|
||||
using WebsocketContextPtr = websocketpp::lib::shared_ptr<boost::asio::ssl::context>;
|
||||
|
||||
@@ -81,6 +78,8 @@ class PubSubManager
|
||||
std::unique_ptr<std::thread> mainThread;
|
||||
|
||||
public:
|
||||
PubSubManager();
|
||||
|
||||
~PubSubManager() = delete;
|
||||
|
||||
enum class State {
|
||||
|
||||
@@ -289,18 +289,15 @@ ResourceManager::ResourceManager()
|
||||
, buttonTimeout(lli(":/images/button_timeout.png", 0.25))
|
||||
{
|
||||
qDebug() << "init ResourceManager";
|
||||
}
|
||||
|
||||
void ResourceManager::initialize()
|
||||
{
|
||||
this->loadDynamicTwitchBadges();
|
||||
|
||||
this->loadChatterinoBadges();
|
||||
}
|
||||
|
||||
ResourceManager &ResourceManager::getInstance()
|
||||
{
|
||||
static ResourceManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
ResourceManager::BadgeVersion::BadgeVersion(QJsonObject &&root)
|
||||
: badgeImage1x(new messages::Image(root.value("image_url_1x").toString()))
|
||||
, badgeImage2x(new messages::Image(root.value("image_url_2x").toString()))
|
||||
|
||||
@@ -13,10 +13,12 @@ namespace singletons {
|
||||
|
||||
class ResourceManager
|
||||
{
|
||||
public:
|
||||
ResourceManager();
|
||||
|
||||
public:
|
||||
static ResourceManager &getInstance();
|
||||
~ResourceManager() = delete;
|
||||
|
||||
void initialize();
|
||||
|
||||
messages::Image *badgeStaff;
|
||||
messages::Image *badgeAdmin;
|
||||
|
||||
@@ -32,7 +32,10 @@ SettingManager::SettingManager()
|
||||
this->wordFlagsListener.cb = [this](auto) {
|
||||
this->updateWordTypeMask(); //
|
||||
};
|
||||
}
|
||||
|
||||
void SettingManager::initialize()
|
||||
{
|
||||
this->moderationActions.connect([this](auto, auto) { this->updateModerationActions(); });
|
||||
this->ignoredKeywords.connect([this](auto, auto) { this->updateIgnoredKeywords(); });
|
||||
|
||||
@@ -52,7 +55,7 @@ bool SettingManager::isIgnoredEmote(const QString &)
|
||||
return false;
|
||||
}
|
||||
|
||||
void SettingManager::initialize()
|
||||
void SettingManager::load()
|
||||
{
|
||||
auto app = getApp();
|
||||
QString settingsPath = app->paths->settingsFolderPath + "/settings.json";
|
||||
@@ -155,7 +158,7 @@ const std::shared_ptr<std::vector<QString>> SettingManager::getIgnoredKeywords()
|
||||
|
||||
void SettingManager::updateModerationActions()
|
||||
{
|
||||
auto &resources = singletons::ResourceManager::getInstance();
|
||||
auto app = getApp();
|
||||
|
||||
this->_moderationActions.clear();
|
||||
|
||||
@@ -207,10 +210,10 @@ void SettingManager::updateModerationActions()
|
||||
|
||||
this->_moderationActions.emplace_back(line1, line2, str);
|
||||
} else {
|
||||
this->_moderationActions.emplace_back(resources.buttonTimeout, str);
|
||||
this->_moderationActions.emplace_back(app->resources->buttonTimeout, str);
|
||||
}
|
||||
} else if (str.startsWith("/ban ")) {
|
||||
this->_moderationActions.emplace_back(resources.buttonBan, str);
|
||||
this->_moderationActions.emplace_back(app->resources->buttonBan, str);
|
||||
} else {
|
||||
QString xD = str;
|
||||
|
||||
|
||||
@@ -21,16 +21,16 @@ class SettingManager
|
||||
using StringSetting = ChatterinoSetting<std::string>;
|
||||
using QStringSetting = ChatterinoSetting<QString>;
|
||||
|
||||
SettingManager();
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
SettingManager();
|
||||
|
||||
~SettingManager() = delete;
|
||||
|
||||
messages::MessageElement::Flags getWordFlags();
|
||||
bool isIgnoredEmote(const QString &emote);
|
||||
|
||||
void initialize();
|
||||
void load();
|
||||
|
||||
/// Appearance
|
||||
BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true};
|
||||
|
||||
@@ -13,10 +13,9 @@ class WindowManager;
|
||||
|
||||
class ThemeManager
|
||||
{
|
||||
ThemeManager();
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
ThemeManager();
|
||||
|
||||
~ThemeManager() = delete;
|
||||
|
||||
inline bool isLightTheme() const
|
||||
|
||||
@@ -331,16 +331,17 @@ IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj)
|
||||
{
|
||||
util::assertInGuiThread();
|
||||
|
||||
auto app = getApp();
|
||||
|
||||
QString type = obj.value("type").toString();
|
||||
if (type == "twitch") {
|
||||
return providers::twitch::TwitchServer::getInstance().getOrAddChannel(
|
||||
obj.value("name").toString());
|
||||
return app->twitch.server->getOrAddChannel(obj.value("name").toString());
|
||||
} else if (type == "mentions") {
|
||||
return providers::twitch::TwitchServer::getInstance().mentionsChannel;
|
||||
return app->twitch.server->mentionsChannel;
|
||||
} else if (type == "watching") {
|
||||
return providers::twitch::TwitchServer::getInstance().watchingChannel;
|
||||
return app->twitch.server->watchingChannel;
|
||||
} else if (type == "whispers") {
|
||||
return providers::twitch::TwitchServer::getInstance().whispersChannel;
|
||||
return app->twitch.server->whispersChannel;
|
||||
}
|
||||
|
||||
return Channel::getEmpty();
|
||||
|
||||
@@ -7,10 +7,9 @@ namespace singletons {
|
||||
|
||||
class WindowManager
|
||||
{
|
||||
WindowManager();
|
||||
friend class Application;
|
||||
|
||||
public:
|
||||
WindowManager();
|
||||
|
||||
~WindowManager() = delete;
|
||||
|
||||
void showSettingsDialog();
|
||||
|
||||
Reference in New Issue
Block a user