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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
145 changed files with 802 additions and 856 deletions

View file

@ -5,7 +5,7 @@
#include "controllers/highlights/HighlightPhrase.hpp"
#include "messages/Message.hpp"
#include "messages/SharedMessageBuilder.hpp"
#include "mocks/EmptyApplication.hpp"
#include "mocks/BaseApplication.hpp"
#include "singletons/Settings.hpp"
#include "util/Helpers.hpp"
@ -47,9 +47,14 @@ public:
}
};
class MockApplication : mock::EmptyApplication
class MockApplication : public mock::BaseApplication
{
public:
MockApplication()
: highlights(this->settings, &this->accounts)
{
}
AccountController *getAccounts() override
{
return &this->accounts;
@ -61,7 +66,6 @@ public:
AccountController accounts;
HighlightController highlights;
// TODO: Figure this out
};
static void BM_HighlightTest(benchmark::State &state)

View file

@ -2,8 +2,8 @@
#include "controllers/accounts/AccountController.hpp"
#include "controllers/highlights/HighlightController.hpp"
#include "messages/Emote.hpp"
#include "mocks/BaseApplication.hpp"
#include "mocks/DisabledStreamerMode.hpp"
#include "mocks/EmptyApplication.hpp"
#include "mocks/LinkResolver.hpp"
#include "mocks/TwitchIrcServer.hpp"
#include "mocks/UserData.hpp"
@ -32,9 +32,14 @@ using namespace literals;
namespace {
class MockApplication : mock::EmptyApplication
class MockApplication : public mock::BaseApplication
{
public:
MockApplication()
: highlights(this->settings, &this->accounts)
{
}
IEmotes *getEmotes() override
{
return &this->emotes;

View file

@ -0,0 +1,37 @@
#pragma once
#include "mocks/DisabledStreamerMode.hpp"
#include "mocks/EmptyApplication.hpp"
#include "singletons/Settings.hpp"
#include <QString>
namespace chatterino::mock {
/**
* BaseApplication intends to be a mock application with a few more sane defaults, but with less configurability
*/
class BaseApplication : public EmptyApplication
{
public:
BaseApplication()
: settings(this->settingsDir.filePath("settings.json"))
{
}
explicit BaseApplication(const QString &settingsData)
: EmptyApplication(settingsData)
, settings(this->settingsDir.filePath("settings.json"))
{
}
IStreamerMode *getStreamerMode() override
{
return &this->streamerMode;
}
Settings settings;
DisabledStreamerMode streamerMode;
};
} // namespace chatterino::mock

View file

@ -17,7 +17,17 @@ public:
{
}
virtual ~EmptyApplication() = default;
explicit EmptyApplication(const QString &settingsData)
: EmptyApplication()
{
QFile settingsFile(this->settingsDir.filePath("settings.json"));
settingsFile.open(QIODevice::WriteOnly | QIODevice::Text);
settingsFile.write(settingsData.toUtf8());
settingsFile.flush();
settingsFile.close();
}
~EmptyApplication() override = default;
bool isTest() const override
{
@ -249,7 +259,6 @@ public:
return nullptr;
}
protected:
QTemporaryDir settingsDir;
Paths paths_;
Args args_;

View file

@ -118,26 +118,26 @@ Application::Application(Settings &_settings, const Paths &paths,
const Args &_args, Updates &_updates)
: paths_(paths)
, args_(_args)
, themes(&this->emplace<Theme>())
, themes(new Theme(paths))
, fonts(new Fonts(_settings))
, emotes(&this->emplace<Emotes>())
, accounts(&this->emplace<AccountController>())
, hotkeys(&this->emplace<HotkeyController>())
, windows(&this->emplace(new WindowManager(paths)))
, toasts(&this->emplace<Toasts>())
, imageUploader(&this->emplace<ImageUploader>())
, seventvAPI(&this->emplace<SeventvAPI>())
, crashHandler(&this->emplace(new CrashHandler(paths)))
, emotes(new Emotes)
, accounts(new AccountController)
, hotkeys(new HotkeyController)
, windows(new WindowManager(paths))
, toasts(new Toasts)
, imageUploader(new ImageUploader)
, seventvAPI(new SeventvAPI)
, crashHandler(new CrashHandler(paths))
, commands(&this->emplace<CommandController>())
, notifications(&this->emplace<NotificationController>())
, highlights(&this->emplace<HighlightController>())
, commands(new CommandController(paths))
, notifications(new NotificationController)
, highlights(new HighlightController(_settings, this->accounts.get()))
, twitch(new TwitchIrcServer)
, ffzBadges(&this->emplace<FfzBadges>())
, seventvBadges(&this->emplace<SeventvBadges>())
, ffzBadges(new FfzBadges)
, seventvBadges(new SeventvBadges)
, userData(new UserDataController(paths))
, sound(makeSoundController(_settings))
, twitchLiveController(&this->emplace<TwitchLiveController>())
, twitchLiveController(new TwitchLiveController)
, twitchPubSub(new PubSub(TWITCH_PUBSUB_URL))
, twitchBadges(new TwitchBadges)
, chatterinoBadges(new ChatterinoBadges)
@ -148,7 +148,7 @@ Application::Application(Settings &_settings, const Paths &paths,
, linkResolver(new LinkResolver)
, streamerMode(new StreamerMode)
#ifdef CHATTERINO_HAVE_PLUGINS
, plugins(&this->emplace(new PluginController(paths)))
, plugins(new PluginController(paths))
#endif
, updates(_updates)
{
@ -165,16 +165,35 @@ Application::~Application() = default;
void Application::fakeDtor()
{
#ifdef CHATTERINO_HAVE_PLUGINS
this->plugins.reset();
#endif
this->twitchPubSub.reset();
this->twitchBadges.reset();
this->twitchLiveController.reset();
this->chatterinoBadges.reset();
this->bttvEmotes.reset();
this->ffzEmotes.reset();
this->seventvEmotes.reset();
this->notifications.reset();
this->commands.reset();
// If a crash happens after crashHandler has been reset, we'll assert
// This isn't super different from before, where if the app is already killed, the getApp() portion of it is already dead
this->crashHandler.reset();
this->seventvAPI.reset();
this->highlights.reset();
this->seventvBadges.reset();
this->ffzBadges.reset();
// this->twitch.reset();
this->imageUploader.reset();
this->hotkeys.reset();
this->fonts.reset();
this->sound.reset();
this->userData.reset();
this->toasts.reset();
this->accounts.reset();
this->emotes.reset();
this->themes.reset();
}
void Application::initialize(Settings &settings, const Paths &paths)
@ -208,17 +227,24 @@ void Application::initialize(Settings &settings, const Paths &paths)
}
}
for (auto &singleton : this->singletons_)
{
singleton->initialize(settings, paths);
}
this->accounts->load();
this->windows->initialize(settings);
this->ffzBadges->load();
this->twitch->initialize();
// Load live status
this->notifications->initialize();
// XXX: Loading Twitch badges after Helix has been initialized, which only happens after
// the AccountController initialize has been called
this->twitchBadges->loadTwitchBadges();
#ifdef CHATTERINO_HAVE_PLUGINS
this->plugins->initialize(settings);
#endif
// Show crash message.
// On Windows, the crash message was already shown.
#ifndef Q_OS_WIN
@ -335,8 +361,9 @@ int Application::run(QApplication &qtApp)
Theme *Application::getThemes()
{
assertInGuiThread();
assert(this->themes);
return this->themes;
return this->themes.get();
}
Fonts *Application::getFonts()
@ -350,22 +377,25 @@ Fonts *Application::getFonts()
IEmotes *Application::getEmotes()
{
assertInGuiThread();
assert(this->emotes);
return this->emotes;
return this->emotes.get();
}
AccountController *Application::getAccounts()
{
assertInGuiThread();
assert(this->accounts);
return this->accounts;
return this->accounts.get();
}
HotkeyController *Application::getHotkeys()
{
assertInGuiThread();
assert(this->hotkeys);
return this->hotkeys;
return this->hotkeys.get();
}
WindowManager *Application::getWindows()
@ -373,56 +403,63 @@ WindowManager *Application::getWindows()
assertInGuiThread();
assert(this->windows);
return this->windows;
return this->windows.get();
}
Toasts *Application::getToasts()
{
assertInGuiThread();
assert(this->toasts);
return this->toasts;
return this->toasts.get();
}
CrashHandler *Application::getCrashHandler()
{
assertInGuiThread();
assert(this->crashHandler);
return this->crashHandler;
return this->crashHandler.get();
}
CommandController *Application::getCommands()
{
assertInGuiThread();
assert(this->commands);
return this->commands;
return this->commands.get();
}
NotificationController *Application::getNotifications()
{
assertInGuiThread();
assert(this->notifications);
return this->notifications;
return this->notifications.get();
}
HighlightController *Application::getHighlights()
{
assertInGuiThread();
assert(this->highlights);
return this->highlights;
return this->highlights.get();
}
FfzBadges *Application::getFfzBadges()
{
assertInGuiThread();
assert(this->ffzBadges);
return this->ffzBadges;
return this->ffzBadges.get();
}
SeventvBadges *Application::getSeventvBadges()
{
// SeventvBadges handles its own locks, so we don't need to assert that this is called in the GUI thread
assert(this->seventvBadges);
return this->seventvBadges;
return this->seventvBadges.get();
}
IUserDataController *Application::getUserData()
@ -442,8 +479,9 @@ ISoundController *Application::getSound()
ITwitchLiveController *Application::getTwitchLiveController()
{
assertInGuiThread();
assert(this->twitchLiveController);
return this->twitchLiveController;
return this->twitchLiveController.get();
}
TwitchBadges *Application::getTwitchBadges()
@ -465,23 +503,26 @@ IChatterinoBadges *Application::getChatterinoBadges()
ImageUploader *Application::getImageUploader()
{
assertInGuiThread();
assert(this->imageUploader);
return this->imageUploader;
return this->imageUploader.get();
}
SeventvAPI *Application::getSeventvAPI()
{
assertInGuiThread();
assert(this->seventvAPI);
return this->seventvAPI;
return this->seventvAPI.get();
}
#ifdef CHATTERINO_HAVE_PLUGINS
PluginController *Application::getPlugins()
{
assertInGuiThread();
assert(this->plugins);
return this->plugins;
return this->plugins.get();
}
#endif
@ -551,10 +592,9 @@ SeventvEmotes *Application::getSeventvEmotes()
void Application::save()
{
for (auto &singleton : this->singletons_)
{
singleton->save();
}
this->commands->save();
this->hotkeys->save();
this->windows->save();
}
void Application::initNm(const Paths &paths)
@ -896,11 +936,11 @@ void Application::initPubSub()
chan->addMessage(p.second,
MessageContext::Original);
getIApp()
getApp()
->getTwitch()
->getAutomodChannel()
->addMessage(p.first, MessageContext::Original);
getIApp()
getApp()
->getTwitch()
->getAutomodChannel()
->addMessage(p.second,
@ -908,12 +948,12 @@ void Application::initPubSub()
if (getSettings()->showAutomodInMentions)
{
getIApp()
getApp()
->getTwitch()
->getMentionsChannel()
->addMessage(p.first,
MessageContext::Original);
getIApp()
getApp()
->getTwitch()
->getMentionsChannel()
->addMessage(p.second,
@ -1124,14 +1164,7 @@ void Application::initSeventvEventAPI()
seventvEventAPI->start();
}
Application *getApp()
{
assert(Application::instance != nullptr);
return Application::instance;
}
IApplication *getIApp()
IApplication *getApp()
{
assert(IApplication::instance != nullptr);

View file

@ -1,6 +1,5 @@
#pragma once
#include "common/Singleton.hpp"
#include "debug/AssertInGuiThread.hpp"
#include "singletons/NativeMessaging.hpp"
@ -108,7 +107,6 @@ class Application : public IApplication
{
const Paths &paths_;
const Args &args_;
std::vector<std::unique_ptr<Singleton>> singletons_;
int argc_{};
char **argv_{};
@ -144,25 +142,25 @@ public:
friend void test();
private:
Theme *const themes{};
std::unique_ptr<Fonts> fonts{};
Emotes *const emotes{};
AccountController *const accounts{};
HotkeyController *const hotkeys{};
WindowManager *const windows{};
Toasts *const toasts{};
ImageUploader *const imageUploader{};
SeventvAPI *const seventvAPI{};
CrashHandler *const crashHandler{};
CommandController *const commands{};
NotificationController *const notifications{};
HighlightController *const highlights{};
std::unique_ptr<Theme> themes;
std::unique_ptr<Fonts> fonts;
std::unique_ptr<Emotes> emotes;
std::unique_ptr<AccountController> accounts;
std::unique_ptr<HotkeyController> hotkeys;
std::unique_ptr<WindowManager> windows;
std::unique_ptr<Toasts> toasts;
std::unique_ptr<ImageUploader> imageUploader;
std::unique_ptr<SeventvAPI> seventvAPI;
std::unique_ptr<CrashHandler> crashHandler;
std::unique_ptr<CommandController> commands;
std::unique_ptr<NotificationController> notifications;
std::unique_ptr<HighlightController> highlights;
std::unique_ptr<TwitchIrcServer> twitch;
FfzBadges *const ffzBadges{};
SeventvBadges *const seventvBadges{};
std::unique_ptr<FfzBadges> ffzBadges;
std::unique_ptr<SeventvBadges> seventvBadges;
std::unique_ptr<UserDataController> userData;
std::unique_ptr<ISoundController> sound;
TwitchLiveController *const twitchLiveController{};
std::unique_ptr<TwitchLiveController> twitchLiveController;
std::unique_ptr<PubSub> twitchPubSub;
std::unique_ptr<TwitchBadges> twitchBadges;
std::unique_ptr<ChatterinoBadges> chatterinoBadges;
@ -173,7 +171,7 @@ private:
std::unique_ptr<ILinkResolver> linkResolver;
std::unique_ptr<IStreamerMode> streamerMode;
#ifdef CHATTERINO_HAVE_PLUGINS
PluginController *const plugins{};
std::unique_ptr<PluginController> plugins;
#endif
public:
@ -227,36 +225,15 @@ public:
IStreamerMode *getStreamerMode() override;
private:
void addSingleton(Singleton *singleton);
void initPubSub();
void initBttvLiveUpdates();
void initSeventvEventAPI();
void initNm(const Paths &paths);
template <typename T,
typename = std::enable_if_t<std::is_base_of<Singleton, T>::value>>
T &emplace()
{
auto t = new T;
this->singletons_.push_back(std::unique_ptr<T>(t));
return *t;
}
template <typename T,
typename = std::enable_if_t<std::is_base_of<Singleton, T>::value>>
T &emplace(T *t)
{
this->singletons_.push_back(std::unique_ptr<T>(t));
return *t;
}
NativeMessagingServer nmServer{};
Updates &updates;
};
Application *getApp();
// Get an interface version of the Application class - should be preferred when possible for new code
IApplication *getIApp();
IApplication *getApp();
} // namespace chatterino

View file

@ -444,8 +444,6 @@ set(SOURCE_FILES
providers/twitch/api/Helix.cpp
providers/twitch/api/Helix.hpp
singletons/Badges.cpp
singletons/Badges.hpp
singletons/CrashHandler.cpp
singletons/CrashHandler.hpp
singletons/Emotes.cpp

View file

@ -131,7 +131,7 @@ namespace {
using namespace std::chrono_literals;
if (std::chrono::steady_clock::now() - signalsInitTime > 30s &&
getIApp()->getCrashHandler()->shouldRecover())
getApp()->getCrashHandler()->shouldRecover())
{
QProcess proc;

View file

@ -100,9 +100,9 @@ void Channel::addMessage(MessagePtr message, MessageContext context,
if (!isDoNotLogSet)
{
// Only log messages where the `DoNotLog` flag is not set
getIApp()->getChatLogger()->addMessage(this->name_, message,
this->platform_,
this->getCurrentStreamID());
getApp()->getChatLogger()->addMessage(this->name_, message,
this->platform_,
this->getCurrentStreamID());
}
}

View file

@ -56,7 +56,7 @@ bool useKeyring()
// Insecure storage:
QString insecurePath()
{
return combinePath(getIApp()->getPaths().settingsDirectory,
return combinePath(getApp()->getPaths().settingsDirectory,
"credentials.json");
}

View file

@ -1,31 +0,0 @@
#pragma once
namespace chatterino {
class Settings;
class Paths;
class Singleton
{
public:
Singleton() = default;
virtual ~Singleton() = default;
Singleton(const Singleton &) = delete;
Singleton &operator=(const Singleton &) = delete;
Singleton(Singleton &&) = delete;
Singleton &operator=(Singleton &&) = delete;
virtual void initialize(Settings &settings, const Paths &paths)
{
(void)(settings);
(void)(paths);
}
virtual void save()
{
}
};
} // namespace chatterino

View file

@ -59,7 +59,7 @@ void loadUncached(std::shared_ptr<NetworkData> &&data)
void loadCached(std::shared_ptr<NetworkData> &&data)
{
QFile cachedFile(getIApp()->getPaths().cacheDirectory() + "/" +
QFile cachedFile(getApp()->getPaths().cacheDirectory() + "/" +
data->getHash());
if (!cachedFile.exists() || !cachedFile.open(QIODevice::ReadOnly))

View file

@ -118,7 +118,7 @@ void NetworkTask::logReply()
void NetworkTask::writeToCache(const QByteArray &bytes) const
{
std::ignore = QtConcurrent::run([data = this->data_, bytes] {
QFile cachedFile(getIApp()->getPaths().cacheDirectory() + "/" +
QFile cachedFile(getApp()->getPaths().cacheDirectory() + "/" +
data->getHash());
if (cachedFile.open(QIODevice::WriteOnly))

View file

@ -47,7 +47,7 @@ AccountController::AccountController()
});
}
void AccountController::initialize(Settings &settings, const Paths &paths)
void AccountController::load()
{
this->twitch.load();
}

View file

@ -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;

View file

@ -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;

View file

@ -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);

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++)
{

View file

@ -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!");

View file

@ -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!");

View file

@ -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(

View file

@ -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(

View file

@ -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(

View file

@ -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);

View file

@ -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)

View file

@ -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())

View file

@ -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(

View file

@ -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(

View file

@ -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(

View file

@ -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(

View file

@ -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(

View file

@ -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())

View file

@ -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.");

View file

@ -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())

View file

@ -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(

View file

@ -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())

View file

@ -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!");

View file

@ -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)
{

View file

@ -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);

View file

@ -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);

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:

View file

@ -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);
});

View file

@ -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)

View file

@ -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

View file

@ -519,7 +519,7 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
break;
}
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
}
} // namespace chatterino

View file

@ -109,7 +109,7 @@ void UserHighlightModel::customRowSetData(
break;
}
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
}
// row into vector item

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

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.

View file

@ -32,7 +32,7 @@ bool isIgnoredMessage(IgnoredMessageParameters &&params)
{
auto sourceUserID = params.twitchUserID;
bool isBlocked = getIApp()
bool isBlocked = getApp()
->getAccounts()
->twitch.getCurrent()
->blockedUserIds()

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();

View file

@ -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);

View file

@ -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);

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?");

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;

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_;

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);

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;

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(

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

View file

@ -50,7 +50,7 @@ Frames::Frames(QList<Frame> &&frames)
DebugCount::increase("animated images");
this->gifTimerConnection_ =
getIApp()->getEmotes()->getGIFTimer().signal.connect([this] {
getApp()->getEmotes()->getGIFTimer().signal.connect([this] {
this->advance();
});
}
@ -67,7 +67,7 @@ Frames::Frames(QList<Frame> &&frames)
else
{
this->durationOffset_ = std::min<int>(
int(getIApp()->getEmotes()->getGIFTimer().position() % totalLength),
int(getApp()->getEmotes()->getGIFTimer().position() % totalLength),
60000);
}
this->processOffset();
@ -242,7 +242,7 @@ void assignFrames(std::weak_ptr<Image> weak, QList<Frame> parsed)
isPushQueued = true;
postToThread([] {
isPushQueued = false;
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
});
}
};

View file

@ -203,7 +203,7 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username,
MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)
: MessageBuilder()
{
auto current = getIApp()->getAccounts()->twitch.getCurrent();
auto current = getApp()->getAccounts()->twitch.getCurrent();
this->emplace<TimestampElement>();
this->message().flags.set(MessageFlag::System);
@ -676,7 +676,7 @@ void MessageBuilder::addLink(const linkparser::Parsed &parsedLink,
MessageElementFlag::Text, this->textColor_);
}
getIApp()->getLinkResolver()->resolve(el->linkInfo());
getApp()->getLinkResolver()->resolve(el->linkInfo());
}
void MessageBuilder::addIrcMessageText(const QString &text)
@ -686,7 +686,7 @@ void MessageBuilder::addIrcMessageText(const QString &text)
auto words = text.split(' ');
MessageColor defaultColorType = MessageColor::Text;
const auto &defaultColor =
defaultColorType.getColor(*getIApp()->getThemes());
defaultColorType.getColor(*getApp()->getThemes());
QColor textColor = defaultColor;
int fg = -1;
int bg = -1;
@ -728,7 +728,7 @@ void MessageBuilder::addIrcMessageText(const QString &text)
if (fg >= 0 && fg <= 98)
{
textColor = IRC_COLORS[fg];
getIApp()->getThemes()->normalizeColor(textColor);
getApp()->getThemes()->normalizeColor(textColor);
}
else
{
@ -768,7 +768,7 @@ void MessageBuilder::addIrcMessageText(const QString &text)
if (fg >= 0 && fg <= 98)
{
textColor = IRC_COLORS[fg];
getIApp()->getThemes()->normalizeColor(textColor);
getApp()->getThemes()->normalizeColor(textColor);
}
else
{
@ -810,7 +810,7 @@ void MessageBuilder::addIrcWord(const QString &text, const QColor &color,
bool addSpace)
{
this->textColor_ = color;
for (auto &variant : getIApp()->getEmotes()->getEmojis()->parse(text))
for (auto &variant : getApp()->getEmotes()->getEmojis()->parse(text))
{
boost::apply_visitor(
[&](auto &&arg) {

View file

@ -454,7 +454,7 @@ TextElement::TextElement(const QString &text, MessageElementFlags flags,
void TextElement::addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags)
{
auto *app = getIApp();
auto *app = getApp();
if (flags.hasAny(this->getFlags()))
{
@ -566,7 +566,7 @@ SingleLineTextElement::SingleLineTextElement(const QString &text,
void SingleLineTextElement::addToContainer(MessageLayoutContainer &container,
MessageElementFlags flags)
{
auto *app = getIApp();
auto *app = getApp();
if (flags.hasAny(this->getFlags()))
{

View file

@ -156,7 +156,7 @@ void SharedMessageBuilder::parseHighlights()
}
auto badges = SharedMessageBuilder::parseBadgeTag(this->tags);
auto [highlighted, highlightResult] = getIApp()->getHighlights()->check(
auto [highlighted, highlightResult] = getApp()->getHighlights()->check(
this->args, badges, this->message().loginName, this->originalMessage_,
this->message().flags);
@ -203,7 +203,7 @@ void SharedMessageBuilder::triggerHighlights(
const QString &channelName, bool playSound,
const std::optional<QUrl> &customSoundUrl, bool windowAlert)
{
if (getIApp()->getStreamerMode()->isEnabled() &&
if (getApp()->getStreamerMode()->isEnabled() &&
getSettings()->streamerModeMuteMentions)
{
// We are in streamer mode with muting mention sounds enabled. Do nothing.
@ -232,12 +232,12 @@ void SharedMessageBuilder::triggerHighlights(
{
soundUrl = getFallbackHighlightSound();
}
getIApp()->getSound()->play(soundUrl);
getApp()->getSound()->play(soundUrl);
}
if (windowAlert)
{
getIApp()->getWindows()->sendAlert();
getApp()->getWindows()->sendAlert();
}
}

View file

@ -88,7 +88,7 @@ bool MessageLayout::layout(int width, float scale, float imageScale,
this->currentLayoutWidth_ = width;
// check if layout state changed
const auto layoutGeneration = getIApp()->getWindows()->getGeneration();
const auto layoutGeneration = getApp()->getWindows()->getGeneration();
if (this->layoutState_ != layoutGeneration)
{
layoutRequired = true;
@ -166,7 +166,7 @@ void MessageLayout::actuallyLayout(int width, MessageElementFlags flags)
{
if (hideModerationActions ||
(getSettings()->streamerModeHideModActions &&
getIApp()->getStreamerMode()->isEnabled()))
getApp()->getStreamerMode()->isEnabled()))
{
continue;
}

View file

@ -48,7 +48,7 @@ void MessageLayoutContainer::beginLayout(int width, float scale,
this->imageScale_ = imageScale;
this->flags_ = flags;
auto mediumFontMetrics =
getIApp()->getFonts()->getFontMetrics(FontStyle::ChatMedium, scale);
getApp()->getFonts()->getFontMetrics(FontStyle::ChatMedium, scale);
this->textLineHeight_ = mediumFontMetrics.height();
this->spaceWidth_ = mediumFontMetrics.horizontalAdvance(' ');
this->dotdotdotWidth_ = mediumFontMetrics.horizontalAdvance("...");

View file

@ -1,4 +1,4 @@
#include "FfzBadges.hpp"
#include "providers/ffz/FfzBadges.hpp"
#include "common/network/NetworkRequest.hpp"
#include "common/network/NetworkResult.hpp"
@ -17,11 +17,6 @@
namespace chatterino {
void FfzBadges::initialize(Settings &settings, const Paths &paths)
{
this->load();
}
std::vector<FfzBadges::Badge> FfzBadges::getUserBadges(const UserId &id)
{
std::vector<Badge> badges;

View file

@ -1,7 +1,6 @@
#pragma once
#include "common/Aliases.hpp"
#include "common/Singleton.hpp"
#include "util/QStringHash.hpp"
#include "util/ThreadGuard.hpp"
@ -19,10 +18,9 @@ namespace chatterino {
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
class FfzBadges : public Singleton
class FfzBadges
{
public:
void initialize(Settings &settings, const Paths &paths) override;
FfzBadges() = default;
struct Badge {
@ -33,9 +31,9 @@ public:
std::vector<Badge> getUserBadges(const UserId &id);
std::optional<Badge> getBadge(int badgeID) const;
private:
void load();
private:
std::shared_mutex mutex_;
// userBadges points a user ID to the list of badges they have

View file

@ -22,7 +22,7 @@ namespace {
QString configPath()
{
return combinePath(getIApp()->getPaths().settingsDirectory, "irc.json");
return combinePath(getApp()->getPaths().settingsDirectory, "irc.json");
}
class Model : public SignalVectorModel<IrcServerData>

View file

@ -245,7 +245,7 @@ void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message)
if (highlighted && showInMentions)
{
getIApp()->getTwitch()->getMentionsChannel()->addMessage(
getApp()->getTwitch()->getMentionsChannel()->addMessage(
msg, MessageContext::Original);
}
}

View file

@ -1,7 +1,5 @@
#pragma once
#include "common/Singleton.hpp"
#include <functional>
class QString;
@ -11,7 +9,7 @@ namespace chatterino {
class NetworkResult;
class SeventvAPI : public Singleton
class SeventvAPI final
{
using ErrorCallback = std::function<void(const NetworkResult &)>;
template <typename... T>
@ -19,7 +17,7 @@ class SeventvAPI : public Singleton
public:
SeventvAPI() = default;
~SeventvAPI() override = default;
~SeventvAPI() = default;
SeventvAPI(const SeventvAPI &) = delete;
SeventvAPI(SeventvAPI &&) = delete;

View file

@ -1,7 +1,6 @@
#pragma once
#include "common/Aliases.hpp"
#include "common/Singleton.hpp"
#include "util/QStringHash.hpp"
#include <QJsonObject>
@ -16,7 +15,7 @@ namespace chatterino {
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
class SeventvBadges : public Singleton
class SeventvBadges
{
public:
// Return the badge, if any, that is assigned to the user

View file

@ -217,7 +217,7 @@ void SeventvEmotes::loadGlobalEmotes()
qCDebug(chatterinoSeventv) << "Loading 7TV Global Emotes";
getIApp()->getSeventvAPI()->getEmoteSet(
getApp()->getSeventvAPI()->getEmoteSet(
u"global"_s,
[this](const auto &json) {
QJsonArray parsedEmotes = json["emotes"].toArray();
@ -246,7 +246,7 @@ void SeventvEmotes::loadChannelEmotes(
qCDebug(chatterinoSeventv)
<< "Reloading 7TV Channel Emotes" << channelId << manualRefresh;
getIApp()->getSeventvAPI()->getUserByTwitchID(
getApp()->getSeventvAPI()->getUserByTwitchID(
channelId,
[callback = std::move(callback), channel, channelId,
manualRefresh](const auto &json) {
@ -405,7 +405,7 @@ void SeventvEmotes::getEmoteSet(
{
qCDebug(chatterinoSeventv) << "Loading 7TV Emote Set" << emoteSetId;
getIApp()->getSeventvAPI()->getEmoteSet(
getApp()->getSeventvAPI()->getEmoteSet(
emoteSetId,
[callback = std::move(successCallback), emoteSetId](const auto &json) {
auto parsedEmotes = json["emotes"].toArray();

View file

@ -348,7 +348,7 @@ void SeventvEventAPI::onUserUpdate(const Dispatch &dispatch)
void SeventvEventAPI::onCosmeticCreate(const CosmeticCreateDispatch &cosmetic)
{
auto *badges = getIApp()->getSeventvBadges();
auto *badges = getApp()->getSeventvBadges();
switch (cosmetic.kind)
{
case CosmeticKind::Badge: {
@ -363,7 +363,7 @@ void SeventvEventAPI::onCosmeticCreate(const CosmeticCreateDispatch &cosmetic)
void SeventvEventAPI::onEntitlementCreate(
const EntitlementCreateDeleteDispatch &entitlement)
{
auto *badges = getIApp()->getSeventvBadges();
auto *badges = getApp()->getSeventvBadges();
switch (entitlement.kind)
{
case CosmeticKind::Badge: {
@ -379,7 +379,7 @@ void SeventvEventAPI::onEntitlementCreate(
void SeventvEventAPI::onEntitlementDelete(
const EntitlementCreateDeleteDispatch &entitlement)
{
auto *badges = getIApp()->getSeventvBadges();
auto *badges = getApp()->getSeventvBadges();
switch (entitlement.kind)
{
case CosmeticKind::Badge: {

View file

@ -132,7 +132,7 @@ void updateReplyParticipatedStatus(const QVariantMap &tags,
bool isNew)
{
const auto &currentLogin =
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
getApp()->getAccounts()->twitch.getCurrent()->getUserName();
if (thread->subscribed())
{
@ -390,7 +390,7 @@ std::vector<MessagePtr> parseNoticeMessage(Communi::IrcNoticeMessage *message)
{
const auto linkColor = MessageColor(MessageColor::Link);
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
const auto curUser = getIApp()->getAccounts()->twitch.getCurrent();
const auto curUser = getApp()->getAccounts()->twitch.getCurrent();
const auto expirationText = QString("Login expired for user \"%1\"!")
.arg(curUser->getUserName());
const auto loginPromptText = QString("Try adding your account again.");
@ -692,7 +692,7 @@ void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
if (twitchChannel != nullptr)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (message->tag("user-id") == currentUser->getUserId())
{
auto badgesTag = message->tag("badges");
@ -736,7 +736,7 @@ void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
{
return;
}
auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(chanName);
auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(chanName);
auto *twitchChannel = dynamic_cast<TwitchChannel *>(chan.get());
if (!twitchChannel)
@ -798,7 +798,7 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
}
// get channel
auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(chanName);
auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(chanName);
if (chan->isEmpty())
{
@ -821,10 +821,10 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
chan->addOrReplaceTimeout(std::move(clearChat.message));
// refresh all
getIApp()->getWindows()->repaintVisibleChatWidgets(chan.get());
getApp()->getWindows()->repaintVisibleChatWidgets(chan.get());
if (getSettings()->hideModerated)
{
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
}
}
@ -843,7 +843,7 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message)
}
// get channel
auto chan = getIApp()->getTwitchAbstract()->getChannelOrEmpty(chanName);
auto chan = getApp()->getTwitchAbstract()->getChannelOrEmpty(chanName);
if (chan->isEmpty())
{
@ -875,7 +875,7 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
// set received emote-sets, used in TwitchAccount::loadUserstateEmotes
bool emoteSetsChanged = currentUser->setUserstateEmoteSets(
@ -892,7 +892,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
return;
}
auto c = getIApp()->getTwitchAbstract()->getChannelOrEmpty(channelName);
auto c = getApp()->getTwitchAbstract()->getChannelOrEmpty(channelName);
if (c->isEmpty())
{
return;
@ -927,7 +927,7 @@ void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handleGlobalUserStateMessage(
Communi::IrcMessage *message)
{
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
// set received emote-sets, this time used to initially load emotes
// NOTE: this should always return true unless we reconnect
@ -947,7 +947,7 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage)
args.isReceivedWhisper = true;
auto *c = getIApp()->getTwitch()->getWhispersChannel().get();
auto *c = getApp()->getTwitch()->getWhispersChannel().get();
TwitchMessageBuilder builder(
c, ircMessage, args,
@ -963,11 +963,11 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage)
MessagePtr message = builder.build();
builder.triggerHighlights();
getIApp()->getTwitch()->setLastUserThatWhisperedMe(builder.userName);
getApp()->getTwitch()->setLastUserThatWhisperedMe(builder.userName);
if (message->flags.has(MessageFlag::ShowInMentions))
{
getIApp()->getTwitch()->getMentionsChannel()->addMessage(
getApp()->getTwitch()->getMentionsChannel()->addMessage(
message, MessageContext::Original);
}
@ -979,13 +979,12 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage)
if (getSettings()->inlineWhispers &&
!(getSettings()->streamerModeSuppressInlineWhispers &&
getIApp()->getStreamerMode()->isEnabled()))
getApp()->getStreamerMode()->isEnabled()))
{
getIApp()->getTwitchAbstract()->forEachChannel(
[&message, overrideFlags](ChannelPtr channel) {
channel->addMessage(message, MessageContext::Repost,
overrideFlags);
});
getApp()->getTwitchAbstract()->forEachChannel([&message, overrideFlags](
ChannelPtr channel) {
channel->addMessage(message, MessageContext::Repost, overrideFlags);
});
}
}
@ -1118,7 +1117,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
{
// Notice wasn't targeted at a single channel, send to all twitch
// channels
getIApp()->getTwitch()->forEachChannelAndSpecialChannels(
getApp()->getTwitch()->forEachChannelAndSpecialChannels(
[msg](const auto &c) {
c->addMessage(msg, MessageContext::Original);
});
@ -1127,7 +1126,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
}
auto channel =
getIApp()->getTwitchAbstract()->getChannelOrEmpty(channelName);
getApp()->getTwitchAbstract()->getChannelOrEmpty(channelName);
if (channel->isEmpty())
{
@ -1210,7 +1209,7 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
{
auto channel = getIApp()->getTwitchAbstract()->getChannelOrEmpty(
auto channel = getApp()->getTwitchAbstract()->getChannelOrEmpty(
message->parameter(0).remove(0, 1));
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
@ -1220,7 +1219,7 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
}
if (message->nick() ==
getIApp()->getAccounts()->twitch.getCurrent()->getUserName())
getApp()->getAccounts()->twitch.getCurrent()->getUserName())
{
twitchChannel->addSystemMessage("joined channel");
twitchChannel->joined.invoke();
@ -1233,7 +1232,7 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
{
auto channel = getIApp()->getTwitchAbstract()->getChannelOrEmpty(
auto channel = getApp()->getTwitchAbstract()->getChannelOrEmpty(
message->parameter(0).remove(0, 1));
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
@ -1243,7 +1242,7 @@ void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
}
const auto selfAccountName =
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
getApp()->getAccounts()->twitch.getCurrent()->getUserName();
if (message->nick() != selfAccountName &&
getSettings()->showParts.getValue())
{
@ -1296,7 +1295,7 @@ void IrcMessageHandler::setSimilarityFlags(const MessagePtr &message,
{
bool isMyself =
message->loginName ==
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
getApp()->getAccounts()->twitch.getCurrent()->getUserName();
bool hideMyself = getSettings()->hideSimilarMyself;
if (isMyself && !hideMyself)

View file

@ -109,7 +109,7 @@ void TwitchAccount::loadBlocks()
this->ignoresUserIds_.clear();
getHelix()->loadBlocks(
getIApp()->getAccounts()->twitch.getCurrent()->userId_,
getApp()->getAccounts()->twitch.getCurrent()->userId_,
[this](const std::vector<HelixBlock> &blocks) {
assertInGuiThread();
@ -325,7 +325,7 @@ void TwitchAccount::loadUserstateEmotes(std::weak_ptr<Channel> weakChannel)
emoteSet->emotes.push_back(TwitchEmote{id, code});
auto emote = getIApp()
auto emote = getApp()
->getEmotes()
->getTwitchEmotes()
->getOrCreateEmote(id, code);
@ -493,7 +493,7 @@ void TwitchAccount::loadSeventvUserID()
return;
}
auto *seventv = getIApp()->getSeventvAPI();
auto *seventv = getApp()->getSeventvAPI();
if (!seventv)
{
qCWarning(chatterinoSeventv)

View file

@ -91,7 +91,7 @@ TwitchChannel::TwitchChannel(const QString &name)
qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened";
this->bSignals_.emplace_back(
getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
getApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
this->setMod(false);
this->refreshPubSub();
}));
@ -143,18 +143,18 @@ TwitchChannel::TwitchChannel(const QString &name)
TwitchChannel::~TwitchChannel()
{
getIApp()->getTwitch()->dropSeventvChannel(this->seventvUserID_,
this->seventvEmoteSetID_);
getApp()->getTwitch()->dropSeventvChannel(this->seventvUserID_,
this->seventvEmoteSetID_);
if (getIApp()->getTwitch()->getBTTVLiveUpdates())
if (getApp()->getTwitch()->getBTTVLiveUpdates())
{
getIApp()->getTwitch()->getBTTVLiveUpdates()->partChannel(
getApp()->getTwitch()->getBTTVLiveUpdates()->partChannel(
this->roomId());
}
if (getIApp()->getTwitch()->getSeventvEventAPI())
if (getApp()->getTwitch()->getSeventvEventAPI())
{
getIApp()->getTwitch()->getSeventvEventAPI()->unsubscribeTwitchChannel(
getApp()->getTwitch()->getSeventvEventAPI()->unsubscribeTwitchChannel(
this->roomId());
}
}
@ -332,7 +332,7 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
<< "] Channel point reward added:" << reward.id << ","
<< reward.title << "," << reward.isUserInputRequired;
auto *server = getIApp()->getTwitch();
auto *server = getApp()->getTwitch();
auto it = std::remove_if(
this->waitingRedemptions_.begin(), this->waitingRedemptions_.end(),
[&](const QueuedRedemption &msg) {
@ -426,7 +426,7 @@ void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate)
qCDebug(chatterinoTwitch).nospace().noquote()
<< "[TwitchChannel " << this->getName() << "] Online";
getIApp()->getNotifications()->notifyTwitchChannelLive({
getApp()->getNotifications()->notifyTwitchChannelLive({
.channelId = this->roomId(),
.channelName = this->getName(),
.displayName = this->getDisplayName(),
@ -452,7 +452,7 @@ void TwitchChannel::onLiveStatusChanged(bool isLive, bool isInitialUpdate)
&builder);
this->addMessage(builder.release(), MessageContext::Original);
getIApp()->getNotifications()->notifyTwitchChannelOffline(
getApp()->getNotifications()->notifyTwitchChannelOffline(
this->roomId());
}
};
@ -509,7 +509,7 @@ void TwitchChannel::showLoginMessage()
{
const auto linkColor = MessageColor(MessageColor::Link);
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
const auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
const auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
const auto expirationText =
QStringLiteral("You need to log in to send messages. You can link your "
"Twitch account");
@ -532,7 +532,7 @@ void TwitchChannel::showLoginMessage()
void TwitchChannel::roomIdChanged()
{
if (getIApp()->isTest())
if (getApp()->isTest())
{
return;
}
@ -544,7 +544,7 @@ void TwitchChannel::roomIdChanged()
this->refreshSevenTVChannelEmotes(false);
this->joinBttvChannel();
this->listenSevenTVCosmetics();
getIApp()->getTwitchLiveController()->add(
getApp()->getTwitchLiveController()->add(
std::dynamic_pointer_cast<TwitchChannel>(shared_from_this()));
}
@ -710,7 +710,7 @@ void TwitchChannel::setStaff(bool value)
bool TwitchChannel::isBroadcaster() const
{
auto *app = getIApp();
auto *app = getApp();
return this->getName() ==
app->getAccounts()->twitch.getCurrent()->getUserName();
@ -728,7 +728,7 @@ bool TwitchChannel::canReconnect() const
void TwitchChannel::reconnect()
{
getIApp()->getTwitchAbstract()->connect();
getApp()->getTwitchAbstract()->connect();
}
QString TwitchChannel::getCurrentStreamID() const
@ -753,7 +753,7 @@ void TwitchChannel::setRoomId(const QString &id)
{
*this->roomID_.access() = id;
// This is intended for tests and benchmarks. See comment in constructor.
if (!getIApp()->isTest())
if (!getApp()->isTest())
{
this->roomIdChanged();
this->loadRecentMessages();
@ -854,17 +854,17 @@ const QString &TwitchChannel::seventvEmoteSetID() const
void TwitchChannel::joinBttvChannel() const
{
if (getIApp()->getTwitch()->getBTTVLiveUpdates())
if (getApp()->getTwitch()->getBTTVLiveUpdates())
{
const auto currentAccount =
getIApp()->getAccounts()->twitch.getCurrent();
getApp()->getAccounts()->twitch.getCurrent();
QString userName;
if (currentAccount && !currentAccount->isAnon())
{
userName = currentAccount->getUserName();
}
getIApp()->getTwitch()->getBTTVLiveUpdates()->joinChannel(
this->roomId(), userName);
getApp()->getTwitch()->getBTTVLiveUpdates()->joinChannel(this->roomId(),
userName);
}
}
@ -1012,14 +1012,14 @@ void TwitchChannel::updateSeventvData(const QString &newUserID,
this->seventvUserID_ = newUserID;
this->seventvEmoteSetID_ = newEmoteSetID;
runInGuiThread([this, oldUserID, oldEmoteSetID]() {
if (getIApp()->getTwitch()->getSeventvEventAPI())
if (getApp()->getTwitch()->getSeventvEventAPI())
{
getIApp()->getTwitch()->getSeventvEventAPI()->subscribeUser(
getApp()->getTwitch()->getSeventvEventAPI()->subscribeUser(
this->seventvUserID_, this->seventvEmoteSetID_);
if (oldUserID || oldEmoteSetID)
{
getIApp()->getTwitch()->dropSeventvChannel(
getApp()->getTwitch()->dropSeventvChannel(
oldUserID.value_or(QString()),
oldEmoteSetID.value_or(QString()));
}
@ -1215,7 +1215,7 @@ void TwitchChannel::loadRecentMessages()
tc->addRecentChatter(msg->displayName);
}
getIApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(
getApp()->getTwitch()->getMentionsChannel()->fillInMissingMessages(
msgs);
},
[weak]() {
@ -1303,7 +1303,7 @@ void TwitchChannel::loadRecentMessagesReconnect()
void TwitchChannel::refreshPubSub()
{
if (getIApp()->isTest())
if (getApp()->isTest())
{
return;
}
@ -1314,17 +1314,17 @@ void TwitchChannel::refreshPubSub()
return;
}
auto currentAccount = getIApp()->getAccounts()->twitch.getCurrent();
auto currentAccount = getApp()->getAccounts()->twitch.getCurrent();
getIApp()->getTwitchPubSub()->setAccount(currentAccount);
getApp()->getTwitchPubSub()->setAccount(currentAccount);
getIApp()->getTwitchPubSub()->listenToChannelModerationActions(roomId);
getApp()->getTwitchPubSub()->listenToChannelModerationActions(roomId);
if (this->hasModRights())
{
getIApp()->getTwitchPubSub()->listenToAutomod(roomId);
getIApp()->getTwitchPubSub()->listenToLowTrustUsers(roomId);
getApp()->getTwitchPubSub()->listenToAutomod(roomId);
getApp()->getTwitchPubSub()->listenToLowTrustUsers(roomId);
}
getIApp()->getTwitchPubSub()->listenToChannelPointRewards(roomId);
getApp()->getTwitchPubSub()->listenToChannelPointRewards(roomId);
}
void TwitchChannel::refreshChatters()
@ -1350,7 +1350,7 @@ void TwitchChannel::refreshChatters()
// Get chatter list via helix api
getHelix()->getChatters(
this->roomId(),
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(),
getApp()->getAccounts()->twitch.getCurrent()->getUserId(),
MAX_CHATTERS_TO_FETCH,
[this, weak = weakOf<Channel>(this)](auto result) {
if (auto shared = weak.lock())
@ -1710,7 +1710,7 @@ std::vector<FfzBadges::Badge> TwitchChannel::ffzChannelBadges(
std::vector<FfzBadges::Badge> badges;
const auto *ffzBadges = getIApp()->getFfzBadges();
const auto *ffzBadges = getApp()->getFfzBadges();
for (const auto &badgeID : it->second)
{
@ -1769,7 +1769,7 @@ void TwitchChannel::updateSevenTVActivity()
QStringLiteral("https://7tv.io/v3/users/%1/presences");
const auto currentSeventvUserID =
getIApp()->getAccounts()->twitch.getCurrent()->getSeventvUserID();
getApp()->getAccounts()->twitch.getCurrent()->getSeventvUserID();
if (currentSeventvUserID.isEmpty())
{
return;
@ -1791,7 +1791,7 @@ void TwitchChannel::updateSevenTVActivity()
qCDebug(chatterinoSeventv) << "Sending activity in" << this->getName();
getIApp()->getSeventvAPI()->updatePresence(
getApp()->getSeventvAPI()->updatePresence(
this->roomId(), currentSeventvUserID,
[chan = weakOf<Channel>(this)]() {
const auto self =
@ -1811,9 +1811,9 @@ void TwitchChannel::updateSevenTVActivity()
void TwitchChannel::listenSevenTVCosmetics() const
{
if (getIApp()->getTwitch()->getSeventvEventAPI())
if (getApp()->getTwitch()->getSeventvEventAPI())
{
getIApp()->getTwitch()->getSeventvEventAPI()->subscribeTwitchChannel(
getApp()->getTwitch()->getSeventvEventAPI()->subscribeTwitchChannel(
this->roomId());
}
}

View file

@ -51,7 +51,7 @@ void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
{
.broadcasterID = broadcasterID,
.senderID =
getIApp()->getAccounts()->twitch.getCurrent()->getUserId(),
getApp()->getAccounts()->twitch.getCurrent()->getUserId(),
.message = message,
.replyParentMessageID = replyParentId,
},
@ -167,7 +167,7 @@ TwitchIrcServer::TwitchIrcServer()
void TwitchIrcServer::initialize()
{
getIApp()->getAccounts()->twitch.currentUserChanged.connect([this]() {
getApp()->getAccounts()->twitch.currentUserChanged.connect([this]() {
postToThread([this] {
this->connect();
});
@ -182,7 +182,7 @@ void TwitchIrcServer::initializeConnection(IrcConnection *connection,
ConnectionType type)
{
std::shared_ptr<TwitchAccount> account =
getIApp()->getAccounts()->twitch.getCurrent();
getApp()->getAccounts()->twitch.getCurrent();
qCDebug(chatterinoTwitch) << "logging in as" << account->getUserName();
@ -690,7 +690,7 @@ void TwitchIrcServer::setLastUserThatWhisperedMe(const QString &user)
void TwitchIrcServer::reloadBTTVGlobalEmotes()
{
getIApp()->getBttvEmotes()->loadEmotes();
getApp()->getBttvEmotes()->loadEmotes();
}
void TwitchIrcServer::reloadAllBTTVChannelEmotes()
@ -705,7 +705,7 @@ void TwitchIrcServer::reloadAllBTTVChannelEmotes()
void TwitchIrcServer::reloadFFZGlobalEmotes()
{
getIApp()->getFfzEmotes()->loadEmotes();
getApp()->getFfzEmotes()->loadEmotes();
}
void TwitchIrcServer::reloadAllFFZChannelEmotes()
@ -720,7 +720,7 @@ void TwitchIrcServer::reloadAllFFZChannelEmotes()
void TwitchIrcServer::reloadSevenTVGlobalEmotes()
{
getIApp()->getSeventvEmotes()->loadGlobalEmotes();
getApp()->getSeventvEmotes()->loadGlobalEmotes();
}
void TwitchIrcServer::reloadAllSevenTVChannelEmotes()

View file

@ -92,7 +92,7 @@ namespace {
const QString &originalMessage,
int messageOffset)
{
auto *app = getIApp();
auto *app = getApp();
if (!emote.contains(':'))
{
return;
@ -167,7 +167,7 @@ namespace {
}
if (auto globalBadge =
getIApp()->getTwitchBadges()->badge(badge.key_, badge.value_))
getApp()->getTwitchBadges()->badge(badge.key_, badge.value_))
{
return globalBadge;
}
@ -673,7 +673,7 @@ void TwitchMessageBuilder::addWords(
// 1. Add text before the emote
QString preText = word.left(currentTwitchEmote.start - cursor);
for (auto &variant :
getIApp()->getEmotes()->getEmojis()->parse(preText))
getApp()->getEmotes()->getEmojis()->parse(preText))
{
boost::apply_visitor(
[&](auto &&arg) {
@ -693,7 +693,7 @@ void TwitchMessageBuilder::addWords(
}
// split words
for (auto &variant : getIApp()->getEmotes()->getEmojis()->parse(word))
for (auto &variant : getApp()->getEmotes()->getEmojis()->parse(word))
{
boost::apply_visitor(
[&](auto &&arg) {
@ -937,7 +937,7 @@ void TwitchMessageBuilder::parseThread()
void TwitchMessageBuilder::parseUsernameColor()
{
const auto *userData = getIApp()->getUserData();
const auto *userData = getApp()->getUserData();
assert(userData != nullptr);
if (const auto &user = userData->getUser(this->userId_))
@ -991,7 +991,7 @@ void TwitchMessageBuilder::parseUsername()
}
// Update current user color if this is our message
auto currentUser = getIApp()->getAccounts()->twitch.getCurrent();
auto currentUser = getApp()->getAccounts()->twitch.getCurrent();
if (this->ircMessage->nick() == currentUser->getUserName())
{
currentUser->setColor(this->usernameColor_);
@ -1000,7 +1000,7 @@ void TwitchMessageBuilder::parseUsername()
void TwitchMessageBuilder::appendUsername()
{
auto *app = getIApp();
auto *app = getApp();
QString username = this->userName;
this->message().loginName = username;
@ -1256,7 +1256,7 @@ void TwitchMessageBuilder::processIgnorePhrases(
Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
{
auto *app = getIApp();
auto *app = getApp();
const auto *globalBttvEmotes = app->getBttvEmotes();
const auto *globalFfzEmotes = app->getFfzEmotes();
@ -1410,8 +1410,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
void TwitchMessageBuilder::appendChatterinoBadges()
{
if (auto badge =
getIApp()->getChatterinoBadges()->getBadge({this->userId_}))
if (auto badge = getApp()->getChatterinoBadges()->getBadge({this->userId_}))
{
this->emplace<BadgeElement>(*badge,
MessageElementFlag::BadgeChatterino);
@ -1421,7 +1420,7 @@ void TwitchMessageBuilder::appendChatterinoBadges()
void TwitchMessageBuilder::appendFfzBadges()
{
for (const auto &badge :
getIApp()->getFfzBadges()->getUserBadges({this->userId_}))
getApp()->getFfzBadges()->getUserBadges({this->userId_}))
{
this->emplace<FfzBadgeElement>(
badge.emote, MessageElementFlag::BadgeFfz, badge.color);
@ -1442,7 +1441,7 @@ void TwitchMessageBuilder::appendFfzBadges()
void TwitchMessageBuilder::appendSeventvBadges()
{
if (auto badge = getIApp()->getSeventvBadges()->getBadge({this->userId_}))
if (auto badge = getApp()->getSeventvBadges()->getBadge({this->userId_}))
{
this->emplace<BadgeElement>(*badge, MessageElementFlag::BadgeSevenTV);
}
@ -1585,7 +1584,7 @@ void TwitchMessageBuilder::appendChannelPointRewardMessage(
if (reward.id == "CELEBRATION")
{
const auto emotePtr =
getIApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote(
getApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote(
EmoteId{reward.emoteId}, EmoteName{reward.emoteName});
builder->emplace<EmoteElement>(emotePtr,
MessageElementFlag::ChannelPointReward,
@ -2060,7 +2059,7 @@ std::pair<MessagePtr, MessagePtr> TwitchMessageBuilder::makeAutomodMessage(
// Normally highlights would be checked & triggered during the builder parse steps
// and when the message is added to the channel
// We do this a bit weird since the message comes in from PubSub and not the normal message route
auto [highlighted, highlightResult] = getIApp()->getHighlights()->check(
auto [highlighted, highlightResult] = getApp()->getHighlights()->check(
{}, {}, action.target.login, action.message, message2->flags);
if (highlighted)
{
@ -2256,7 +2255,7 @@ std::pair<MessagePtr, MessagePtr> TwitchMessageBuilder::makeLowTrustUserMessage(
else
{
const auto emotePtr =
getIApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote(
getApp()->getEmotes()->getTwitchEmotes()->getOrCreateEmote(
EmoteId{fragment.emoteID}, EmoteName{fragment.text});
builder2.emplace<EmoteElement>(
emotePtr, MessageElementFlag::TwitchEmote, MessageColor::Text);

View file

@ -1,9 +0,0 @@
#include "Badges.hpp"
namespace chatterino {
Badges::Badges()
{
}
} // namespace chatterino

View file

@ -1,13 +0,0 @@
#pragma once
#include "common/Singleton.hpp"
namespace chatterino {
class Badges : public Singleton
{
public:
Badges();
};
} // namespace chatterino

View file

@ -130,10 +130,6 @@ using namespace std::string_literals;
CrashHandler::CrashHandler(const Paths &paths_)
: paths(paths_)
{
}
void CrashHandler::initialize(Settings & /*settings*/, const Paths &paths_)
{
auto optSettings = readRecoverySettings(paths);
if (optSettings)

View file

@ -1,7 +1,5 @@
#pragma once
#include "common/Singleton.hpp"
#include <QtGlobal>
#ifdef CHATTERINO_WITH_CRASHPAD
@ -15,7 +13,7 @@ namespace chatterino {
class Args;
class Paths;
class CrashHandler : public Singleton
class CrashHandler
{
const Paths &paths;
@ -30,8 +28,6 @@ public:
/// Sets and saves whether Chatterino should restart on a crash
void saveShouldRecover(bool value);
void initialize(Settings &settings, const Paths &paths) override;
private:
bool shouldRecover_ = false;
};

View file

@ -3,19 +3,10 @@
namespace chatterino {
Emotes::Emotes()
{
}
void Emotes::initialize(Settings &settings, const Paths &paths)
{
this->emojis.load();
this->gifTimer.initialize();
}
bool Emotes::isIgnoredEmote(const QString &)
{
return false;
}
} // namespace chatterino

View file

@ -1,15 +1,11 @@
#pragma once
#include "common/Singleton.hpp"
#include "providers/emoji/Emojis.hpp"
#include "providers/twitch/TwitchEmotes.hpp"
#include "singletons/helper/GifTimer.hpp"
namespace chatterino {
class Settings;
class Paths;
class IEmotes
{
public:
@ -20,15 +16,11 @@ public:
virtual GIFTimer &getGIFTimer() = 0;
};
class Emotes final : public IEmotes, public Singleton
class Emotes final : public IEmotes
{
public:
Emotes();
void initialize(Settings &settings, const Paths &paths) override;
bool isIgnoredEmote(const QString &emote);
ITwitchEmotes *getTwitchEmotes() final
{
return &this->twitch;

View file

@ -54,7 +54,7 @@ void ImageUploader::logToFile(const QString &originalFilePath,
{
const QString logFileName =
combinePath((getSettings()->logPath.getValue().isEmpty()
? getIApp()->getPaths().messageLogDirectory
? getApp()->getPaths().messageLogDirectory
: getSettings()->logPath),
"ImageUploader.json");
@ -123,10 +123,6 @@ QString getLinkFromResponse(NetworkResult response, QString pattern)
return pattern;
}
void ImageUploader::save()
{
}
void ImageUploader::sendImageUploadRequest(RawImageData imageData,
ChannelPtr channel,
QPointer<ResizingTextEdit> textEdit)

View file

@ -1,7 +1,5 @@
#pragma once
#include "common/Singleton.hpp"
#include <QMimeData>
#include <QMutex>
#include <QString>
@ -22,7 +20,7 @@ struct RawImageData {
QString filePath;
};
class ImageUploader final : public Singleton
class ImageUploader final
{
public:
/**
@ -33,7 +31,6 @@ public:
std::pair<std::queue<RawImageData>, QString> getImages(
const QMimeData *source) const;
void save() override;
void upload(std::queue<RawImageData> images, ChannelPtr channel,
QPointer<ResizingTextEdit> outputTextEdit);

View file

@ -238,11 +238,10 @@ void NativeMessagingServer::ReceiverThread::handleSelect(
postToThread([=] {
if (!name.isEmpty())
{
auto channel =
getIApp()->getTwitchAbstract()->getOrAddChannel(name);
if (getIApp()->getTwitch()->getWatchingChannel().get() != channel)
auto channel = getApp()->getTwitchAbstract()->getOrAddChannel(name);
if (getApp()->getTwitch()->getWatchingChannel().get() != channel)
{
getIApp()->getTwitch()->setWatchingChannel(channel);
getApp()->getTwitch()->setWatchingChannel(channel);
}
}
@ -253,7 +252,7 @@ void NativeMessagingServer::ReceiverThread::handleSelect(
if (!name.isEmpty())
{
window->setChannel(
getIApp()->getTwitchAbstract()->getOrAddChannel(name));
getApp()->getTwitchAbstract()->getOrAddChannel(name));
}
#endif
}
@ -305,7 +304,7 @@ void NativeMessagingServer::syncChannels(const QJsonArray &twitchChannels)
}
// the deduping is done on the extension side
updated.emplace_back(
getIApp()->getTwitchAbstract()->getOrAddChannel(name));
getApp()->getTwitchAbstract()->getOrAddChannel(name));
}
// This will destroy channels that aren't used anymore.

View file

@ -74,7 +74,7 @@ bool isBroadcasterSoftwareActive()
shouldShowTimeoutWarning = false;
postToThread([] {
getIApp()->getTwitchAbstract()->addGlobalSystemMessage(
getApp()->getTwitchAbstract()->addGlobalSystemMessage(
"Streamer Mode is set to Automatic, but pgrep timed "
"out. This can happen if your system lagged at the "
"wrong moment. If Streamer Mode continues to not work, "
@ -94,7 +94,7 @@ bool isBroadcasterSoftwareActive()
shouldShowWarning = false;
postToThread([] {
getIApp()->getTwitchAbstract()->addGlobalSystemMessage(
getApp()->getTwitchAbstract()->addGlobalSystemMessage(
"Streamer Mode is set to Automatic, but pgrep is "
"missing. "
"Install it to fix the issue or set Streamer Mode to "

View file

@ -282,7 +282,7 @@ bool Theme::isSystemTheme() const
return this->themeName == u"System"_s;
}
void Theme::initialize(Settings &settings, const Paths &paths)
Theme::Theme(const Paths &paths)
{
this->themeName.connect(
[this](auto themeName) {
@ -307,7 +307,7 @@ void Theme::initialize(Settings &settings, const Paths &paths)
if (this->isSystemTheme())
{
this->update();
getIApp()->getWindows()->forceLayoutChannelViews();
getApp()->getWindows()->forceLayoutChannelViews();
}
});
#endif
@ -597,7 +597,7 @@ void Theme::normalizeColor(QColor &color) const
Theme *getTheme()
{
return getIApp()->getThemes();
return getApp()->getThemes();
}
} // namespace chatterino

View file

@ -1,7 +1,7 @@
#pragma once
#include "common/ChatterinoSetting.hpp"
#include "common/Singleton.hpp"
#include "singletons/Paths.hpp"
#include "util/RapidJsonSerializeQString.hpp"
#include <pajlada/settings/setting.hpp>
@ -33,7 +33,7 @@ struct ThemeDescriptor {
bool custom{};
};
class Theme final : public Singleton
class Theme final
{
public:
static const std::vector<ThemeDescriptor> builtInThemes;
@ -43,7 +43,7 @@ public:
static const int AUTO_RELOAD_INTERVAL_MS = 500;
void initialize(Settings &settings, const Paths &paths) final;
Theme(const Paths &paths);
bool isLightTheme() const;
bool isSystemTheme() const;

View file

@ -35,7 +35,7 @@ using namespace literals;
QString avatarFilePath(const QString &channelName)
{
// TODO: cleanup channel (to be used as a file) and use combinePath
return getIApp()->getPaths().twitchProfileAvatars % '/' % channelName %
return getApp()->getPaths().twitchProfileAvatars % '/' % channelName %
u".png";
}
@ -74,7 +74,7 @@ bool Toasts::isEnabled()
{
#ifdef Q_OS_WIN
return WinToast::isCompatible() && getSettings()->notificationToast &&
!(getIApp()->getStreamerMode()->isEnabled() &&
!(getApp()->getStreamerMode()->isEnabled() &&
getSettings()->streamerModeSuppressLiveNotifications);
#else
return false;

View file

@ -1,7 +1,5 @@
#pragma once
#include "common/Singleton.hpp"
#include <pajlada/settings/setting.hpp>
#include <QString>
@ -16,7 +14,7 @@ enum class ToastReaction {
DontOpen = 3
};
class Toasts final : public Singleton
class Toasts final
{
public:
void sendChannelNotification(const QString &channelName,

View file

@ -118,7 +118,7 @@ WindowManager::WindowManager(const Paths &paths)
this->saveTimer->setSingleShot(true);
QObject::connect(this->saveTimer, &QTimer::timeout, [] {
getIApp()->getWindows()->save();
getApp()->getWindows()->save();
});
}
@ -341,21 +341,18 @@ void WindowManager::setEmotePopupBounds(QRect bounds)
}
}
void WindowManager::initialize(Settings &settings, const Paths &paths)
void WindowManager::initialize(Settings &settings)
{
(void)paths;
assertInGuiThread();
// We can safely ignore this signal connection since both Themes and WindowManager
// share the Application state lifetime
// NOTE: APPLICATION_LIFETIME
std::ignore =
getIApp()->getThemes()->repaintVisibleChatWidgets_.connect([this] {
getApp()->getThemes()->repaintVisibleChatWidgets_.connect([this] {
this->repaintVisibleChatWidgets();
});
assert(!this->initialized_);
{
WindowLayout windowLayout;
@ -368,7 +365,7 @@ void WindowManager::initialize(Settings &settings, const Paths &paths)
windowLayout = this->loadWindowLayoutFromFile();
}
auto desired = getIApp()->getArgs().activateChannel;
auto desired = getApp()->getArgs().activateChannel;
if (desired)
{
windowLayout.activateOrAddChannel(desired->provider, desired->name);
@ -428,8 +425,6 @@ void WindowManager::initialize(Settings &settings, const Paths &paths)
settings.boldUsernames.connect([this](auto, auto) {
this->forceLayoutChannelViews();
});
this->initialized_ = true;
}
void WindowManager::save()
@ -687,28 +682,28 @@ IndirectChannel WindowManager::decodeChannel(const SplitDescriptor &descriptor)
if (descriptor.type_ == "twitch")
{
return getIApp()->getTwitchAbstract()->getOrAddChannel(
return getApp()->getTwitchAbstract()->getOrAddChannel(
descriptor.channelName_);
}
else if (descriptor.type_ == "mentions")
{
return getIApp()->getTwitch()->getMentionsChannel();
return getApp()->getTwitch()->getMentionsChannel();
}
else if (descriptor.type_ == "watching")
{
return getIApp()->getTwitch()->getWatchingChannel();
return getApp()->getTwitch()->getWatchingChannel();
}
else if (descriptor.type_ == "whispers")
{
return getIApp()->getTwitch()->getWhispersChannel();
return getApp()->getTwitch()->getWhispersChannel();
}
else if (descriptor.type_ == "live")
{
return getIApp()->getTwitch()->getLiveChannel();
return getApp()->getTwitch()->getLiveChannel();
}
else if (descriptor.type_ == "automod")
{
return getIApp()->getTwitch()->getAutomodChannel();
return getApp()->getTwitch()->getAutomodChannel();
}
else if (descriptor.type_ == "irc")
{
@ -717,7 +712,7 @@ IndirectChannel WindowManager::decodeChannel(const SplitDescriptor &descriptor)
}
else if (descriptor.type_ == "misc")
{
return getIApp()->getTwitchAbstract()->getChannelOrEmpty(
return getApp()->getTwitchAbstract()->getChannelOrEmpty(
descriptor.channelName_);
}

View file

@ -1,7 +1,6 @@
#pragma once
#include "common/FlagsEnum.hpp"
#include "common/Singleton.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include <pajlada/settings/settinglistener.hpp>
@ -32,13 +31,13 @@ enum class WindowType;
enum class SettingsDialogPreference;
class FramelessEmbedWindow;
class WindowManager final : public Singleton
class WindowManager final
{
public:
static const QString WINDOW_LAYOUT_FILENAME;
explicit WindowManager(const Paths &paths);
~WindowManager() override;
~WindowManager();
WindowManager(const WindowManager &) = delete;
WindowManager(WindowManager &&) = delete;
@ -102,8 +101,9 @@ public:
QRect emotePopupBounds() const;
void setEmotePopupBounds(QRect bounds);
void initialize(Settings &settings, const Paths &paths) override;
void save() override;
// Set up some final signals & actually show the windows
void initialize(Settings &settings);
void save();
void closeAll();
int getGeneration() const;
@ -151,7 +151,6 @@ private:
// Contains the full path to the window layout file, e.g. /home/pajlada/.local/share/Chatterino/Settings/window-layout.json
const QString windowLayoutFilePath;
bool initialized_ = false;
bool shuttingDown_ = false;
QRect emotePopupBounds_;

View file

@ -31,7 +31,7 @@ void GIFTimer::initialize()
this->position_ += GIF_FRAME_LENGTH;
this->signal.invoke();
getIApp()->getWindows()->repaintGifEmotes();
getApp()->getWindows()->repaintGifEmotes();
});
}

View file

@ -88,7 +88,7 @@ LoggingChannel::LoggingChannel(QString _channelName, QString _platform)
getSettings()->logPath.connect([this](const QString &logPath, auto) {
this->baseDirectory = logPath.isEmpty()
? getIApp()->getPaths().messageLogDirectory
? getApp()->getPaths().messageLogDirectory
: logPath;
this->openLogFile();
});

View file

@ -41,7 +41,7 @@ void initUpdateButton(Button &button,
}
break;
case UpdateDialog::Install: {
getIApp()->getUpdates().installUpdates();
getApp()->getUpdates().installUpdates();
}
break;
}
@ -53,17 +53,17 @@ void initUpdateButton(Button &button,
// update image when state changes
auto updateChange = [&button](auto) {
button.setVisible(getIApp()->getUpdates().shouldShowUpdateButton());
button.setVisible(getApp()->getUpdates().shouldShowUpdateButton());
const auto *imageUrl = getIApp()->getUpdates().isError()
const auto *imageUrl = getApp()->getUpdates().isError()
? ":/buttons/updateError.png"
: ":/buttons/update.png";
button.setPixmap(QPixmap(imageUrl));
};
updateChange(getIApp()->getUpdates().getStatus());
updateChange(getApp()->getUpdates().getStatus());
signalHolder.managedConnect(getIApp()->getUpdates().statusUpdated,
signalHolder.managedConnect(getApp()->getUpdates().statusUpdated,
[updateChange](auto status) {
updateChange(status);
});

View file

@ -183,7 +183,7 @@ void openStreamlinkForChannel(const QString &channel)
{
static const QString INFO_TEMPLATE("Opening %1 in Streamlink ...");
auto *currentPage = dynamic_cast<SplitContainer *>(getIApp()
auto *currentPage = dynamic_cast<SplitContainer *>(getApp()
->getWindows()
->getMainWindow()
.getNotebook()

View file

@ -18,7 +18,7 @@ namespace chatterino {
BaseWidget::BaseWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
, theme(getIApp()->getThemes())
, theme(getApp()->getThemes())
{
this->signalHolder_.managedConnect(this->theme->updated, [this]() {
this->themeChangedEvent();

View file

@ -712,7 +712,7 @@ void BaseWindow::resizeEvent(QResizeEvent *)
// Queue up save because: Window resized
if (!flags_.has(DisableLayoutSave))
{
getIApp()->getWindows()->queueSave();
getApp()->getWindows()->queueSave();
}
#ifdef USEWINSDK
@ -727,7 +727,7 @@ void BaseWindow::moveEvent(QMoveEvent *event)
#ifdef CHATTERINO
if (!flags_.has(DisableLayoutSave))
{
getIApp()->getWindows()->queueSave();
getApp()->getWindows()->queueSave();
}
#endif
@ -909,7 +909,7 @@ void BaseWindow::scaleChangedEvent(float scale)
#endif
this->setFont(
getIApp()->getFonts()->getFont(FontStyle::UiTabs, this->scale()));
getApp()->getFonts()->getFont(FontStyle::UiTabs, this->scale()));
}
void BaseWindow::paintEvent(QPaintEvent *)

Some files were not shown because too many files have changed in this diff Show more