Skip to content

Commit

Permalink
refactor: some more Application refactors (#5551)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada authored Aug 25, 2024
1 parent f4d6845 commit 3e510fd
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 170 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
- Dev: Refactored a few `#define`s into `const(expr)` and cleaned includes. (#5527)
- Dev: Added `FlagsEnum::isEmpty`. (#5550)
- Dev: Prepared for Qt 6.8 by addressing some deprecations. (#5529)
- Dev: Moved some responsibility away from Application into WindowManager. (#5551)
- Dev: Fixed benchmarks segfaulting on run. (#5559)
- Dev: Refactored `MessageBuilder` to be a single class. (#5548)
- Dev: Recent changes are now shown in the nightly release description. (#5553, #5554)
Expand Down
18 changes: 18 additions & 0 deletions mocks/include/mocks/BaseApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include "mocks/DisabledStreamerMode.hpp"
#include "mocks/EmptyApplication.hpp"
#include "providers/bttv/BttvLiveUpdates.hpp"
#include "singletons/Fonts.hpp"
#include "singletons/Settings.hpp"
#include "singletons/Theme.hpp"

#include <QString>

Expand All @@ -18,12 +20,16 @@ class BaseApplication : public EmptyApplication
public:
BaseApplication()
: settings(this->args, this->settingsDir.path())
, theme(this->paths_)
, fonts(this->settings)
{
}

explicit BaseApplication(const QString &settingsData)
: EmptyApplication(settingsData)
, settings(this->args, this->settingsDir.path())
, theme(this->paths_)
, fonts(this->settings)
{
}

Expand All @@ -32,6 +38,16 @@ class BaseApplication : public EmptyApplication
return &this->streamerMode;
}

Theme *getThemes() override
{
return &this->theme;
}

Fonts *getFonts() override
{
return &this->fonts;
}

BttvLiveUpdates *getBttvLiveUpdates() override
{
return nullptr;
Expand All @@ -45,6 +61,8 @@ class BaseApplication : public EmptyApplication
Args args;
Settings settings;
DisabledStreamerMode streamerMode;
Theme theme;
Fonts fonts;
};

} // namespace chatterino::mock
48 changes: 11 additions & 37 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Application::Application(Settings &_settings, const Paths &paths,
, emotes(new Emotes)
, accounts(new AccountController)
, hotkeys(new HotkeyController)
, windows(new WindowManager(paths))
, windows(new WindowManager(paths, _settings, *this->themes, *this->fonts))
, toasts(new Toasts)
, imageUploader(new ImageUploader)
, seventvAPI(new SeventvAPI)
Expand Down Expand Up @@ -184,11 +184,6 @@ Application::Application(Settings &_settings, const Paths &paths,
#endif
, updates(_updates)
{
// We can safely ignore this signal's connection since the Application will always
// be destroyed after fonts
std::ignore = this->fonts->fontChanged.connect([this]() {
this->windows->layoutChannelViews();
});
}

Application::~Application()
Expand Down Expand Up @@ -225,9 +220,15 @@ void Application::initialize(Settings &settings, const Paths &paths)

this->accounts->load();

this->windows->initialize(settings);
this->windows->initialize();

this->ffzBadges->load();

// Load global emotes
this->bttvEmotes->loadEmotes();
this->ffzEmotes->loadEmotes();
this->seventvEmotes->loadGlobalEmotes();

this->twitch->initialize();

// Load live status
Expand Down Expand Up @@ -266,8 +267,6 @@ void Application::initialize(Settings &settings, const Paths &paths)
}
#endif

this->windows->updateWordTypeMask();

if (!this->args_.isFramelessEmbed)
{
this->initNm(paths);
Expand Down Expand Up @@ -297,34 +296,9 @@ int Application::run(QApplication &qtApp)
},
false);

// We can safely ignore the signal connections since Application will always live longer than
// everything else, including settings. right?
// NOTE: SETTINGS_LIFETIME
std::ignore =
getSettings()->moderationActions.delayedItemsChanged.connect([this] {
this->windows->forceLayoutChannelViews();
});

std::ignore =
getSettings()->highlightedMessages.delayedItemsChanged.connect([this] {
this->windows->forceLayoutChannelViews();
});
std::ignore =
getSettings()->highlightedUsers.delayedItemsChanged.connect([this] {
this->windows->forceLayoutChannelViews();
});
std::ignore =
getSettings()->highlightedBadges.delayedItemsChanged.connect([this] {
this->windows->forceLayoutChannelViews();
});

getSettings()->removeSpacesBetweenEmotes.connect([this] {
this->windows->forceLayoutChannelViews();
});

getSettings()->enableBTTVGlobalEmotes.connect(
[this] {
this->twitch->reloadBTTVGlobalEmotes();
this->bttvEmotes->loadEmotes();
},
false);
getSettings()->enableBTTVChannelEmotes.connect(
Expand All @@ -334,7 +308,7 @@ int Application::run(QApplication &qtApp)
false);
getSettings()->enableFFZGlobalEmotes.connect(
[this] {
this->twitch->reloadFFZGlobalEmotes();
this->ffzEmotes->loadEmotes();
},
false);
getSettings()->enableFFZChannelEmotes.connect(
Expand All @@ -344,7 +318,7 @@ int Application::run(QApplication &qtApp)
false);
getSettings()->enableSevenTVGlobalEmotes.connect(
[this] {
this->twitch->reloadSevenTVGlobalEmotes();
this->seventvEmotes->loadGlobalEmotes();
},
false);
getSettings()->enableSevenTVChannelEmotes.connect(
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ set(SOURCE_FILES
util/SampleData.cpp
util/SampleData.hpp
util/SharedPtrElementLess.hpp
util/SignalListener.hpp
util/StreamLink.cpp
util/StreamLink.hpp
util/ThreadGuard.hpp
Expand Down
10 changes: 10 additions & 0 deletions src/common/ChatterinoSetting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,14 @@ class EnumStringSetting : public pajlada::Settings::Setting<QString>
using pajlada::Settings::Setting<QString>::operator QString;
};

template <typename T>
struct IsChatterinoSettingT : std::false_type {
};
template <typename T>
struct IsChatterinoSettingT<ChatterinoSetting<T>> : std::true_type {
};

template <typename T>
concept IsChatterinoSetting = IsChatterinoSettingT<T>::value;

} // namespace chatterino
19 changes: 0 additions & 19 deletions src/providers/twitch/TwitchIrcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ void TwitchIrcServer::initialize()
this->connect();
});
});

this->reloadBTTVGlobalEmotes();
this->reloadFFZGlobalEmotes();
this->reloadSevenTVGlobalEmotes();
}

void TwitchIrcServer::initializeConnection(IrcConnection *connection,
Expand Down Expand Up @@ -806,11 +802,6 @@ void TwitchIrcServer::setLastUserThatWhisperedMe(const QString &user)
this->lastUserThatWhisperedMe.set(user);
}

void TwitchIrcServer::reloadBTTVGlobalEmotes()
{
getApp()->getBttvEmotes()->loadEmotes();
}

void TwitchIrcServer::reloadAllBTTVChannelEmotes()
{
this->forEachChannel([](const auto &chan) {
Expand All @@ -821,11 +812,6 @@ void TwitchIrcServer::reloadAllBTTVChannelEmotes()
});
}

void TwitchIrcServer::reloadFFZGlobalEmotes()
{
getApp()->getFfzEmotes()->loadEmotes();
}

void TwitchIrcServer::reloadAllFFZChannelEmotes()
{
this->forEachChannel([](const auto &chan) {
Expand All @@ -836,11 +822,6 @@ void TwitchIrcServer::reloadAllFFZChannelEmotes()
});
}

void TwitchIrcServer::reloadSevenTVGlobalEmotes()
{
getApp()->getSeventvEmotes()->loadGlobalEmotes();
}

void TwitchIrcServer::reloadAllSevenTVChannelEmotes()
{
this->forEachChannel([](const auto &chan) {
Expand Down
3 changes: 0 additions & 3 deletions src/providers/twitch/TwitchIrcServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,8 @@ class TwitchIrcServer final : public ITwitchIrcServer, public QObject
std::shared_ptr<Channel> getChannelOrEmptyByID(
const QString &channelID) override;

void reloadBTTVGlobalEmotes();
void reloadAllBTTVChannelEmotes();
void reloadFFZGlobalEmotes();
void reloadAllFFZChannelEmotes();
void reloadSevenTVGlobalEmotes();
void reloadAllSevenTVChannelEmotes();

/** Calls `func` with all twitch channels that have `emoteSetId` added. */
Expand Down
Loading

0 comments on commit 3e510fd

Please sign in to comment.