mess around with ast matching and some refactoring

This commit is contained in:
Rasmus Karlsson 2024-06-24 01:40:22 +02:00
parent 7bfb5ac0a4
commit 8d5a546f23
No known key found for this signature in database
7 changed files with 80 additions and 36 deletions

41
scripts/get-app-uses.sh Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env bash
# This script will print any usages of IApplication - can be used to figure out
# dependencies of an file. e.g. if used on SeventvEmotes.cpp, you'll see it uses SeventvAPI
set -e
command_file="/tmp/c2-get-app-uses-command"
usage() {
>&2 echo "usage: $0 <file> - prints the Application dependencies this file has"
exit
}
file="$1"
if [ -z "$file" ]; then
usage
fi
if [ ! -f "$file" ]; then
>&2 echo "error: file '$file' does not exist"
exit 1
fi
echo 'set output print
match cxxMemberCallExpr(on(hasType(asString("IApplication *"))))' >"$command_file"
next=0
usages=()
while read -r l; do
# echo "l: '$l'"
if [ "$next" = "1" ]; then
echo "$l"
usages+=("$l")
fi
next=0
if [[ $l = 'Binding for "root":' ]]; then
next=1
fi
done <<< "$(clang-query "$file" -f="$command_file" 2>/dev/null)"

View file

