mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
started to refactor Application
This commit is contained in:
parent
6a418e6e59
commit
c609a9fd37
|
@ -36,6 +36,8 @@ Application::Application(int _argc, char **_argv)
|
||||||
: argc_(_argc)
|
: argc_(_argc)
|
||||||
, argv_(_argv)
|
, argv_(_argv)
|
||||||
{
|
{
|
||||||
|
getSettings()->initialize();
|
||||||
|
getSettings()->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::construct()
|
void Application::construct()
|
||||||
|
@ -45,23 +47,24 @@ void Application::construct()
|
||||||
|
|
||||||
// 1. Instantiate all classes
|
// 1. Instantiate all classes
|
||||||
this->settings = getSettings();
|
this->settings = getSettings();
|
||||||
this->paths = Paths::getInstance();
|
this->paths = getPaths();
|
||||||
|
|
||||||
this->themes = new Theme;
|
this->addSingleton(this->themes = new Theme);
|
||||||
this->windows = new WindowManager;
|
this->addSingleton(this->windows = new WindowManager);
|
||||||
this->logging = new Logging;
|
this->addSingleton(this->logging = new Logging);
|
||||||
this->commands = new CommandController;
|
this->addSingleton(this->commands = new CommandController);
|
||||||
this->highlights = new HighlightController;
|
this->addSingleton(this->highlights = new HighlightController);
|
||||||
this->ignores = new IgnoreController;
|
this->addSingleton(this->ignores = new IgnoreController);
|
||||||
this->taggedUsers = new TaggedUsersController;
|
this->addSingleton(this->taggedUsers = new TaggedUsersController);
|
||||||
this->accounts = new AccountController;
|
this->addSingleton(this->accounts = new AccountController);
|
||||||
this->emotes = new Emotes;
|
this->addSingleton(this->emotes = new Emotes);
|
||||||
this->fonts = new Fonts;
|
this->addSingleton(this->fonts = new Fonts);
|
||||||
this->resources = new Resources;
|
this->addSingleton(this->resources = new Resources);
|
||||||
this->moderationActions = new ModerationActions;
|
this->addSingleton(this->moderationActions = new ModerationActions);
|
||||||
|
|
||||||
this->twitch.server = new TwitchServer;
|
this->addSingleton(this->twitch2 = new TwitchServer);
|
||||||
this->twitch.pubsub = new PubSub;
|
this->twitch.server = this->twitch2;
|
||||||
|
this->twitch.pubsub = this->twitch2->pubsub;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::instantiate(int argc, char **argv)
|
void Application::instantiate(int argc, char **argv)
|
||||||
|
@ -77,24 +80,9 @@ void Application::initialize()
|
||||||
isAppInitialized = true;
|
isAppInitialized = true;
|
||||||
|
|
||||||
// 2. Initialize/load classes
|
// 2. Initialize/load classes
|
||||||
this->settings->initialize();
|
for (Singleton *singleton : this->singletons_) {
|
||||||
|
singleton->initialize(*this);
|
||||||
this->settings->load();
|
}
|
||||||
this->commands->load();
|
|
||||||
this->logging->initialize();
|
|
||||||
this->windows->initialize();
|
|
||||||
|
|
||||||
this->resources->initialize();
|
|
||||||
|
|
||||||
this->highlights->initialize();
|
|
||||||
this->ignores->initialize();
|
|
||||||
|
|
||||||
this->emotes->initialize();
|
|
||||||
|
|
||||||
this->accounts->load();
|
|
||||||
|
|
||||||
this->twitch.server->initialize();
|
|
||||||
this->moderationActions->initialize();
|
|
||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
this->windows->updateWordTypeMask();
|
this->windows->updateWordTypeMask();
|
||||||
|
@ -197,11 +185,11 @@ void Application::initialize()
|
||||||
this->twitch.pubsub->start();
|
this->twitch.pubsub->start();
|
||||||
|
|
||||||
auto RequestModerationActions = [=]() {
|
auto RequestModerationActions = [=]() {
|
||||||
this->twitch.pubsub->unlistenAllModerationActions();
|
this->twitch.server->pubsub->unlistenAllModerationActions();
|
||||||
// TODO(pajlada): Unlisten to all authed topics instead of only moderation topics
|
// TODO(pajlada): Unlisten to all authed topics instead of only moderation topics
|
||||||
// this->twitch.pubsub->UnlistenAllAuthedTopics();
|
// this->twitch.pubsub->UnlistenAllAuthedTopics();
|
||||||
|
|
||||||
this->twitch.pubsub->listenToWhispers(this->accounts->twitch.getCurrent()); //
|
this->twitch.server->pubsub->listenToWhispers(this->accounts->twitch.getCurrent()); //
|
||||||
};
|
};
|
||||||
|
|
||||||
this->accounts->twitch.currentUserChanged.connect(RequestModerationActions);
|
this->accounts->twitch.currentUserChanged.connect(RequestModerationActions);
|
||||||
|
@ -222,9 +210,14 @@ int Application::run(QApplication &qtApp)
|
||||||
|
|
||||||
void Application::save()
|
void Application::save()
|
||||||
{
|
{
|
||||||
this->windows->save();
|
for (Singleton *singleton : this->singletons_) {
|
||||||
|
singleton->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this->commands->save();
|
void Application::addSingleton(Singleton *singleton)
|
||||||
|
{
|
||||||
|
this->singletons_.push_back(singleton);
|
||||||
}
|
}
|
||||||
|
|
||||||
Application *getApp()
|
Application *getApp()
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
|
class Singleton;
|
||||||
|
|
||||||
class TwitchServer;
|
class TwitchServer;
|
||||||
class PubSub;
|
class PubSub;
|
||||||
|
|
||||||
|
@ -44,7 +46,9 @@ public:
|
||||||
|
|
||||||
friend void test();
|
friend void test();
|
||||||
|
|
||||||
Paths *paths = nullptr;
|
[[deprecated("use getSettings() instead")]] Settings *settings = nullptr;
|
||||||
|
[[deprecated("use getPaths() instead")]] Paths *paths = nullptr;
|
||||||
|
|
||||||
Theme *themes = nullptr;
|
Theme *themes = nullptr;
|
||||||
WindowManager *windows = nullptr;
|
WindowManager *windows = nullptr;
|
||||||
Logging *logging = nullptr;
|
Logging *logging = nullptr;
|
||||||
|
@ -55,15 +59,15 @@ public:
|
||||||
AccountController *accounts = nullptr;
|
AccountController *accounts = nullptr;
|
||||||
Emotes *emotes = nullptr;
|
Emotes *emotes = nullptr;
|
||||||
NativeMessaging *nativeMessaging = nullptr;
|
NativeMessaging *nativeMessaging = nullptr;
|
||||||
Settings *settings = nullptr;
|
|
||||||
Fonts *fonts = nullptr;
|
Fonts *fonts = nullptr;
|
||||||
Resources *resources = nullptr;
|
Resources *resources = nullptr;
|
||||||
ModerationActions *moderationActions = nullptr;
|
ModerationActions *moderationActions = nullptr;
|
||||||
|
TwitchServer *twitch2 = nullptr;
|
||||||
|
|
||||||
/// Provider-specific
|
/// Provider-specific
|
||||||
struct {
|
struct {
|
||||||
TwitchServer *server = nullptr;
|
[[deprecated("use twitch2 instead")]] TwitchServer *server = nullptr;
|
||||||
PubSub *pubsub = nullptr;
|
[[deprecated("use twitch2->pubsub instead")]] PubSub *pubsub = nullptr;
|
||||||
} twitch;
|
} twitch;
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
|
@ -72,8 +76,12 @@ public:
|
||||||
static void runNativeMessagingHost();
|
static void runNativeMessagingHost();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void addSingleton(Singleton *singleton);
|
||||||
|
|
||||||
int argc_;
|
int argc_;
|
||||||
char **argv_;
|
char **argv_;
|
||||||
|
|
||||||
|
std::vector<Singleton *> singletons_;
|
||||||
};
|
};
|
||||||
|
|
||||||
Application *getApp();
|
Application *getApp();
|
||||||
|
|
|
@ -8,14 +8,13 @@ class Application;
|
||||||
|
|
||||||
class Singleton : boost::noncopyable
|
class Singleton : boost::noncopyable
|
||||||
{
|
{
|
||||||
virtual ~Singleton() = default;
|
public:
|
||||||
|
virtual void initialize(Application &app)
|
||||||
virtual void initialize(Application &application)
|
|
||||||
{
|
{
|
||||||
(void)(application);
|
(void)(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void finalize()
|
virtual void save()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,7 @@ AccountController::AccountController()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountController::load()
|
void AccountController::initialize(Application &app)
|
||||||
{
|
{
|
||||||
this->twitch.load();
|
this->twitch.load();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "common/SignalVector.hpp"
|
#include "common/SignalVector.hpp"
|
||||||
|
@ -11,14 +13,14 @@ namespace chatterino {
|
||||||
|
|
||||||
class AccountModel;
|
class AccountModel;
|
||||||
|
|
||||||
class AccountController
|
class AccountController : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AccountController();
|
AccountController();
|
||||||
|
|
||||||
AccountModel *createModel(QObject *parent);
|
AccountModel *createModel(QObject *parent);
|
||||||
|
|
||||||
void load();
|
virtual void initialize(Application &app) override;
|
||||||
|
|
||||||
TwitchAccountManager twitch;
|
TwitchAccountManager twitch;
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,11 @@ CommandController::CommandController()
|
||||||
this->items.itemRemoved.connect(addFirstMatchToMap);
|
this->items.itemRemoved.connect(addFirstMatchToMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommandController::initialize(Application &app)
|
||||||
|
{
|
||||||
|
this->load();
|
||||||
|
}
|
||||||
|
|
||||||
void CommandController::load()
|
void CommandController::load()
|
||||||
{
|
{
|
||||||
auto app = getApp();
|
auto app = getApp();
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -12,7 +14,7 @@ class Channel;
|
||||||
|
|
||||||
class CommandModel;
|
class CommandModel;
|
||||||
|
|
||||||
class CommandController
|
class CommandController : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CommandController();
|
CommandController();
|
||||||
|
@ -20,14 +22,16 @@ public:
|
||||||
QString execCommand(const QString &text, std::shared_ptr<Channel> channel, bool dryRun);
|
QString execCommand(const QString &text, std::shared_ptr<Channel> channel, bool dryRun);
|
||||||
QStringList getDefaultTwitchCommandList();
|
QStringList getDefaultTwitchCommandList();
|
||||||
|
|
||||||
void load();
|
virtual void initialize(Application &app) override;
|
||||||
void save();
|
virtual void save() override;
|
||||||
|
|
||||||
CommandModel *createModel(QObject *parent);
|
CommandModel *createModel(QObject *parent);
|
||||||
|
|
||||||
UnsortedSignalVector<Command> items;
|
UnsortedSignalVector<Command> items;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void load();
|
||||||
|
|
||||||
QMap<QString, Command> commandsMap_;
|
QMap<QString, Command> commandsMap_;
|
||||||
|
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
|
|
|
@ -12,7 +12,7 @@ HighlightController::HighlightController()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void HighlightController::initialize()
|
void HighlightController::initialize(Application &app)
|
||||||
{
|
{
|
||||||
assert(!this->initialized_);
|
assert(!this->initialized_);
|
||||||
this->initialized_ = true;
|
this->initialized_ = true;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include "common/SignalVector.hpp"
|
#include "common/SignalVector.hpp"
|
||||||
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
#include "controllers/highlights/HighlightBlacklistUser.hpp"
|
||||||
#include "controllers/highlights/HighlightPhrase.hpp"
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
||||||
|
@ -12,12 +14,12 @@ class UserHighlightModel;
|
||||||
class HighlightModel;
|
class HighlightModel;
|
||||||
class HighlightBlacklistModel;
|
class HighlightBlacklistModel;
|
||||||
|
|
||||||
class HighlightController
|
class HighlightController : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HighlightController();
|
HighlightController();
|
||||||
|
|
||||||
void initialize();
|
virtual void initialize(Application &app) override;
|
||||||
|
|
||||||
UnsortedSignalVector<HighlightPhrase> phrases;
|
UnsortedSignalVector<HighlightPhrase> phrases;
|
||||||
UnsortedSignalVector<HighlightBlacklistUser> blacklistedUsers;
|
UnsortedSignalVector<HighlightBlacklistUser> blacklistedUsers;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
void IgnoreController::initialize()
|
void IgnoreController::initialize(Application &)
|
||||||
{
|
{
|
||||||
assert(!this->initialized_);
|
assert(!this->initialized_);
|
||||||
this->initialized_ = true;
|
this->initialized_ = true;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include "common/SignalVector.hpp"
|
#include "common/SignalVector.hpp"
|
||||||
#include "controllers/ignores/IgnorePhrase.hpp"
|
#include "controllers/ignores/IgnorePhrase.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
@ -8,10 +10,10 @@ namespace chatterino {
|
||||||
|
|
||||||
class IgnoreModel;
|
class IgnoreModel;
|
||||||
|
|
||||||
class IgnoreController
|
class IgnoreController : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void initialize();
|
virtual void initialize(Application &app) override;
|
||||||
|
|
||||||
UnsortedSignalVector<IgnorePhrase> phrases;
|
UnsortedSignalVector<IgnorePhrase> phrases;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ ModerationActions::ModerationActions()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModerationActions::initialize()
|
void ModerationActions::initialize(Application &app)
|
||||||
{
|
{
|
||||||
assert(!this->initialized_);
|
assert(!this->initialized_);
|
||||||
this->initialized_ = true;
|
this->initialized_ = true;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include "common/ChatterinoSetting.hpp"
|
#include "common/ChatterinoSetting.hpp"
|
||||||
#include "common/SignalVector.hpp"
|
#include "common/SignalVector.hpp"
|
||||||
#include "controllers/moderationactions/ModerationAction.hpp"
|
#include "controllers/moderationactions/ModerationAction.hpp"
|
||||||
|
@ -8,12 +10,12 @@ namespace chatterino {
|
||||||
|
|
||||||
class ModerationActionModel;
|
class ModerationActionModel;
|
||||||
|
|
||||||
class ModerationActions
|
class ModerationActions final : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ModerationActions();
|
ModerationActions();
|
||||||
|
|
||||||
void initialize();
|
virtual void initialize(Application &app) override;
|
||||||
|
|
||||||
UnsortedSignalVector<ModerationAction> items;
|
UnsortedSignalVector<ModerationAction> items;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include "common/SignalVector.hpp"
|
#include "common/SignalVector.hpp"
|
||||||
#include "controllers/taggedusers/TaggedUser.hpp"
|
#include "controllers/taggedusers/TaggedUser.hpp"
|
||||||
|
|
||||||
|
@ -7,7 +9,7 @@ namespace chatterino {
|
||||||
|
|
||||||
class TaggedUsersModel;
|
class TaggedUsersModel;
|
||||||
|
|
||||||
class TaggedUsersController
|
class TaggedUsersController : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TaggedUsersController();
|
TaggedUsersController();
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#include "TwitchServer.hpp"
|
#include "TwitchServer.hpp"
|
||||||
|
|
||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
|
#include "common/Common.hpp"
|
||||||
#include "controllers/accounts/AccountController.hpp"
|
#include "controllers/accounts/AccountController.hpp"
|
||||||
#include "controllers/highlights/HighlightController.hpp"
|
#include "controllers/highlights/HighlightController.hpp"
|
||||||
#include "providers/twitch/IrcMessageHandler.hpp"
|
#include "providers/twitch/IrcMessageHandler.hpp"
|
||||||
|
#include "providers/twitch/PubsubClient.hpp"
|
||||||
#include "providers/twitch/TwitchAccount.hpp"
|
#include "providers/twitch/TwitchAccount.hpp"
|
||||||
#include "providers/twitch/TwitchHelpers.hpp"
|
#include "providers/twitch/TwitchHelpers.hpp"
|
||||||
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
||||||
|
@ -24,16 +26,22 @@ TwitchServer::TwitchServer()
|
||||||
, watchingChannel(Channel::getEmpty(), Channel::Type::TwitchWatching)
|
, watchingChannel(Channel::getEmpty(), Channel::Type::TwitchWatching)
|
||||||
{
|
{
|
||||||
qDebug() << "init TwitchServer";
|
qDebug() << "init TwitchServer";
|
||||||
|
|
||||||
|
this->pubsub = new PubSub;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchServer::initialize()
|
void TwitchServer::initialize(Application &app)
|
||||||
{
|
{
|
||||||
getApp()->accounts->twitch.currentUserChanged.connect(
|
this->app = &app;
|
||||||
|
|
||||||
|
app.accounts->twitch.currentUserChanged.connect(
|
||||||
[this]() { postToThread([this] { this->connect(); }); });
|
[this]() { postToThread([this] { this->connect(); }); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, bool isWrite)
|
void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, bool isWrite)
|
||||||
{
|
{
|
||||||
|
assert(this->app);
|
||||||
|
|
||||||
std::shared_ptr<TwitchAccount> account = getApp()->accounts->twitch.getCurrent();
|
std::shared_ptr<TwitchAccount> account = getApp()->accounts->twitch.getCurrent();
|
||||||
|
|
||||||
qDebug() << "logging in as" << account->getUserName();
|
qDebug() << "logging in as" << account->getUserName();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/MutexValue.hpp"
|
#include "common/MutexValue.hpp"
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
#include "providers/irc/AbstractIrcServer.hpp"
|
#include "providers/irc/AbstractIrcServer.hpp"
|
||||||
#include "providers/twitch/TwitchAccount.hpp"
|
#include "providers/twitch/TwitchAccount.hpp"
|
||||||
#include "providers/twitch/TwitchChannel.hpp"
|
#include "providers/twitch/TwitchChannel.hpp"
|
||||||
|
@ -11,12 +12,15 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class TwitchServer final : public AbstractIrcServer
|
class PubSub;
|
||||||
|
|
||||||
|
class TwitchServer : public AbstractIrcServer, public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TwitchServer();
|
TwitchServer();
|
||||||
|
virtual ~TwitchServer() override = default;
|
||||||
|
|
||||||
void initialize();
|
virtual void initialize(Application &app) override;
|
||||||
|
|
||||||
// fourtf: ugh
|
// fourtf: ugh
|
||||||
void forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func);
|
void forEachChannelAndSpecialChannels(std::function<void(ChannelPtr)> func);
|
||||||
|
@ -29,6 +33,8 @@ public:
|
||||||
const ChannelPtr mentionsChannel;
|
const ChannelPtr mentionsChannel;
|
||||||
IndirectChannel watchingChannel;
|
IndirectChannel watchingChannel;
|
||||||
|
|
||||||
|
PubSub *pubsub;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initializeConnection(IrcConnection *connection, bool isRead, bool isWrite) override;
|
void initializeConnection(IrcConnection *connection, bool isRead, bool isWrite) override;
|
||||||
std::shared_ptr<Channel> createChannel(const QString &channelName) override;
|
std::shared_ptr<Channel> createChannel(const QString &channelName) override;
|
||||||
|
@ -44,6 +50,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
void onMessageSendRequested(TwitchChannel *channel, const QString &message, bool &sent);
|
void onMessageSendRequested(TwitchChannel *channel, const QString &message, bool &sent);
|
||||||
|
|
||||||
|
Application *app = nullptr;
|
||||||
|
|
||||||
std::mutex lastMessageMutex_;
|
std::mutex lastMessageMutex_;
|
||||||
std::queue<std::chrono::steady_clock::time_point> lastMessagePleb_;
|
std::queue<std::chrono::steady_clock::time_point> lastMessagePleb_;
|
||||||
std::queue<std::chrono::steady_clock::time_point> lastMessageMod_;
|
std::queue<std::chrono::steady_clock::time_point> lastMessageMod_;
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
void Emotes::initialize()
|
void Emotes::initialize(Application &app)
|
||||||
{
|
{
|
||||||
getApp()->accounts->twitch.currentUserChanged.connect([this] {
|
app.accounts->twitch.currentUserChanged.connect([this, &app] {
|
||||||
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
auto currentUser = app.accounts->twitch.getCurrent();
|
||||||
assert(currentUser);
|
assert(currentUser);
|
||||||
this->twitch.refresh(currentUser);
|
this->twitch.refresh(currentUser);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#define GIF_FRAME_LENGTH 33
|
#define GIF_FRAME_LENGTH 33
|
||||||
|
|
||||||
#include "providers/bttv/BttvEmotes.hpp"
|
#include "providers/bttv/BttvEmotes.hpp"
|
||||||
|
@ -10,12 +12,10 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class Emotes
|
class Emotes final : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~Emotes() = delete;
|
virtual void initialize(Application &app) override;
|
||||||
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
bool isIgnoredEmote(const QString &emote);
|
bool isIgnoredEmote(const QString &emote);
|
||||||
|
|
||||||
|
|
|
@ -26,37 +26,38 @@ Fonts::Fonts()
|
||||||
: chatFontFamily("/appearance/currentFontFamily", DEFAULT_FONT_FAMILY)
|
: chatFontFamily("/appearance/currentFontFamily", DEFAULT_FONT_FAMILY)
|
||||||
, chatFontSize("/appearance/currentFontSize", DEFAULT_FONT_SIZE)
|
, chatFontSize("/appearance/currentFontSize", DEFAULT_FONT_SIZE)
|
||||||
{
|
{
|
||||||
qDebug() << "init FontManager";
|
|
||||||
|
|
||||||
this->chatFontFamily.connect([this](const std::string &, auto) {
|
|
||||||
assertInGuiThread();
|
|
||||||
|
|
||||||
if (getApp()->windows) {
|
|
||||||
getApp()->windows->incGeneration();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &map : this->fontsByType_) {
|
|
||||||
map.clear();
|
|
||||||
}
|
|
||||||
this->fontChanged.invoke();
|
|
||||||
});
|
|
||||||
|
|
||||||
this->chatFontSize.connect([this](const int &, auto) {
|
|
||||||
assertInGuiThread();
|
|
||||||
|
|
||||||
if (getApp()->windows) {
|
|
||||||
getApp()->windows->incGeneration();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &map : this->fontsByType_) {
|
|
||||||
map.clear();
|
|
||||||
}
|
|
||||||
this->fontChanged.invoke();
|
|
||||||
});
|
|
||||||
|
|
||||||
this->fontsByType_.resize(size_t(EndType));
|
this->fontsByType_.resize(size_t(EndType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Fonts::initialize(Application &app)
|
||||||
|
{
|
||||||
|
this->chatFontFamily.connect([this, &app](const std::string &, auto) {
|
||||||
|
assertInGuiThread();
|
||||||
|
|
||||||
|
if (app.windows) {
|
||||||
|
app.windows->incGeneration();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &map : this->fontsByType_) {
|
||||||
|
map.clear();
|
||||||
|
}
|
||||||
|
this->fontChanged.invoke();
|
||||||
|
});
|
||||||
|
|
||||||
|
this->chatFontSize.connect([this, &app](const int &, auto) {
|
||||||
|
assertInGuiThread();
|
||||||
|
|
||||||
|
if (app.windows) {
|
||||||
|
app.windows->incGeneration();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &map : this->fontsByType_) {
|
||||||
|
map.clear();
|
||||||
|
}
|
||||||
|
this->fontChanged.invoke();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
QFont Fonts::getFont(Fonts::Type type, float scale)
|
QFont Fonts::getFont(Fonts::Type type, float scale)
|
||||||
{
|
{
|
||||||
return this->getOrCreateFontData(type, scale).font;
|
return this->getOrCreateFontData(type, scale).font;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
|
@ -11,11 +13,13 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class Fonts : boost::noncopyable
|
class Fonts final : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Fonts();
|
Fonts();
|
||||||
|
|
||||||
|
virtual void initialize(Application &app) override;
|
||||||
|
|
||||||
// font data gets set in createFontData(...)
|
// font data gets set in createFontData(...)
|
||||||
enum Type : uint8_t {
|
enum Type : uint8_t {
|
||||||
Tiny,
|
Tiny,
|
||||||
|
|
|
@ -12,16 +12,13 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
void Logging::initialize()
|
void Logging::initialize(Application &app)
|
||||||
{
|
{
|
||||||
this->pathManager = getApp()->paths;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logging::addMessage(const QString &channelName, MessagePtr message)
|
void Logging::addMessage(const QString &channelName, MessagePtr message)
|
||||||
{
|
{
|
||||||
auto app = getApp();
|
if (!getSettings()->enableLogging) {
|
||||||
|
|
||||||
if (!app->settings->enableLogging) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include "messages/Message.hpp"
|
#include "messages/Message.hpp"
|
||||||
#include "singletons/helper/LoggingChannel.hpp"
|
#include "singletons/helper/LoggingChannel.hpp"
|
||||||
|
|
||||||
|
@ -9,16 +11,14 @@ namespace chatterino {
|
||||||
|
|
||||||
class Paths;
|
class Paths;
|
||||||
|
|
||||||
class Logging
|
class Logging : public Singleton
|
||||||
{
|
{
|
||||||
Paths *pathManager = nullptr;
|
Paths *pathManager = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Logging() = default;
|
Logging() = default;
|
||||||
|
|
||||||
~Logging() = delete;
|
virtual void initialize(Application &app) override;
|
||||||
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
void addMessage(const QString &channelName, MessagePtr message);
|
void addMessage(const QString &channelName, MessagePtr message);
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
class NativeMessaging final
|
||||||
class NativeMessaging
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// fourtf: don't add this class to the application class
|
// fourtf: don't add this class to the application class
|
||||||
NativeMessaging();
|
NativeMessaging();
|
||||||
|
|
||||||
~NativeMessaging() = delete;
|
|
||||||
|
|
||||||
class ReceiverThread : public QThread
|
class ReceiverThread : public QThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -114,4 +114,9 @@ void Paths::initSubDirectories()
|
||||||
this->miscDirectory = makePath("Misc");
|
this->miscDirectory = makePath("Misc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Paths *getPaths()
|
||||||
|
{
|
||||||
|
return Paths::getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -45,4 +45,6 @@ private:
|
||||||
boost::optional<bool> portable_;
|
boost::optional<bool> portable_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Paths *getPaths();
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -302,7 +302,7 @@ Resources::Resources()
|
||||||
qDebug() << "init ResourceManager";
|
qDebug() << "init ResourceManager";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resources::initialize()
|
void Resources::initialize(Application &app)
|
||||||
{
|
{
|
||||||
this->loadDynamicTwitchBadges();
|
this->loadDynamicTwitchBadges();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include "common/Emotemap.hpp"
|
#include "common/Emotemap.hpp"
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
@ -11,14 +13,14 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class Resources
|
class Resources : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Resources();
|
Resources();
|
||||||
|
|
||||||
~Resources() = delete;
|
~Resources() = delete;
|
||||||
|
|
||||||
void initialize();
|
virtual void initialize(Application &app) override;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
QIcon left;
|
QIcon left;
|
||||||
|
|
|
@ -29,26 +29,11 @@ Settings &Settings::getInstance()
|
||||||
|
|
||||||
void Settings::initialize()
|
void Settings::initialize()
|
||||||
{
|
{
|
||||||
this->timestampFormat.connect([](auto, auto) {
|
|
||||||
auto app = getApp();
|
|
||||||
app->windows->layoutChannelViews();
|
|
||||||
});
|
|
||||||
|
|
||||||
this->emoteScale.connect([](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
|
||||||
|
|
||||||
this->timestampFormat.connect([](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
|
||||||
this->alternateMessageBackground.connect(
|
|
||||||
[](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
|
||||||
this->separateMessages.connect(
|
|
||||||
[](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
|
||||||
this->collpseMessagesMinLines.connect(
|
|
||||||
[](auto, auto) { getApp()->windows->forceLayoutChannelViews(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::load()
|
void Settings::load()
|
||||||
{
|
{
|
||||||
auto app = getApp();
|
QString settingsPath = getPaths()->settingsDirectory + "/settings.json";
|
||||||
QString settingsPath = app->paths->settingsDirectory + "/settings.json";
|
|
||||||
|
|
||||||
pajlada::Settings::SettingManager::load(qPrintable(settingsPath));
|
pajlada::Settings::SettingManager::load(qPrintable(settingsPath));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/SerializeCustom.hpp"
|
#include "common/SerializeCustom.hpp"
|
||||||
|
#include "common/Singleton.hpp"
|
||||||
|
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
@ -10,13 +11,11 @@ namespace chatterino {
|
||||||
|
|
||||||
class WindowManager;
|
class WindowManager;
|
||||||
|
|
||||||
class Theme
|
class Theme final : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Theme();
|
Theme();
|
||||||
|
|
||||||
~Theme() = delete;
|
|
||||||
|
|
||||||
inline bool isLightTheme() const
|
inline bool isLightTheme() const
|
||||||
{
|
{
|
||||||
return this->isLight_;
|
return this->isLight_;
|
||||||
|
|
|
@ -206,17 +206,16 @@ Window *WindowManager::windowAt(int index)
|
||||||
return this->windows_.at(index);
|
return this->windows_.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::initialize()
|
void WindowManager::initialize(Application &app)
|
||||||
{
|
{
|
||||||
assertInGuiThread();
|
assertInGuiThread();
|
||||||
|
|
||||||
auto app = getApp();
|
app.themes->repaintVisibleChatWidgets_.connect([this] { this->repaintVisibleChatWidgets(); });
|
||||||
app->themes->repaintVisibleChatWidgets_.connect([this] { this->repaintVisibleChatWidgets(); });
|
|
||||||
|
|
||||||
assert(!this->initialized_);
|
assert(!this->initialized_);
|
||||||
|
|
||||||
// load file
|
// load file
|
||||||
QString settingsPath = app->paths->settingsDirectory + SETTINGS_FILENAME;
|
QString settingsPath = getPaths()->settingsDirectory + SETTINGS_FILENAME;
|
||||||
QFile file(settingsPath);
|
QFile file(settingsPath);
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
QByteArray data = file.readAll();
|
QByteArray data = file.readAll();
|
||||||
|
@ -301,6 +300,22 @@ void WindowManager::initialize()
|
||||||
mainWindow_->getNotebook().addPage(true);
|
mainWindow_->getNotebook().addPage(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto settings = getSettings();
|
||||||
|
|
||||||
|
settings->timestampFormat.connect([this](auto, auto) {
|
||||||
|
auto app = getApp();
|
||||||
|
this->layoutChannelViews();
|
||||||
|
});
|
||||||
|
|
||||||
|
settings->emoteScale.connect([this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||||
|
|
||||||
|
settings->timestampFormat.connect([this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||||
|
settings->alternateMessageBackground.connect(
|
||||||
|
[this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||||
|
settings->separateMessages.connect([this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||||
|
settings->collpseMessagesMinLines.connect(
|
||||||
|
[this](auto, auto) { this->forceLayoutChannelViews(); });
|
||||||
|
|
||||||
this->initialized_ = true;
|
this->initialized_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,9 +336,12 @@ void WindowManager::save()
|
||||||
case Window::Type::Main:
|
case Window::Type::Main:
|
||||||
window_obj.insert("type", "main");
|
window_obj.insert("type", "main");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Window::Type::Popup:
|
case Window::Type::Popup:
|
||||||
window_obj.insert("type", "popup");
|
window_obj.insert("type", "popup");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Window::Type::Attached:;
|
||||||
}
|
}
|
||||||
|
|
||||||
// window geometry
|
// window geometry
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <common/Singleton.hpp>
|
||||||
|
|
||||||
#include "widgets/Window.hpp"
|
#include "widgets/Window.hpp"
|
||||||
#include "widgets/splits/SplitContainer.hpp"
|
#include "widgets/splits/SplitContainer.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class WindowManager
|
class WindowManager : public Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowManager();
|
WindowManager();
|
||||||
~WindowManager() = delete;
|
|
||||||
|
|
||||||
static void encodeChannel(IndirectChannel channel, QJsonObject &obj);
|
static void encodeChannel(IndirectChannel channel, QJsonObject &obj);
|
||||||
static IndirectChannel decodeChannel(const QJsonObject &obj);
|
static IndirectChannel decodeChannel(const QJsonObject &obj);
|
||||||
|
@ -36,8 +37,8 @@ public:
|
||||||
int windowCount();
|
int windowCount();
|
||||||
Window *windowAt(int index);
|
Window *windowAt(int index);
|
||||||
|
|
||||||
void save();
|
virtual void initialize(Application &app) override;
|
||||||
void initialize();
|
virtual void save() override;
|
||||||
void closeAll();
|
void closeAll();
|
||||||
|
|
||||||
int getGeneration() const;
|
int getGeneration() const;
|
||||||
|
|
|
@ -676,7 +676,7 @@ void ChannelView::wheelEvent(QWheelEvent *event)
|
||||||
|
|
||||||
auto snapshot = this->getMessagesSnapshot();
|
auto snapshot = this->getMessagesSnapshot();
|
||||||
int snapshotLength = int(snapshot.getLength());
|
int snapshotLength = int(snapshot.getLength());
|
||||||
int i = std::min(int(desired), snapshotLength);
|
int i = std::min<int>(int(desired), snapshotLength);
|
||||||
|
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
qreal scrollFactor = fmod(desired, 1);
|
qreal scrollFactor = fmod(desired, 1);
|
||||||
|
|
Loading…
Reference in a new issue