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>())
, fonts(new Fonts(_settings))
, 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>())
, windows(&this->emplace(new WindowManager(paths)))
, toasts(&this->emplace<Toasts>())
, imageUploader(&this->emplace<ImageUploader>())
, seventvAPI(&this->emplace<SeventvAPI>())
, crashHandler(&this->emplace(new CrashHandler(paths)))
, commands(&this->emplace<CommandController>())
, notifications(&this->emplace<NotificationController>())
, highlights(&this->emplace<HighlightController>())
, twitch(new TwitchIrcServer)
, ffzBadges(&this->emplace<FfzBadges>())
, seventvBadges(&this->emplace<SeventvBadges>())
, userData(new UserDataController(paths))
, sound(makeSoundController(_settings))
, twitchLiveController(&this->emplace<TwitchLiveController>())
, notifications(new NotificationController)
, twitchPubSub(new PubSub(TWITCH_PUBSUB_URL))
, twitchBadges(new TwitchBadges)
, chatterinoBadges(new ChatterinoBadges)
, bttvEmotes(new BttvEmotes)
, ffzEmotes(new FfzEmotes)
, seventvEmotes(new SeventvEmotes)
, logging(new Logging(_settings))
, linkResolver(new LinkResolver)
, streamerMode(new StreamerMode)
@ -168,13 +168,17 @@ void Application::fakeDtor()
this->twitchPubSub.reset();
this->twitchBadges.reset();
this->chatterinoBadges.reset();
this->bttvEmotes.reset();
this->ffzEmotes.reset();
this->seventvEmotes.reset();
// this->twitch.reset();
this->fonts.reset();
this->sound.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)
@ -357,8 +361,9 @@ IEmotes *Application::getEmotes()
AccountController *Application::getAccounts()
{
assertInGuiThread();
assert(this->accounts);
return this->accounts;
return this->accounts.get();
}
HotkeyController *Application::getHotkeys()
@ -400,8 +405,9 @@ CommandController *Application::getCommands()
NotificationController *Application::getNotifications()
{
assertInGuiThread();
assert(this->notifications);
return this->notifications;
return this->notifications.get();
}
HighlightController *Application::getHighlights()
@ -421,8 +427,9 @@ FfzBadges *Application::getFfzBadges()
SeventvBadges *Application::getSeventvBadges()
{
// 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()
@ -472,8 +479,9 @@ ImageUploader *Application::getImageUploader()
SeventvAPI *Application::getSeventvAPI()
{
assertInGuiThread();
assert(this->seventvAPI);
return this->seventvAPI;
return this->seventvAPI.get();
}
#ifdef CHATTERINO_HAVE_PLUGINS

View file

@ -147,28 +147,28 @@ private:
Theme *const themes{};
std::unique_ptr<Fonts> fonts{};
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{};
WindowManager *const windows{};
Toasts *const toasts{};
ImageUploader *const imageUploader{};
SeventvAPI *const seventvAPI{};
CrashHandler *const crashHandler{};
CommandController *const commands{};
NotificationController *const notifications{};
HighlightController *const highlights{};
std::unique_ptr<TwitchIrcServer> twitch;
FfzBadges *const ffzBadges{};
SeventvBadges *const seventvBadges{};
std::unique_ptr<UserDataController> userData;
std::unique_ptr<ISoundController> sound;
TwitchLiveController *const twitchLiveController{};
std::unique_ptr<NotificationController> notifications;
std::unique_ptr<PubSub> twitchPubSub;
std::unique_ptr<TwitchBadges> twitchBadges;
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;
std::unique_ptr<ILinkResolver> linkResolver;
std::unique_ptr<IStreamerMode> streamerMode;

View file

@ -27,9 +27,9 @@
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())
{
this->channelMap[Platform::Twitch].append(channelName);
@ -43,8 +43,6 @@ void NotificationController::initialize(Settings &settings, const Paths &paths)
this->channelMap[Platform::Twitch].raw());
});
liveStatusTimer_ = new QTimer();
this->fetchFakeChannels();
QObject::connect(this->liveStatusTimer_, &QTimer::timeout, [this] {

View file

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

View file

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

View file

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