@ -121,29 +121,29 @@ Application::Application(Settings &_settings, const Paths &paths,
, themes(&this->emplace<Theme>()) , themes(&this->emplace<Theme>())
, fonts(new Fonts(_settings)) , fonts(new Fonts(_settings))
, emotes(&this->emplace<Emotes>()) , emotes(&this->emplace<Emotes>())
, accounts(&this->emplace<AccountController>()) , accounts(new AccountController)
, bttvEmotes(new BttvEmotes)
, ffzEmotes(new FfzEmotes)
, seventvAPI(new SeventvAPI)
, seventvEmotes(new SeventvEmotes)
, seventvBadges(new SeventvBadges)
, hotkeys(&this->emplace<HotkeyController>()) , hotkeys(&this->emplace<HotkeyController>())
, windows(&this->emplace(new WindowManager(paths))) , windows(&this->emplace(new WindowManager(paths)))
, toasts(&this->emplace<Toasts>()) , toasts(&this->emplace<Toasts>())
, imageUploader(&this->emplace<ImageUploader>()) , imageUploader(&this->emplace<ImageUploader>())
, seventvAPI(&this->emplace<SeventvAPI>())
, crashHandler(&this->emplace(new CrashHandler(paths))) , crashHandler(&this->emplace(new CrashHandler(paths)))
, commands(&this->emplace<CommandController>()) , commands(&this->emplace<CommandController>())
, notifications(&this->emplace<NotificationController>())
, highlights(&this->emplace<HighlightController>()) , highlights(&this->emplace<HighlightController>())
, twitch(new TwitchIrcServer) , twitch(new TwitchIrcServer)
, ffzBadges(&this->emplace<FfzBadges>()) , ffzBadges(&this->emplace<FfzBadges>())
, seventvBadges(&this->emplace<SeventvBadges>())
, userData(new UserDataController(paths)) , userData(new UserDataController(paths))
, sound(makeSoundController(_settings)) , sound(makeSoundController(_settings))
, twitchLiveController(&this->emplace<TwitchLiveController>()) , twitchLiveController(&this->emplace<TwitchLiveController>())
, notifications(new NotificationController)
, twitchPubSub(new PubSub(TWITCH_PUBSUB_URL)) , twitchPubSub(new PubSub(TWITCH_PUBSUB_URL))
, twitchBadges(new TwitchBadges) , twitchBadges(new TwitchBadges)
, chatterinoBadges(new ChatterinoBadges) , chatterinoBadges(new ChatterinoBadges)
, bttvEmotes(new BttvEmotes)
, ffzEmotes(new FfzEmotes)
, seventvEmotes(new SeventvEmotes)
, logging(new Logging(_settings)) , logging(new Logging(_settings))
, linkResolver(new LinkResolver) , linkResolver(new LinkResolver)
, streamerMode(new StreamerMode) , streamerMode(new StreamerMode)
@ -168,13 +168,17 @@ void Application::fakeDtor()
this->twitchPubSub.reset(); this->twitchPubSub.reset();
this->twitchBadges.reset(); this->twitchBadges.reset();
this->chatterinoBadges.reset(); this->chatterinoBadges.reset();
this->bttvEmotes.reset();
this->ffzEmotes.reset();
this->seventvEmotes.reset();
// this->twitch.reset(); // this->twitch.reset();
this->fonts.reset(); this->fonts.reset();
this->sound.reset(); this->sound.reset();
this->userData.reset(); this->userData.reset();
this->seventvBadges.reset();
this->seventvEmotes.reset();
this->seventvAPI.reset();
this->ffzEmotes.reset();
this->bttvEmotes.reset();
this->accounts.reset();
} }
void Application::initialize(Settings &settings, const Paths &paths) void Application::initialize(Settings &settings, const Paths &paths)
@ -357,8 +361,9 @@ IEmotes *Application::getEmotes()
AccountController *Application::getAccounts() AccountController *Application::getAccounts()
{ {
assertInGuiThread(); assertInGuiThread();
assert(this->accounts);
return this->accounts; return this->accounts.get();
} }
HotkeyController *Application::getHotkeys() HotkeyController *Application::getHotkeys()
@ -400,8 +405,9 @@ CommandController *Application::getCommands()
NotificationController *Application::getNotifications() NotificationController *Application::getNotifications()
{ {
assertInGuiThread(); assertInGuiThread();
assert(this->notifications);
return this->notifications; return this->notifications.get();
} }
HighlightController *Application::getHighlights() HighlightController *Application::getHighlights()
@ -421,8 +427,9 @@ FfzBadges *Application::getFfzBadges()
SeventvBadges *Application::getSeventvBadges() SeventvBadges *Application::getSeventvBadges()
{ {
// SeventvBadges handles its own locks, so we don't need to assert that this is called in the GUI thread // 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() IUserDataController *Application::getUserData()
@ -472,8 +479,9 @@ ImageUploader *Application::getImageUploader()
SeventvAPI *Application::getSeventvAPI() SeventvAPI *Application::getSeventvAPI()
{ {
assertInGuiThread(); assertInGuiThread();
assert(this->seventvAPI);
return this->seventvAPI; return this->seventvAPI.get();
} }
#ifdef CHATTERINO_HAVE_PLUGINS #ifdef CHATTERINO_HAVE_PLUGINS

View file

@ -147,28 +147,28 @@ private:
Theme *const themes{}; Theme *const themes{};
std::unique_ptr<Fonts> fonts{}; std::unique_ptr<Fonts> fonts{};
Emotes *const emotes{}; Emotes *const emotes{};
AccountController *const accounts{}; std::unique_ptr<AccountController> accounts;
std::unique_ptr<BttvEmotes> bttvEmotes;
std::unique_ptr<FfzEmotes> ffzEmotes;
std::unique_ptr<SeventvAPI> seventvAPI;
std::unique_ptr<SeventvEmotes> seventvEmotes;
std::unique_ptr<SeventvBadges> seventvBadges;
HotkeyController *const hotkeys{}; HotkeyController *const hotkeys{};
WindowManager *const windows{}; WindowManager *const windows{};
Toasts *const toasts{}; Toasts *const toasts{};
ImageUploader *const imageUploader{}; ImageUploader *const imageUploader{};
SeventvAPI *const seventvAPI{};
CrashHandler *const crashHandler{}; CrashHandler *const crashHandler{};
CommandController *const commands{}; CommandController *const commands{};
NotificationController *const notifications{};
HighlightController *const highlights{}; HighlightController *const highlights{};
std::unique_ptr<TwitchIrcServer> twitch; std::unique_ptr<TwitchIrcServer> twitch;
FfzBadges *const ffzBadges{}; FfzBadges *const ffzBadges{};
SeventvBadges *const seventvBadges{};
std::unique_ptr<UserDataController> userData; std::unique_ptr<UserDataController> userData;
std::unique_ptr<ISoundController> sound; std::unique_ptr<ISoundController> sound;
TwitchLiveController *const twitchLiveController{}; TwitchLiveController *const twitchLiveController{};
std::unique_ptr<NotificationController> notifications;
std::unique_ptr<PubSub> twitchPubSub; std::unique_ptr<PubSub> twitchPubSub;
std::unique_ptr<TwitchBadges> twitchBadges; std::unique_ptr<TwitchBadges> twitchBadges;
std::unique_ptr<ChatterinoBadges> chatterinoBadges; std::unique_ptr<ChatterinoBadges> chatterinoBadges;
std::unique_ptr<BttvEmotes> bttvEmotes;
std::unique_ptr<FfzEmotes> ffzEmotes;
std::unique_ptr<SeventvEmotes> seventvEmotes;
const std::unique_ptr<Logging> logging; const std::unique_ptr<Logging> logging;
std::unique_ptr<ILinkResolver> linkResolver; std::unique_ptr<ILinkResolver> linkResolver;
std::unique_ptr<IStreamerMode> streamerMode; std::unique_ptr<IStreamerMode> streamerMode;

View file

@ -27,9 +27,9 @@
namespace chatterino { namespace chatterino {
void NotificationController::initialize(Settings &settings, const Paths &paths) NotificationController::NotificationController()
: liveStatusTimer_(new QTimer(this))
{ {
this->initialized_ = true;
for (const QString &channelName : this->twitchSetting_.getValue()) for (const QString &channelName : this->twitchSetting_.getValue())
{ {
this->channelMap[Platform::Twitch].append(channelName); this->channelMap[Platform::Twitch].append(channelName);
@ -43,8 +43,6 @@ void NotificationController::initialize(Settings &settings, const Paths &paths)
this->channelMap[Platform::Twitch].raw()); this->channelMap[Platform::Twitch].raw());
}); });
liveStatusTimer_ = new QTimer();
this->fetchFakeChannels(); this->fetchFakeChannels();
QObject::connect(this->liveStatusTimer_, &QTimer::timeout, [this] { QObject::connect(this->liveStatusTimer_, &QTimer::timeout, [this] {

View file

@ -2,7 +2,6 @@
#include "common/ChatterinoSetting.hpp" #include "common/ChatterinoSetting.hpp"
#include "common/SignalVector.hpp" #include "common/SignalVector.hpp"
#include "common/Singleton.hpp"
#include <QTimer> #include <QTimer>
@ -17,10 +16,13 @@ enum class Platform : uint8_t {
Twitch, // 0 Twitch, // 0
}; };
class NotificationController final : public Singleton, private QObject /**
* NotificationController is responsible for ?
*/
class NotificationController final : private QObject
{ {
public: public:
void initialize(Settings &settings, const Paths &paths) override; NotificationController();
bool isChannelNotified(const QString &channelName, Platform p); bool isChannelNotified(const QString &channelName, Platform p);
void updateChannelNotification(const QString &channelName, Platform p); void updateChannelNotification(const QString &channelName, Platform p);
@ -36,8 +38,6 @@ public:
NotificationModel *createModel(QObject *parent, Platform p); NotificationModel *createModel(QObject *parent, Platform p);
private: private:
bool initialized_ = false;
void fetchFakeChannels(); void fetchFakeChannels();
void removeFakeChannel(const QString channelName); void removeFakeChannel(const QString channelName);
void checkStream(bool live, QString channelName); void checkStream(bool live, QString channelName);

View file

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

View file

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