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
@@ -47,7 +47,7 @@ AccountController::AccountController()
});
}
void AccountController::initialize(Settings &settings, const Paths &paths)
void AccountController::load()
{
this->twitch.load();
}
@@ -1,7 +1,6 @@
#pragma once
#include "common/SignalVector.hpp"
#include "common/Singleton.hpp"
#include "providers/twitch/TwitchAccountManager.hpp"
#include <QObject>
@@ -14,14 +13,17 @@ class Paths;
class AccountModel;
class AccountController final : public Singleton
class AccountController final
{
public:
AccountController();
AccountModel *createModel(QObject *parent);
void initialize(Settings &settings, const Paths &paths) override;
/**
* Load current user & send off a signal to subscribers about any potential changes
*/
void load();
TwitchAccountManager twitch;
@@ -121,7 +121,7 @@ const std::unordered_map<QString, VariableReplacer> COMMAND_VARS{
(void)(channel); //unused
(void)(message); //unused
auto uid =
getIApp()->getAccounts()->twitch.getCurrent()->getUserId();
getApp()->getAccounts()->twitch.getCurrent()->getUserId();
return uid.isEmpty() ? altText : uid;
},
},
@@ -131,7 +131,7 @@ const std::unordered_map<QString, VariableReplacer> COMMAND_VARS{
(void)(channel); //unused
(void)(message); //unused
auto name =
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
getApp()->getAccounts()->twitch.getCurrent()->getUserName();
return name.isEmpty() ? altText : name;
},
},
@@ -263,7 +263,7 @@ const std::unordered_map<QString, VariableReplacer> COMMAND_VARS{
namespace chatterino {
void CommandController::initialize(Settings &, const Paths &paths)
CommandController::CommandController(const Paths &paths)
{
// Update commands map when the vector of commands has been updated
auto addFirstMatchToMap = [this](auto args) {
@@ -485,7 +485,7 @@ QString CommandController::execCommand(const QString &textNoEmoji,
ChannelPtr channel, bool dryRun)
{
QString text =
getIApp()->getEmotes()->getEmojis()->replaceShortCodes(textNoEmoji);
getApp()->getEmotes()->getEmojis()->replaceShortCodes(textNoEmoji);
QStringList words = text.split(' ', Qt::SkipEmptyParts);
if (words.length() == 0)
@@ -500,7 +500,7 @@ QString CommandController::execCommand(const QString &textNoEmoji,
const auto it = this->userCommands_.find(commandName);
if (it != this->userCommands_.end())
{
text = getIApp()->getEmotes()->getEmojis()->replaceShortCodes(
text = getApp()->getEmotes()->getEmojis()->replaceShortCodes(
this->execCustomCommand(words, it.value(), dryRun, channel));
words = text.split(' ', Qt::SkipEmptyParts);
@@ -570,7 +570,7 @@ bool CommandController::registerPluginCommand(const QString &commandName)
}
this->commands_[commandName] = [commandName](const CommandContext &ctx) {
return getIApp()->getPlugins()->tryExecPluginCommand(commandName, ctx);
return getApp()->getPlugins()->tryExecPluginCommand(commandName, ctx);
};
this->pluginCommands_.append(commandName);
return true;
@@ -1,7 +1,6 @@
#pragma once
#include "common/SignalVector.hpp"
#include "common/Singleton.hpp"
#include "util/QStringHash.hpp"
#include <pajlada/settings.hpp>
@@ -24,7 +23,7 @@ struct Command;
class CommandModel;
struct CommandContext;
class CommandController final : public Singleton
class CommandController final
{
public:
SignalVector<Command> items;
@@ -33,8 +32,8 @@ public:
bool dryRun);
QStringList getDefaultChatterinoCommandList();
void initialize(Settings &, const Paths &paths) override;
void save() override;
CommandController(const Paths &paths);
void save();
CommandModel *createModel(QObject *parent);
+11 -12
View File
@@ -220,7 +220,7 @@ QString marker(const CommandContext &ctx)
}
// Avoid Helix calls without Client ID and/or OAuth Token
if (getIApp()->getAccounts()->twitch.getCurrent()->isAnon())
if (getApp()->getAccounts()->twitch.getCurrent()->isAnon())
{
ctx.channel->addSystemMessage(
"You need to be logged in to create stream markers!");
@@ -367,7 +367,7 @@ QString popup(const CommandContext &ctx)
if (target.isEmpty())
{
auto *currentPage =
dynamic_cast<SplitContainer *>(getIApp()
dynamic_cast<SplitContainer *>(getApp()
->getWindows()
->getMainWindow()
.getNotebook()
@@ -388,9 +388,8 @@ QString popup(const CommandContext &ctx)
}
// Open channel passed as argument in a popup
auto targetChannel =
getIApp()->getTwitchAbstract()->getOrAddChannel(target);
getIApp()->getWindows()->openInPopup(targetChannel);
auto targetChannel = getApp()->getTwitchAbstract()->getOrAddChannel(target);
getApp()->getWindows()->openInPopup(targetChannel);
return "";
}
@@ -399,7 +398,7 @@ QString clearmessages(const CommandContext &ctx)
{
(void)ctx;
auto *currentPage = getIApp()
auto *currentPage = getApp()
->getWindows()
->getLastSelectedWindow()
->getNotebook()
@@ -531,7 +530,7 @@ QString sendRawMessage(const CommandContext &ctx)
if (ctx.channel->isTwitchChannel())
{
getIApp()->getTwitchAbstract()->sendRawMessage(
getApp()->getTwitchAbstract()->sendRawMessage(
ctx.words.mid(1).join(" "));
}
else
@@ -565,7 +564,7 @@ QString injectFakeMessage(const CommandContext &ctx)
}
auto ircText = ctx.words.mid(1).join(" ");
getIApp()->getTwitchAbstract()->addFakeMessage(ircText);
getApp()->getTwitchAbstract()->addFakeMessage(ircText);
return "";
}
@@ -634,7 +633,7 @@ QString unstableSetUserClientSideColor(const CommandContext &ctx)
auto color = ctx.words.value(2);
getIApp()->getUserData()->setUserColor(userID, color);
getApp()->getUserData()->setUserColor(userID, color);
return "";
}
@@ -664,7 +663,7 @@ QString openUsercard(const CommandContext &ctx)
stripChannelName(channelName);
ChannelPtr channelTemp =
getIApp()->getTwitchAbstract()->getChannelOrEmpty(channelName);
getApp()->getTwitchAbstract()->getChannelOrEmpty(channelName);
if (channelTemp->isEmpty())
{
@@ -679,7 +678,7 @@ QString openUsercard(const CommandContext &ctx)
// try to link to current split if possible
Split *currentSplit = nullptr;
auto *currentPage = dynamic_cast<SplitContainer *>(getIApp()
auto *currentPage = dynamic_cast<SplitContainer *>(getApp()
->getWindows()
->getMainWindow()
.getNotebook()
@@ -695,7 +694,7 @@ QString openUsercard(const CommandContext &ctx)
{
// not possible to use current split, try searching for one
const auto &notebook =
getIApp()->getWindows()->getMainWindow().getNotebook();
getApp()->getWindows()->getMainWindow().getNotebook();
auto count = notebook.getPageCount();
for (int i = 0; i < count; i++)
{
@@ -32,7 +32,7 @@ QString addModerator(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage("You must be logged in to mod someone!");
@@ -32,7 +32,7 @@ QString addVIP(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage("You must be logged in to VIP someone!");
@@ -50,7 +50,7 @@ QString sendAnnouncementColor(const CommandContext &ctx,
return "";
}
auto user = getIApp()->getAccounts()->twitch.getCurrent();
auto user = getApp()->getAccounts()->twitch.getCurrent();
if (user->isAnon())
{
ctx.channel->addSystemMessage(
@@ -141,7 +141,7 @@ QString sendBan(const CommandContext &ctx)
assert(!actions.value().empty());
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage("You must be logged in to ban someone!");
@@ -252,7 +252,7 @@ QString sendBanById(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
channel->addSystemMessage("You must be logged in to ban someone!");
@@ -292,7 +292,7 @@ QString sendTimeout(const CommandContext &ctx)
assert(!actions.value().empty());
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(
@@ -36,7 +36,7 @@ QString blockUser(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
@@ -52,7 +52,7 @@ QString blockUser(const CommandContext &ctx)
target,
[currentUser, channel{ctx.channel},
target](const HelixUser &targetUser) {
getIApp()->getAccounts()->twitch.getCurrent()->blockUser(
getApp()->getAccounts()->twitch.getCurrent()->blockUser(
targetUser.id, nullptr,
[channel, target, targetUser] {
channel->addSystemMessage(
@@ -109,7 +109,7 @@ QString unblockUser(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
@@ -124,7 +124,7 @@ QString unblockUser(const CommandContext &ctx)
getHelix()->getUserByName(
target,
[currentUser, channel{ctx.channel}, target](const auto &targetUser) {
getIApp()->getAccounts()->twitch.getCurrent()->unblockUser(
getApp()->getAccounts()->twitch.getCurrent()->unblockUser(
targetUser.id, nullptr,
[channel, target, targetUser] {
channel->addSystemMessage(
@@ -100,7 +100,7 @@ namespace chatterino::commands {
QString emoteOnly(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -130,7 +130,7 @@ QString emoteOnly(const CommandContext &ctx)
QString emoteOnlyOff(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -158,7 +158,7 @@ QString emoteOnlyOff(const CommandContext &ctx)
QString subscribers(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -188,7 +188,7 @@ QString subscribers(const CommandContext &ctx)
QString subscribersOff(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -218,7 +218,7 @@ QString subscribersOff(const CommandContext &ctx)
QString slow(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -265,7 +265,7 @@ QString slow(const CommandContext &ctx)
QString slowOff(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -294,7 +294,7 @@ QString slowOff(const CommandContext &ctx)
QString followers(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -342,7 +342,7 @@ QString followers(const CommandContext &ctx)
QString followersOff(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -372,7 +372,7 @@ QString followersOff(const CommandContext &ctx)
QString uniqueChat(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -402,7 +402,7 @@ QString uniqueChat(const CommandContext &ctx)
QString uniqueChatOff(const CommandContext &ctx)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(P_NOT_LOGGED_IN);
@@ -77,7 +77,7 @@ QString chatters(const CommandContext &ctx)
// Refresh chatter list via helix api for mods
getHelix()->getChatters(
ctx.twitchChannel->roomId(),
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), 1,
getApp()->getAccounts()->twitch.getCurrent()->getUserId(), 1,
[channel{ctx.channel}](auto result) {
channel->addSystemMessage(QString("Chatter count: %1.")
.arg(localizeNumbers(result.total)));
@@ -106,7 +106,7 @@ QString testChatters(const CommandContext &ctx)
getHelix()->getChatters(
ctx.twitchChannel->roomId(),
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(), 5000,
getApp()->getAccounts()->twitch.getCurrent()->getUserId(), 5000,
[channel{ctx.channel}, twitchChannel{ctx.twitchChannel}](auto result) {
QStringList entries;
for (const auto &username : result.chatters)
@@ -21,7 +21,7 @@ QString deleteMessages(TwitchChannel *twitchChannel, const QString &messageID)
{
const auto *commandName = messageID.isEmpty() ? "/clear" : "/delete";
auto user = getIApp()->getAccounts()->twitch.getCurrent();
auto user = getApp()->getAccounts()->twitch.getCurrent();
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
@@ -81,7 +81,7 @@ QString getVIPs(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(
@@ -136,7 +136,7 @@ QString startRaid(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage("You must be logged in to start a raid!");
@@ -192,7 +192,7 @@ QString cancelRaid(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(
@@ -32,7 +32,7 @@ QString removeModerator(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(
@@ -34,7 +34,7 @@ QString removeVIP(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(
@@ -92,7 +92,7 @@ QString formatWhisperError(HelixWhisperError error, const QString &message)
bool appendWhisperMessageWordsLocally(const QStringList &words)
{
auto *app = getIApp();
auto *app = getApp();
MessageBuilder b;
@@ -102,7 +102,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
MessageElementFlag::Text, MessageColor::Text,
FontStyle::ChatMediumBold);
b.emplace<TextElement>("->", MessageElementFlag::Text,
getIApp()->getThemes()->messages.textColors.system);
getApp()->getThemes()->messages.textColors.system);
b.emplace<TextElement>(words[1] + ":", MessageElementFlag::Text,
MessageColor::Text, FontStyle::ChatMediumBold);
@@ -177,12 +177,12 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
b->flags.set(MessageFlag::Whisper);
auto messagexD = b.release();
getIApp()->getTwitch()->getWhispersChannel()->addMessage(
getApp()->getTwitch()->getWhispersChannel()->addMessage(
messagexD, MessageContext::Original);
if (getSettings()->inlineWhispers &&
!(getSettings()->streamerModeSuppressInlineWhispers &&
getIApp()->getStreamerMode()->isEnabled()))
getApp()->getStreamerMode()->isEnabled()))
{
app->getTwitchAbstract()->forEachChannel(
[&messagexD](ChannelPtr _channel) {
@@ -210,7 +210,7 @@ QString sendWhisper(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(
@@ -22,7 +22,7 @@ QString toggleShieldMode(const CommandContext &ctx, bool isActivating)
return {};
}
auto user = getIApp()->getAccounts()->twitch.getCurrent();
auto user = getApp()->getAccounts()->twitch.getCurrent();
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
@@ -23,7 +23,7 @@ QString sendShoutout(const CommandContext &ctx)
return "";
}
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
channel->addSystemMessage("You must be logged in to send shoutout.");
@@ -98,7 +98,7 @@ QString startCommercial(const CommandContext &ctx)
return "";
}
auto user = getIApp()->getAccounts()->twitch.getCurrent();
auto user = getApp()->getAccounts()->twitch.getCurrent();
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
@@ -108,7 +108,7 @@ QString unbanUser(const CommandContext &ctx)
assert(!actions.value().empty());
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage(
@@ -25,7 +25,7 @@ QString updateUserColor(const CommandContext &ctx)
"The /color command only works in Twitch channels.");
return "";
}
auto user = getIApp()->getAccounts()->twitch.getCurrent();
auto user = getApp()->getAccounts()->twitch.getCurrent();
// Avoid Helix calls without Client ID and/or OAuth Token
if (user->isAnon())
@@ -104,7 +104,7 @@ QString sendWarn(const CommandContext &ctx)
assert(!actions.value().empty());
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (currentUser->isAnon())
{
ctx.channel->addSystemMessage("You must be logged in to warn someone!");
@@ -39,7 +39,7 @@ void TabCompletionModel::updateResults(const QString &query,
// Try plugins first
bool done{};
std::tie(done, results) =
getIApp()->getPlugins()->updateCustomCompletions(
getApp()->getPlugins()->updateCustomCompletions(
query, fullTextContent, cursorPosition, isFirstWord);
if (done)
{
@@ -71,20 +71,20 @@ void CommandSource::initializeItems()
std::vector<CommandItem> commands;
#ifdef CHATTERINO_HAVE_PLUGINS
for (const auto &command : getIApp()->getCommands()->pluginCommands())
for (const auto &command : getApp()->getCommands()->pluginCommands())
{
addCommand(command, commands);
}
#endif
// Custom Chatterino commands
for (const auto &command : getIApp()->getCommands()->items)
for (const auto &command : getApp()->getCommands()->items)
{
addCommand(command.name, commands);
}
// Default Chatterino commands
auto x = getIApp()->getCommands()->getDefaultChatterinoCommandList();
auto x = getApp()->getCommands()->getDefaultChatterinoCommandList();
for (const auto &command : x)
{
addCommand(command, commands);
@@ -88,7 +88,7 @@ void EmoteSource::addToStringList(QStringList &list, size_t maxCount,
void EmoteSource::initializeFromChannel(const Channel *channel)
{
auto *app = getIApp();
auto *app = getApp();
std::vector<EmoteItem> emotes;
const auto *tc = dynamic_cast<const TwitchChannel *>(channel);
+1 -1
View File
@@ -12,7 +12,7 @@ namespace chatterino::filters {
ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)
{
auto watchingChannel = getIApp()->getTwitch()->getWatchingChannel().get();
auto watchingChannel = getApp()->getTwitch()->getWatchingChannel().get();
/*
* Looking to add a new identifier to filters? Here's what to do:
@@ -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
+1 -1
View File
@@ -58,7 +58,7 @@ std::vector<QString> Hotkey::arguments() const
QString Hotkey::getCategory() const
{
return getIApp()->getHotkeys()->categoryDisplayName(this->category_);
return getApp()->getHotkeys()->categoryDisplayName(this->category_);
}
Qt::ShortcutContext Hotkey::getContext() const
+2 -3
View File
@@ -1,7 +1,6 @@
#pragma once
#include "common/SignalVector.hpp"
#include "common/Singleton.hpp"
#include "controllers/hotkeys/HotkeyCategory.hpp"
#include <pajlada/signals/signal.hpp>
@@ -18,7 +17,7 @@ class Hotkey;
class HotkeyModel;
class HotkeyController final : public Singleton
class HotkeyController final
{
public:
using HotkeyFunction = std::function<QString(std::vector<QString>)>;
@@ -31,7 +30,7 @@ public:
HotkeyMap actionMap,
QWidget *parent);
void save() override;
void save();
std::shared_ptr<Hotkey> getHotkeyByName(QString name);
/**
* @brief returns a QKeySequence that perfoms the actions requested.
+1 -1
View File
@@ -32,7 +32,7 @@ bool isIgnoredMessage(IgnoredMessageParameters &&params)
{
auto sourceUserID = params.twitchUserID;
bool isBlocked = getIApp()
bool isBlocked = getApp()
->getAccounts()
->twitch.getCurrent()
->blockedUserIds()
+1 -1
View File
@@ -95,7 +95,7 @@ bool IgnorePhrase::containsEmote() const
{
if (!this->emotesChecked_)
{
const auto &accvec = getIApp()->getAccounts()->twitch.accounts;
const auto &accvec = getApp()->getAccounts()->twitch.accounts;
for (const auto &acc : accvec)
{
const auto &accemotes = *acc->accessEmotes();
@@ -17,9 +17,10 @@
#include <QUrl>
namespace ranges = std::ranges;
namespace chatterino {
void NotificationController::initialize(Settings &settings, const Paths &paths)
NotificationController::NotificationController()
{
for (const QString &channelName : this->twitchSetting_.getValue())
{
@@ -34,14 +35,17 @@ void NotificationController::initialize(Settings &settings, const Paths &paths)
this->channelMap[Platform::Twitch].raw());
});
this->fetchFakeChannels();
QObject::connect(&this->liveStatusTimer_, &QTimer::timeout, [this] {
this->fetchFakeChannels();
});
this->liveStatusTimer_.start(60 * 1000);
}
void NotificationController::initialize()
{
this->fetchFakeChannels();
}
void NotificationController::updateChannelNotification(
const QString &channelName, Platform p)
{
@@ -92,7 +96,7 @@ void NotificationController::playSound() const
getSettings()->notificationPathSound.getValue())
: QUrl("qrc:/sounds/ping2.wav");
getIApp()->getSound()->play(highlightSoundUrl);
getApp()->getSound()->play(highlightSoundUrl);
}
NotificationModel *NotificationController::createModel(QObject *parent,
@@ -109,7 +113,7 @@ void NotificationController::notifyTwitchChannelLive(
bool showNotification =
!(getSettings()->suppressInitialLiveNotification &&
payload.isInitialUpdate) &&
!(getIApp()->getStreamerMode()->isEnabled() &&
!(getApp()->getStreamerMode()->isEnabled() &&
getSettings()->streamerModeSuppressLiveNotifications);
bool playedSound = false;
@@ -118,7 +122,7 @@ void NotificationController::notifyTwitchChannelLive(
{
if (Toasts::isEnabled())
{
getIApp()->getToasts()->sendChannelNotification(
getApp()->getToasts()->sendChannelNotification(
payload.channelName, payload.title, Platform::Twitch);
}
if (getSettings()->notificationPlaySound)
@@ -128,7 +132,7 @@ void NotificationController::notifyTwitchChannelLive(
}
if (getSettings()->notificationFlashTaskbar)
{
getIApp()->getWindows()->sendAlert();
getApp()->getWindows()->sendAlert();
}
}
@@ -136,7 +140,7 @@ void NotificationController::notifyTwitchChannelLive(
MessageBuilder builder;
TwitchMessageBuilder::liveMessage(payload.displayName, &builder);
builder.message().id = payload.channelId;
getIApp()->getTwitch()->getLiveChannel()->addMessage(
getApp()->getTwitch()->getLiveChannel()->addMessage(
builder.release(), MessageContext::Original);
// Notify on all channels with a ping sound
@@ -152,7 +156,7 @@ void NotificationController::notifyTwitchChannelOffline(const QString &id) const
{
// "delete" old 'CHANNEL is live' message
LimitedQueueSnapshot<MessagePtr> snapshot =
getIApp()->getTwitch()->getLiveChannel()->getMessageSnapshot();
getApp()->getTwitch()->getLiveChannel()->getMessageSnapshot();
int snapshotLength = static_cast<int>(snapshot.size());
int end = std::max(0, snapshotLength - 200);
@@ -177,7 +181,7 @@ void NotificationController::fetchFakeChannels()
for (size_t i = 0; i < channelMap[Platform::Twitch].raw().size(); i++)
{
const auto &name = channelMap[Platform::Twitch].raw()[i];
auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(name);
auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(name);
if (chan->isEmpty())
{
channels.push_back(name);
@@ -2,7 +2,6 @@
#include "common/ChatterinoSetting.hpp"
#include "common/SignalVector.hpp"
#include "common/Singleton.hpp"
#include "util/QCompareCaseInsensitive.hpp"
#include <QTimer>
@@ -19,10 +18,13 @@ enum class Platform : uint8_t {
Twitch, // 0
};
class NotificationController final : public Singleton
class NotificationController final
{
public:
void initialize(Settings &settings, const Paths &paths) override;
NotificationController();
// Perform an initial load so we don't have to wait for the timer
void initialize();
bool isChannelNotified(const QString &channelName, Platform p) const;
void updateChannelNotification(const QString &channelName, Platform p);
+7 -7
View File
@@ -65,7 +65,7 @@ namespace chatterino::lua::api {
int c2_register_command(lua_State *L)
{
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
luaL_error(L, "internal error: no plugin");
@@ -99,7 +99,7 @@ int c2_register_command(lua_State *L)
int c2_register_callback(lua_State *L)
{
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
luaL_error(L, "internal error: no plugin");
@@ -133,7 +133,7 @@ int c2_register_callback(lua_State *L)
int c2_log(lua_State *L)
{
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
luaL_error(L, "c2_log: internal error: no plugin?");
@@ -154,7 +154,7 @@ int c2_log(lua_State *L)
int c2_later(lua_State *L)
{
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
return luaL_error(L, "c2.later: internal error: no plugin?");
@@ -257,7 +257,7 @@ int g_load(lua_State *L)
int loadfile(lua_State *L, const QString &str)
{
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
return luaL_error(L, "loadfile: internal error: no plugin?");
@@ -307,7 +307,7 @@ int searcherAbsolute(lua_State *L)
name = name.replace('.', QDir::separator());
QString filename;
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
return luaL_error(L, "searcherAbsolute: internal error: no plugin?");
@@ -348,7 +348,7 @@ int searcherRelative(lua_State *L)
int g_print(lua_State *L)
{
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
if (pl == nullptr)
{
luaL_error(L, "c2_print: internal error: no plugin?");
+1 -1
View File
@@ -197,7 +197,7 @@ bool Plugin::registerCommand(const QString &name, const QString &functionName)
return false;
}
auto ok = getIApp()->getCommands()->registerPluginCommand(name);
auto ok = getApp()->getCommands()->registerPluginCommand(name);
if (!ok)
{
return false;
+2 -4
View File
@@ -35,10 +35,8 @@ PluginController::PluginController(const Paths &paths_)
{
}
void PluginController::initialize(Settings &settings, const Paths &paths)
void PluginController::initialize(Settings &settings)
{
(void)paths;
// actuallyInitialize will be called by this connection
settings.pluginsEnabled.connect([this](bool enabled) {
if (enabled)
@@ -354,7 +352,7 @@ bool PluginController::reload(const QString &id)
}
for (const auto &[cmd, _] : it->second->ownedCommands)
{
getIApp()->getCommands()->unregisterPluginCommand(cmd);
getApp()->getCommands()->unregisterPluginCommand(cmd);
}
it->second->ownedCommands.clear();
QDir loadDir = it->second->loadDirectory_;
+2 -3
View File
@@ -2,7 +2,6 @@
#ifdef CHATTERINO_HAVE_PLUGINS
# include "common/Singleton.hpp"
# include "controllers/commands/CommandContext.hpp"
# include "controllers/plugins/Plugin.hpp"
@@ -24,14 +23,14 @@ namespace chatterino {
class Paths;
class PluginController : public Singleton
class PluginController
{
const Paths &paths;
public:
explicit PluginController(const Paths &paths_);
void initialize(Settings &settings, const Paths &paths) override;
void initialize(Settings &settings);
QString tryExecPluginCommand(const QString &commandName,
const CommandContext &ctx);
+3 -3
View File
@@ -174,7 +174,7 @@ int ChannelRef::send_message(lua_State *L)
text = text.replace('\n', ' ');
if (execcmds)
{
text = getIApp()->getCommands()->execCommand(text, that, false);
text = getApp()->getCommands()->execCommand(text, that, false);
}
that->sendMessage(text);
return 0;
@@ -300,7 +300,7 @@ int ChannelRef::get_by_name(lua_State *L)
lua_pushnil(L);
return 1;
}
auto chn = getIApp()->getTwitchAbstract()->getChannelOrEmpty(name);
auto chn = getApp()->getTwitchAbstract()->getChannelOrEmpty(name);
lua::push(L, chn);
return 1;
}
@@ -324,7 +324,7 @@ int ChannelRef::get_by_twitch_id(lua_State *L)
lua_pushnil(L);
return 1;
}
auto chn = getIApp()->getTwitch()->getChannelOrEmptyByID(id);
auto chn = getApp()->getTwitch()->getChannelOrEmptyByID(id);
lua::push(L, chn);
return 1;
+1 -1
View File
@@ -309,7 +309,7 @@ int HTTPRequest::create(lua_State *L)
L, "cannot get method (1st argument of HTTPRequest.create, "
"expected a string)");
}
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
if (!pl->hasHTTPPermissionFor(parsedurl))
{
return luaL_error(
+1 -2
View File
@@ -1,6 +1,5 @@
#pragma once
#include "common/Singleton.hpp"
#include "util/QStringHash.hpp"
#include <QString>
@@ -26,7 +25,7 @@ public:
virtual void add(const std::shared_ptr<TwitchChannel> &newChannel) = 0;
};
class TwitchLiveController : public ITwitchLiveController, public Singleton
class TwitchLiveController : public ITwitchLiveController
{
public:
// Controls how often all channels have their stream status refreshed