chore: remove Singleton & replace getIApp with getApp (#5514)
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
#include "Badges.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
Badges::Badges()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Singleton.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Badges : public Singleton
|
||||
{
|
||||
public:
|
||||
Badges();
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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_);
|
||||
}
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -31,7 +31,7 @@ void GIFTimer::initialize()
|
||||
|
||||
this->position_ += GIF_FRAME_LENGTH;
|
||||
this->signal.invoke();
|
||||
getIApp()->getWindows()->repaintGifEmotes();
|
||||
getApp()->getWindows()->repaintGifEmotes();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user