Skip to content

Commit

Permalink
refactor: Remove most raw accesses into Application (#5104)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada authored Jan 19, 2024
1 parent 326a402 commit 4380ef8
Show file tree
Hide file tree
Showing 82 changed files with 552 additions and 452 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
- Dev: Renamed `tools` directory to `scripts`. (#5035)
- Dev: Refactor `ChannelView`, removing a bunch of clang-tidy warnings. (#4926)
- Dev: Refactor `IrcMessageHandler`, removing a bunch of clang-tidy warnings & changing its public API. (#4927)
- Dev: Removed almost all raw accesses into Application. (#5104)
- Dev: `Details` file properties tab is now populated on Windows. (#4912)
- Dev: Removed `Outcome` from network requests. (#4959)
- Dev: Added Tests for Windows and MacOS in CI. (#4970, #5032)
Expand Down
108 changes: 108 additions & 0 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,98 @@ int Application::run(QApplication &qtApp)
return qtApp.exec();
}

Theme *Application::getThemes()
{
assertInGuiThread();

return this->themes;
}

Fonts *Application::getFonts()
{
assertInGuiThread();

return this->fonts;
}

IEmotes *Application::getEmotes()
{
assertInGuiThread();

return this->emotes;
}

AccountController *Application::getAccounts()
{
assertInGuiThread();

return this->accounts;
}

HotkeyController *Application::getHotkeys()
{
assertInGuiThread();

return this->hotkeys;
}

WindowManager *Application::getWindows()
{
assertInGuiThread();
assert(this->windows);

return this->windows;
}

Toasts *Application::getToasts()
{
assertInGuiThread();

return this->toasts;
}

CrashHandler *Application::getCrashHandler()
{
assertInGuiThread();

return this->crashHandler;
}

CommandController *Application::getCommands()
{
assertInGuiThread();

return this->commands;
}

NotificationController *Application::getNotifications()
{
assertInGuiThread();

return this->notifications;
}

HighlightController *Application::getHighlights()
{
assertInGuiThread();

return this->highlights;
}

FfzBadges *Application::getFfzBadges()
{
assertInGuiThread();

return this->ffzBadges;
}

SeventvBadges *Application::getSeventvBadges()
{
// SeventvBadges handles its own locks, so we don't need to assert that this is called in the GUI thread

return this->seventvBadges;
}

IUserDataController *Application::getUserData()
{
assertInGuiThread();
Expand Down Expand Up @@ -348,6 +433,29 @@ IChatterinoBadges *Application::getChatterinoBadges()
return this->chatterinoBadges.get();
}

ImageUploader *Application::getImageUploader()
{
assertInGuiThread();

return this->imageUploader;
}

SeventvAPI *Application::getSeventvAPI()
{
assertInGuiThread();

return this->seventvAPI;
}

#ifdef CHATTERINO_HAVE_PLUGINS
PluginController *Application::getPlugins()
{
assertInGuiThread();

return this->plugins;
}
#endif

ITwitchIrcServer *Application::getTwitch()
{
assertInGuiThread();
Expand Down
119 changes: 30 additions & 89 deletions src/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class IApplication
virtual TwitchBadges *getTwitchBadges() = 0;
virtual ImageUploader *getImageUploader() = 0;
virtual SeventvAPI *getSeventvAPI() = 0;
#ifdef CHATTERINO_HAVE_PLUGINS
virtual PluginController *getPlugins() = 0;
#endif
virtual Updates &getUpdates() = 0;
};

Expand Down Expand Up @@ -122,38 +125,43 @@ class Application : public IApplication

friend void test();

private:
Theme *const themes{};
Fonts *const fonts{};

public:
Emotes *const emotes{};

private:
AccountController *const accounts{};
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{};

public:
TwitchIrcServer *const twitch{};

private:
FfzBadges *const ffzBadges{};
SeventvBadges *const seventvBadges{};
UserDataController *const userData{};
ISoundController *const sound{};

private:
TwitchLiveController *const twitchLiveController{};
std::unique_ptr<PubSub> twitchPubSub;
std::unique_ptr<TwitchBadges> twitchBadges;
std::unique_ptr<ChatterinoBadges> chatterinoBadges;
const std::unique_ptr<Logging> logging;

public:
#ifdef CHATTERINO_HAVE_PLUGINS
PluginController *const plugins{};
#endif

public:
const Paths &getPaths() override
{
return this->paths_;
Expand All @@ -162,99 +170,32 @@ class Application : public IApplication
{
return this->args_;
}
Theme *getThemes() override
{
assertInGuiThread();

return this->themes;
}
Fonts *getFonts() override
{
assertInGuiThread();

return this->fonts;
}
Theme *getThemes() override;
Fonts *getFonts() override;
IEmotes *getEmotes() override;
AccountController *getAccounts() override
{
assertInGuiThread();

return this->accounts;
}
HotkeyController *getHotkeys() override
{
assertInGuiThread();

return this->hotkeys;
}
WindowManager *getWindows() override
{
assertInGuiThread();

return this->windows;
}
Toasts *getToasts() override
{
assertInGuiThread();

return this->toasts;
}
CrashHandler *getCrashHandler() override
{
assertInGuiThread();

return this->crashHandler;
}
CommandController *getCommands() override
{
assertInGuiThread();

return this->commands;
}
NotificationController *getNotifications() override
{
assertInGuiThread();

return this->notifications;
}
HighlightController *getHighlights() override
{
assertInGuiThread();

return this->highlights;
}
AccountController *getAccounts() override;
HotkeyController *getHotkeys() override;
WindowManager *getWindows() override;
Toasts *getToasts() override;
CrashHandler *getCrashHandler() override;
CommandController *getCommands() override;
NotificationController *getNotifications() override;
HighlightController *getHighlights() override;
ITwitchIrcServer *getTwitch() override;
PubSub *getTwitchPubSub() override;
Logging *getChatLogger() override;
FfzBadges *getFfzBadges() override
{
assertInGuiThread();

return this->ffzBadges;
}
SeventvBadges *getSeventvBadges() override
{
assertInGuiThread();

return this->seventvBadges;
}
FfzBadges *getFfzBadges() override;
SeventvBadges *getSeventvBadges() override;
IUserDataController *getUserData() override;
ISoundController *getSound() override;
ITwitchLiveController *getTwitchLiveController() override;
TwitchBadges *getTwitchBadges() override;
IChatterinoBadges *getChatterinoBadges() override;
ImageUploader *getImageUploader() override
{
assertInGuiThread();

return this->imageUploader;
}
SeventvAPI *getSeventvAPI() override
{
assertInGuiThread();

return this->seventvAPI;
}
ImageUploader *getImageUploader() override;
SeventvAPI *getSeventvAPI() override;
#ifdef CHATTERINO_HAVE_PLUGINS
PluginController *getPlugins() override;
#endif
Updates &getUpdates() override
{
assertInGuiThread();
Expand Down
8 changes: 5 additions & 3 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ const std::unordered_map<QString, VariableReplacer> COMMAND_VARS{
[](const auto &altText, const auto &channel, const auto *message) {
(void)(channel); //unused
(void)(message); //unused
auto uid = getApp()->accounts->twitch.getCurrent()->getUserId();
auto uid =
getIApp()->getAccounts()->twitch.getCurrent()->getUserId();
return uid.isEmpty() ? altText : uid;
},
},
Expand All @@ -129,7 +130,8 @@ const std::unordered_map<QString, VariableReplacer> COMMAND_VARS{
[](const auto &altText, const auto &channel, const auto *message) {
(void)(channel); //unused
(void)(message); //unused
auto name = getApp()->accounts->twitch.getCurrent()->getUserName();
auto name =
getIApp()->getAccounts()->twitch.getCurrent()->getUserName();
return name.isEmpty() ? altText : name;
},
},
Expand Down Expand Up @@ -560,7 +562,7 @@ bool CommandController::registerPluginCommand(const QString &commandName)
}

this->commands_[commandName] = [commandName](const CommandContext &ctx) {
return getApp()->plugins->tryExecPluginCommand(commandName, ctx);
return getIApp()->getPlugins()->tryExecPluginCommand(commandName, ctx);
};
this->pluginCommands_.append(commandName);
return true;
Expand Down
Loading

0 comments on commit 4380ef8

Please sign in to comment.