2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
|
|
|
|
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
|
|
|
#include "controllers/commands/CommandController.hpp"
|
|
|
|
#include "controllers/highlights/HighlightController.hpp"
|
|
|
|
#include "controllers/ignores/IgnoreController.hpp"
|
|
|
|
#include "controllers/taggedusers/TaggedUsersController.hpp"
|
|
|
|
#include "providers/twitch/Pubsub.hpp"
|
|
|
|
#include "providers/twitch/TwitchServer.hpp"
|
|
|
|
#include "singletons/EmoteManager.hpp"
|
|
|
|
#include "singletons/FontManager.hpp"
|
|
|
|
#include "singletons/LoggingManager.hpp"
|
|
|
|
#include "singletons/NativeMessagingManager.hpp"
|
|
|
|
#include "singletons/PathManager.hpp"
|
|
|
|
#include "singletons/ResourceManager.hpp"
|
|
|
|
#include "singletons/SettingsManager.hpp"
|
|
|
|
#include "singletons/ThemeManager.hpp"
|
|
|
|
#include "singletons/WindowManager.hpp"
|
|
|
|
#include "util/PostToThread.hpp"
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
#include <atomic>
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
namespace chatterino {
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool isBigEndian()
|
|
|
|
{
|
|
|
|
int test = 1;
|
2018-05-24 15:42:06 +02:00
|
|
|
char *p = reinterpret_cast<char *>(&test);
|
2018-04-27 22:11:19 +02:00
|
|
|
|
|
|
|
return p[0] == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
static std::atomic<bool> isAppConstructed{false};
|
|
|
|
static std::atomic<bool> isAppInitialized{false};
|
|
|
|
|
|
|
|
static Application *staticApp = nullptr;
|
|
|
|
|
2017-06-26 16:41:20 +02:00
|
|
|
// this class is responsible for handling the workflow of Chatterino
|
|
|
|
// It will create the instances of the major classes, and connect their signals to each other
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
Application::Application(int _argc, char **_argv)
|
|
|
|
: argc(_argc)
|
|
|
|
, argv(_argv)
|
2017-06-13 21:13:58 +02:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
}
|
2018-04-09 22:59:19 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
void Application::construct()
|
|
|
|
{
|
|
|
|
assert(isAppConstructed == false);
|
|
|
|
isAppConstructed = true;
|
|
|
|
|
|
|
|
// 1. Instantiate all classes
|
2018-06-26 17:06:17 +02:00
|
|
|
this->settings = new chatterino::SettingManager;
|
|
|
|
this->paths = chatterino::PathManager::getInstance();
|
|
|
|
this->themes = new chatterino::ThemeManager;
|
|
|
|
this->windows = new chatterino::WindowManager;
|
|
|
|
this->logging = new chatterino::LoggingManager;
|
|
|
|
this->commands = new CommandController;
|
|
|
|
this->highlights = new HighlightController;
|
|
|
|
this->ignores = new IgnoreController;
|
|
|
|
this->taggedUsers = new TaggedUsersController;
|
|
|
|
this->accounts = new AccountController;
|
|
|
|
this->emotes = new chatterino::EmoteManager;
|
|
|
|
this->fonts = new chatterino::FontManager;
|
|
|
|
this->resources = new chatterino::ResourceManager;
|
|
|
|
|
|
|
|
this->twitch.server = new TwitchServer;
|
|
|
|
this->twitch.pubsub = new PubSub;
|
2018-04-27 22:11:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Application::instantiate(int argc, char **argv)
|
|
|
|
{
|
|
|
|
assert(staticApp == nullptr);
|
2017-12-31 22:58:35 +01:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
staticApp = new Application(argc, argv);
|
|
|
|
}
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
void Application::initialize()
|
|
|
|
{
|
|
|
|
assert(isAppInitialized == false);
|
|
|
|
isAppInitialized = true;
|
2018-01-05 02:23:49 +01:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
// 2. Initialize/load classes
|
2018-04-28 15:20:18 +02:00
|
|
|
this->settings->initialize();
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-04-28 15:20:18 +02:00
|
|
|
this->settings->load();
|
2018-04-29 23:25:49 +02:00
|
|
|
this->commands->load();
|
2018-05-31 16:02:20 +02:00
|
|
|
this->logging->initialize();
|
2018-05-24 10:03:07 +02:00
|
|
|
this->windows->initialize();
|
2017-12-14 00:25:06 +01:00
|
|
|
|
2018-05-06 14:01:02 +02:00
|
|
|
this->resources->initialize();
|
|
|
|
|
2018-05-06 00:32:45 +02:00
|
|
|
this->highlights->initialize();
|
2018-05-13 19:24:32 +02:00
|
|
|
this->ignores->initialize();
|
2018-05-06 00:32:45 +02:00
|
|
|
|
2018-05-06 14:36:21 +02:00
|
|
|
this->emotes->initialize();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
this->accounts->load();
|
2017-07-28 19:46:53 +02:00
|
|
|
|
2018-04-28 15:20:18 +02:00
|
|
|
this->twitch.server->initialize();
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
// XXX
|
2018-04-27 22:11:19 +02:00
|
|
|
this->settings->updateWordTypeMask();
|
2018-04-12 00:33:55 +02:00
|
|
|
|
2018-06-24 14:03:26 +02:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#ifdef QT_DEBUG
|
|
|
|
#ifdef C_DEBUG_NM
|
|
|
|
this->nativeMessaging->registerHost();
|
|
|
|
this->nativeMessaging->openGuiMessageQueue();
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
this->nativeMessaging->registerHost();
|
2018-04-27 22:11:19 +02:00
|
|
|
this->nativeMessaging->openGuiMessageQueue();
|
2018-06-24 14:03:26 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
this->twitch.pubsub->signals_.whisper.sent.connect([](const auto &msg) {
|
2018-06-26 17:06:17 +02:00
|
|
|
Log("WHISPER SENT LOL"); //
|
2018-04-15 15:09:31 +02:00
|
|
|
});
|
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
this->twitch.pubsub->signals_.whisper.received.connect([](const auto &msg) {
|
2018-06-26 17:06:17 +02:00
|
|
|
Log("WHISPER RECEIVED LOL"); //
|
2018-04-15 15:09:31 +02:00
|
|
|
});
|
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
this->twitch.pubsub->signals_.moderation.chatCleared.connect([this](const auto &action) {
|
2018-04-29 13:24:37 +02:00
|
|
|
auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID);
|
|
|
|
if (chan->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString text = QString("%1 cleared the chat").arg(action.source.name);
|
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
auto msg = chatterino::Message::createSystemMessage(text);
|
|
|
|
postToThread([chan, msg] { chan->addMessage(msg); });
|
2018-04-15 15:09:31 +02:00
|
|
|
});
|
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
this->twitch.pubsub->signals_.moderation.modeChanged.connect([this](const auto &action) {
|
2018-04-29 13:24:37 +02:00
|
|
|
auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID);
|
|
|
|
if (chan->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
QString text = QString("%1 turned %2 %3 mode") //
|
|
|
|
.arg(action.source.name)
|
|
|
|
.arg(action.state == ModeChangedAction::State::On ? "on" : "off")
|
|
|
|
.arg(action.getModeName());
|
2018-04-29 13:24:37 +02:00
|
|
|
|
|
|
|
if (action.duration > 0) {
|
|
|
|
text.append(" (" + QString::number(action.duration) + " seconds)");
|
|
|
|
}
|
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
auto msg = chatterino::Message::createSystemMessage(text);
|
|
|
|
postToThread([chan, msg] { chan->addMessage(msg); });
|
2018-04-15 15:09:31 +02:00
|
|
|
});
|
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
this->twitch.pubsub->signals_.moderation.moderationStateChanged.connect(
|
|
|
|
[this](const auto &action) {
|
|
|
|
auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID);
|
|
|
|
if (chan->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
QString text;
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
if (action.modded) {
|
|
|
|
text = QString("%1 modded %2").arg(action.source.name, action.target.name);
|
|
|
|
} else {
|
|
|
|
text = QString("%1 unmodded %2").arg(action.source.name, action.target.name);
|
|
|
|
}
|
2018-04-29 13:24:37 +02:00
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
auto msg = chatterino::Message::createSystemMessage(text);
|
|
|
|
postToThread([chan, msg] { chan->addMessage(msg); });
|
|
|
|
});
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
this->twitch.pubsub->signals_.moderation.userBanned.connect([&](const auto &action) {
|
2018-04-28 15:20:18 +02:00
|
|
|
auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID);
|
2018-04-22 15:47:39 +02:00
|
|
|
|
|
|
|
if (chan->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
auto msg = chatterino::Message::createTimeoutMessage(action);
|
|
|
|
msg->flags |= chatterino::Message::PubSub;
|
2018-04-22 15:47:39 +02:00
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
postToThread([chan, msg] { chan->addOrReplaceTimeout(msg); });
|
2018-04-15 15:09:31 +02:00
|
|
|
});
|
|
|
|
|
2018-06-26 17:42:35 +02:00
|
|
|
this->twitch.pubsub->signals_.moderation.userUnbanned.connect([&](const auto &action) {
|
2018-04-28 15:20:18 +02:00
|
|
|
auto chan = this->twitch.server->getChannelOrEmptyByID(action.roomID);
|
2018-04-27 18:35:31 +02:00
|
|
|
|
|
|
|
if (chan->isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
auto msg = chatterino::Message::createUntimeoutMessage(action);
|
2018-04-27 18:35:31 +02:00
|
|
|
|
2018-06-26 17:06:17 +02:00
|
|
|
postToThread([chan, msg] { chan->addMessage(msg); });
|
2018-04-15 15:09:31 +02:00
|
|
|
});
|
|
|
|
|
2018-04-28 16:07:18 +02:00
|
|
|
this->twitch.pubsub->start();
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
auto RequestModerationActions = [=]() {
|
2018-04-28 16:07:18 +02:00
|
|
|
this->twitch.pubsub->unlistenAllModerationActions();
|
2018-04-15 15:09:31 +02:00
|
|
|
// TODO(pajlada): Unlisten to all authed topics instead of only moderation topics
|
2018-04-28 15:48:40 +02:00
|
|
|
// this->twitch.pubsub->UnlistenAllAuthedTopics();
|
2018-04-15 15:09:31 +02:00
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
this->twitch.pubsub->listenToWhispers(this->accounts->twitch.getCurrent()); //
|
2018-04-15 15:09:31 +02:00
|
|
|
};
|
|
|
|
|
2018-05-26 20:26:25 +02:00
|
|
|
this->accounts->twitch.currentUserChanged.connect(RequestModerationActions);
|
2018-04-15 15:09:31 +02:00
|
|
|
|
|
|
|
RequestModerationActions();
|
2017-06-13 21:13:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int Application::run(QApplication &qtApp)
|
|
|
|
{
|
|
|
|
// Start connecting to the IRC Servers (Twitch only for now)
|
2018-04-28 15:20:18 +02:00
|
|
|
this->twitch.server->connect();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
|
|
|
// Show main window
|
2018-04-27 22:11:19 +02:00
|
|
|
this->windows->getMainWindow().show();
|
2017-06-13 21:13:58 +02:00
|
|
|
|
|
|
|
return qtApp.exec();
|
|
|
|
}
|
|
|
|
|
2017-12-22 14:44:31 +01:00
|
|
|
void Application::save()
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
this->windows->save();
|
|
|
|
|
2018-04-29 23:25:49 +02:00
|
|
|
this->commands->save();
|
2018-04-27 22:11:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Application *getApp()
|
|
|
|
{
|
|
|
|
assert(staticApp != nullptr);
|
2018-01-05 02:38:00 +01:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
return staticApp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appInitialized()
|
|
|
|
{
|
|
|
|
return isAppInitialized;
|
2017-12-22 14:44:31 +01:00
|
|
|
}
|
|
|
|
|
2017-06-13 21:13:58 +02:00
|
|
|
} // namespace chatterino
|