fix: close logging-channels when closing channels (#5592)

Co-authored-by: kornes <28986062+kornes@users.noreply.github.com>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix
2024-09-14 12:17:31 +02:00
committed by GitHub
parent 2afa227139
commit 694cc2dbff
13 changed files with 106 additions and 15 deletions
+7 -1
View File
@@ -149,6 +149,7 @@ Application::Application(Settings &_settings, const Paths &paths,
, args_(_args)
, themes(new Theme(paths))
, fonts(new Fonts(_settings))
, logging(new Logging(_settings))
, emotes(new Emotes)
, accounts(new AccountController)
, hotkeys(new HotkeyController)
@@ -175,7 +176,6 @@ Application::Application(Settings &_settings, const Paths &paths,
, ffzEmotes(new FfzEmotes)
, seventvEmotes(new SeventvEmotes)
, seventvEventAPI(makeSeventvEventAPI(_settings))
, logging(new Logging(_settings))
, linkResolver(new LinkResolver)
, streamerMode(new StreamerMode)
, twitchUsers(new TwitchUsers)
@@ -503,6 +503,7 @@ PubSub *Application::getTwitchPubSub()
ILogging *Application::getChatLogger()
{
assertInGuiThread();
assert(this->logging);
return this->logging.get();
}
@@ -697,4 +698,9 @@ IApplication *getApp()
return INSTANCE;
}
IApplication *tryGetApp()
{
return INSTANCE;
}
} // namespace chatterino
+4 -1
View File
@@ -144,6 +144,7 @@ public:
private:
std::unique_ptr<Theme> themes;
std::unique_ptr<Fonts> fonts;
const std::unique_ptr<Logging> logging;
std::unique_ptr<Emotes> emotes;
std::unique_ptr<AccountController> accounts;
std::unique_ptr<HotkeyController> hotkeys;
@@ -169,7 +170,6 @@ private:
std::unique_ptr<FfzEmotes> ffzEmotes;
std::unique_ptr<SeventvEmotes> seventvEmotes;
std::unique_ptr<SeventvEventAPI> seventvEventAPI;
const std::unique_ptr<Logging> logging;
std::unique_ptr<ILinkResolver> linkResolver;
std::unique_ptr<IStreamerMode> streamerMode;
std::unique_ptr<ITwitchUsers> twitchUsers;
@@ -239,4 +239,7 @@ private:
IApplication *getApp();
/// Might return `nullptr` if the app is being destroyed
IApplication *tryGetApp();
} // namespace chatterino
+5
View File
@@ -38,6 +38,11 @@ Channel::Channel(const QString &name, Type type)
Channel::~Channel()
{
auto *app = tryGetApp();
if (app)
{
app->getChatLogger()->closeChannel(this->name_, this->platform_);
}
this->destroyed.invoke();
}
+13 -3
View File
@@ -2,7 +2,6 @@
#include "messages/Message.hpp"
#include "singletons/helper/LoggingChannel.hpp"
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include <QDir>
@@ -58,7 +57,7 @@ void Logging::addMessage(const QString &channelName, MessagePtr message,
auto map = std::map<QString, std::unique_ptr<LoggingChannel>>();
this->loggingChannels_[platformName] = std::move(map);
auto &ref = this->loggingChannels_.at(platformName);
ref.emplace(channelName, std::move(channel));
ref.emplace(channelName, channel);
return;
}
auto chanIt = platIt->second.find(channelName);
@@ -66,7 +65,7 @@ void Logging::addMessage(const QString &channelName, MessagePtr message,
{
auto *channel = new LoggingChannel(channelName, platformName);
channel->addMessage(message, streamID);
platIt->second.emplace(channelName, std::move(channel));
platIt->second.emplace(channelName, channel);
}
else
{
@@ -74,4 +73,15 @@ void Logging::addMessage(const QString &channelName, MessagePtr message,
}
}
void Logging::closeChannel(const QString &channelName,
const QString &platformName)
{
auto platIt = this->loggingChannels_.find(platformName);
if (platIt == this->loggingChannels_.end())
{
return;
}
platIt->second.erase(channelName);
}
} // namespace chatterino
+6
View File
@@ -24,6 +24,9 @@ public:
virtual void addMessage(const QString &channelName, MessagePtr message,
const QString &platformName,
const QString &streamID) = 0;
virtual void closeChannel(const QString &channelName,
const QString &platformName) = 0;
};
class Logging : public ILogging
@@ -35,6 +38,9 @@ public:
const QString &platformName,
const QString &streamID) override;
void closeChannel(const QString &channelName,
const QString &platformName) override;
private:
using PlatformName = QString;
using ChannelName = QString;
+1 -1
View File
@@ -40,7 +40,7 @@ QString generateClosingString(
{
QString ret("# Stop logging at ");
ret.append(now.toString("yyyy-MM-dd HH:mm:ss"));
ret.append(now.toString("yyyy-MM-dd HH:mm:ss "));
ret.append(now.timeZoneAbbreviation());
ret.append(ENDLINE);