fix: more carefully use app in NetworkPrivate/NetworkTask (#6698)

This commit is contained in:
pajlada
2025-12-30 17:10:42 +01:00
committed by GitHub
parent beb6cede51
commit b49fb258ce
3 changed files with 37 additions and 3 deletions
+18 -2
View File
@@ -59,8 +59,24 @@ void loadUncached(std::shared_ptr<NetworkData> &&data)
void loadCached(std::shared_ptr<NetworkData> &&data)
{
QFile cachedFile(getApp()->getPaths().cacheDirectory() + "/" +
data->getHash());
if (isAppAboutToQuit())
{
qCDebug(chatterinoHTTP)
<< "Skipping cached network load " << data->request.url()
<< "because app is about to quit";
return;
}
auto *app = tryGetApp();
if (!app)
{
qCDebug(chatterinoHTTP)
<< "Skipping cached network load " << data->request.url()
<< "because app is about to quit";
return;
}
QFile cachedFile(app->getPaths().cacheDirectory() + "/" + data->getHash());
if (!cachedFile.exists() || !cachedFile.open(QIODevice::ReadOnly))
{
+18 -1
View File
@@ -141,7 +141,24 @@ void NetworkTask::logReply()
void NetworkTask::writeToCache(const QByteArray &bytes) const
{
std::ignore = QtConcurrent::run([data = this->data_, bytes] {
QFile cachedFile(getApp()->getPaths().cacheDirectory() + "/" +
if (isAppAboutToQuit())
{
qCDebug(chatterinoHTTP)
<< "Skipping cache write for" << data->request.url()
<< "because app is about to quit";
return;
}
auto *app = tryGetApp();
if (!app)
{
qCDebug(chatterinoHTTP)
<< "Skipping cache write for" << data->request.url()
<< "because app is null";
return;
}
QFile cachedFile(app->getPaths().cacheDirectory() + "/" +
data->getHash());
if (cachedFile.open(QIODevice::WriteOnly))