From 7f4665e3cca891bdd42d67a5a82a8c6561d1c86e Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 14 Jul 2023 21:07:34 +0300 Subject: [PATCH 01/37] format Signed-off-by: Trial97 --- .../modplatform/flame/FileResolvingTask.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/launcher/modplatform/flame/FileResolvingTask.cpp b/launcher/modplatform/flame/FileResolvingTask.cpp index ce7a60551..f84002385 100644 --- a/launcher/modplatform/flame/FileResolvingTask.cpp +++ b/launcher/modplatform/flame/FileResolvingTask.cpp @@ -128,12 +128,13 @@ void Flame::FileResolvingTask::netJobFinished() m_checkJob->start(); } -void Flame::FileResolvingTask::modrinthCheckFinished() { +void Flame::FileResolvingTask::modrinthCheckFinished() +{ setProgress(2, 3); qDebug() << "Finished with blocked mods : " << blockedProjects.size(); for (auto it = blockedProjects.keyBegin(); it != blockedProjects.keyEnd(); it++) { - auto &out = *it; + auto& out = *it; auto bytes = blockedProjects[out]; if (!out->resolved) { continue; @@ -153,15 +154,13 @@ void Flame::FileResolvingTask::modrinthCheckFinished() { out->resolved = false; } } - //copy to an output list and filter out projects found on modrinth + // copy to an output list and filter out projects found on modrinth auto block = std::make_shared>(); auto it = blockedProjects.keys(); - std::copy_if(it.begin(), it.end(), std::back_inserter(*block), [](File *f) { - return !f->resolved; - }); - //Display not found mods early + std::copy_if(it.begin(), it.end(), std::back_inserter(*block), [](File* f) { return !f->resolved; }); + // Display not found mods early if (!block->empty()) { - //blocked mods found, we need the slug for displaying.... we need another job :D ! + // blocked mods found, we need the slug for displaying.... we need another job :D ! m_slugJob.reset(new NetJob("Slug Job", m_network)); int index = 0; for (auto mod : *block) { @@ -173,8 +172,8 @@ void Flame::FileResolvingTask::modrinthCheckFinished() { QObject::connect(dl.get(), &Net::Download::succeeded, [block, index, output]() { auto mod = block->at(index); // use the shared_ptr so it is captured and only freed when we are done auto json = QJsonDocument::fromJson(*output); - auto base = Json::requireString(Json::requireObject(Json::requireObject(Json::requireObject(json),"data"),"links"), - "websiteUrl"); + auto base = + Json::requireString(Json::requireObject(Json::requireObject(Json::requireObject(json), "data"), "links"), "websiteUrl"); auto link = QString("%1/download/%2").arg(base, QString::number(mod->fileId)); mod->websiteUrl = link; }); From d3dc00dcab31ecf4a8ae5886db310ff0bedc9018 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 14 Jul 2023 21:07:53 +0300 Subject: [PATCH 02/37] made concurent task fail Signed-off-by: Trial97 --- .../modplatform/flame/FileResolvingTask.cpp | 1 - launcher/tasks/ConcurrentTask.cpp | 20 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/launcher/modplatform/flame/FileResolvingTask.cpp b/launcher/modplatform/flame/FileResolvingTask.cpp index f84002385..7695dfcdf 100644 --- a/launcher/modplatform/flame/FileResolvingTask.cpp +++ b/launcher/modplatform/flame/FileResolvingTask.cpp @@ -112,7 +112,6 @@ void Flame::FileResolvingTask::netJobFinished() connect(m_checkJob.get(), &NetJob::failed, this, [this, step_progress](QString reason) { step_progress->state = TaskStepState::Failed; stepProgress(*step_progress); - emitFailed(reason); }); connect(m_checkJob.get(), &NetJob::stepProgress, this, &FileResolvingTask::propogateStepProgress); connect(m_checkJob.get(), &NetJob::progress, this, [this, step_progress](qint64 current, qint64 total) { diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index 9aada5e69..7c7cfaf72 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -118,8 +118,11 @@ void ConcurrentTask::startNext() if (m_aborted || m_doing.count() > m_total_max_size) return; - if (m_queue.isEmpty() && m_doing.isEmpty() && !wasSuccessful()) { - emitSucceeded(); + if (m_queue.isEmpty() && m_doing.isEmpty() && isRunning()) { + if (m_failed.isEmpty()) + emitSucceeded(); + else + emitFailed(tr("One or more subtasks failed")); return; } @@ -194,7 +197,7 @@ void ConcurrentTask::subTaskStatus(Task::Ptr task, const QString& msg) auto task_progress = m_task_progress.value(task->getUid()); task_progress->status = msg; task_progress->state = TaskStepState::Running; - + emit stepProgress(*task_progress); if (totalSize() == 1) { @@ -207,7 +210,7 @@ void ConcurrentTask::subTaskDetails(Task::Ptr task, const QString& msg) auto task_progress = m_task_progress.value(task->getUid()); task_progress->details = msg; task_progress->state = TaskStepState::Running; - + emit stepProgress(*task_progress); if (totalSize() == 1) { @@ -220,7 +223,7 @@ void ConcurrentTask::subTaskProgress(Task::Ptr task, qint64 current, qint64 tota auto task_progress = m_task_progress.value(task->getUid()); task_progress->update(current, total); - + emit stepProgress(*task_progress); updateStepProgress(*task_progress, Operation::CHANGED); updateState(); @@ -233,7 +236,7 @@ void ConcurrentTask::subTaskProgress(Task::Ptr task, qint64 current, qint64 tota void ConcurrentTask::subTaskStepProgress(Task::Ptr task, TaskStepProgress const& task_progress) { Operation op = Operation::ADDED; - + if (!m_task_progress.contains(task_progress.uid)) { m_task_progress.insert(task_progress.uid, std::make_shared(task_progress)); op = Operation::ADDED; @@ -254,12 +257,10 @@ void ConcurrentTask::subTaskStepProgress(Task::Ptr task, TaskStepProgress const& emit stepProgress(*tp.get()); updateStepProgress(*tp.get(), op); } - } void ConcurrentTask::updateStepProgress(TaskStepProgress const& changed_progress, Operation op) { - switch (op) { case Operation::ADDED: m_stepProgress += changed_progress.current; @@ -274,9 +275,8 @@ void ConcurrentTask::updateStepProgress(TaskStepProgress const& changed_progress m_stepTotalProgress -= changed_progress.old_total; m_stepProgress += changed_progress.current; m_stepTotalProgress += changed_progress.total; - break; + break; } - } void ConcurrentTask::updateState() From 0880d4d37b654ffe68c4497a78883e73933dfe98 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 15 Jul 2023 09:16:37 +0300 Subject: [PATCH 03/37] made sure abort signal is catched in cocurent task Signed-off-by: Trial97 --- launcher/tasks/ConcurrentTask.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index 7c7cfaf72..7bb02e57d 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -88,6 +88,7 @@ bool ConcurrentTask::abort() QMutableHashIterator doing_iter(m_doing); while (doing_iter.hasNext()) { auto task = doing_iter.next(); + disconnect(task.value().get(), &Task::aborted, this, 0); suceedeed &= (task.value())->abort(); } @@ -133,6 +134,9 @@ void ConcurrentTask::startNext() connect(next.get(), &Task::succeeded, this, [this, next]() { subTaskSucceeded(next); }); connect(next.get(), &Task::failed, this, [this, next](QString msg) { subTaskFailed(next, msg); }); + // this should never happen but if it does better to fail the task that being stuck + // most + connect(next.get(), &Task::aborted, this, [this, next] { subTaskFailed(next, "Aborted"); }); connect(next.get(), &Task::status, this, [this, next](QString msg) { subTaskStatus(next, msg); }); connect(next.get(), &Task::details, this, [this, next](QString msg) { subTaskDetails(next, msg); }); From a7e0c9db9694a153a94cf0c924296576b0e9b767 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 15 Jul 2023 12:01:07 +0300 Subject: [PATCH 04/37] connected failed event for some tasks Signed-off-by: Trial97 --- launcher/modplatform/EnsureMetadataTask.cpp | 2 ++ .../modplatform/flame/FlameCheckUpdate.cpp | 7 ++--- launcher/modplatform/flame/FlameCheckUpdate.h | 8 +++++- .../flame/FlameInstanceCreationTask.cpp | 1 + .../modplatform/flame/FlamePackExportTask.cpp | 1 + .../modrinth/ModrinthCheckUpdate.cpp | 14 ++++------ launcher/ui/dialogs/ModUpdateDialog.cpp | 8 +++++- .../ui/pages/modplatform/flame/FlamePage.cpp | 12 ++++----- .../modplatform/modrinth/ModrinthPage.cpp | 5 ++++ .../pages/modplatform/technic/TechnicPage.cpp | 10 ++++--- .../ui/widgets/VariableSizedImageObject.cpp | 26 +++++++++++++------ 11 files changed, 63 insertions(+), 31 deletions(-) diff --git a/launcher/modplatform/EnsureMetadataTask.cpp b/launcher/modplatform/EnsureMetadataTask.cpp index c3eadd06d..22581e43e 100644 --- a/launcher/modplatform/EnsureMetadataTask.cpp +++ b/launcher/modplatform/EnsureMetadataTask.cpp @@ -148,6 +148,7 @@ void EnsureMetadataTask::executeTask() if (m_current_task) m_current_task.reset(); }); + connect(project_task.get(), &Task::failed, this, &EnsureMetadataTask::emitFailed); m_current_task = project_task; project_task->start(); @@ -158,6 +159,7 @@ void EnsureMetadataTask::executeTask() if (m_current_task) m_current_task.reset(); }); + connect(version_task.get(), &Task::failed, this, &EnsureMetadataTask::emitFailed); if (m_mods.size() > 1) setStatus(tr("Requesting metadata information from %1...").arg(ProviderCaps.readableName(m_provider))); diff --git a/launcher/modplatform/flame/FlameCheckUpdate.cpp b/launcher/modplatform/flame/FlameCheckUpdate.cpp index a2628e34c..092133f1a 100644 --- a/launcher/modplatform/flame/FlameCheckUpdate.cpp +++ b/launcher/modplatform/flame/FlameCheckUpdate.cpp @@ -23,7 +23,7 @@ bool FlameCheckUpdate::abort() return true; } -ModPlatform::IndexedPack getProjectInfo(ModPlatform::IndexedVersion& ver_info) +ModPlatform::IndexedPack FlameCheckUpdate::getProjectInfo(ModPlatform::IndexedVersion& ver_info) { ModPlatform::IndexedPack pack; @@ -56,6 +56,7 @@ ModPlatform::IndexedPack getProjectInfo(ModPlatform::IndexedVersion& ver_info) } }); + connect(get_project_job, &NetJob::failed, this, &FlameCheckUpdate::emitFailed); QObject::connect(get_project_job, &NetJob::finished, [&loop, get_project_job] { get_project_job->deleteLater(); loop.quit(); @@ -67,7 +68,7 @@ ModPlatform::IndexedPack getProjectInfo(ModPlatform::IndexedVersion& ver_info) return pack; } -ModPlatform::IndexedVersion getFileInfo(int addonId, int fileId) +ModPlatform::IndexedVersion FlameCheckUpdate::getFileInfo(int addonId, int fileId) { ModPlatform::IndexedVersion ver; @@ -99,7 +100,7 @@ ModPlatform::IndexedVersion getFileInfo(int addonId, int fileId) qDebug() << doc; } }); - + connect(get_file_info_job, &NetJob::failed, this, &FlameCheckUpdate::emitFailed); QObject::connect(get_file_info_job, &NetJob::finished, [&loop, get_file_info_job] { get_file_info_job->deleteLater(); loop.quit(); diff --git a/launcher/modplatform/flame/FlameCheckUpdate.h b/launcher/modplatform/flame/FlameCheckUpdate.h index 4a98d684f..0dbd199e7 100644 --- a/launcher/modplatform/flame/FlameCheckUpdate.h +++ b/launcher/modplatform/flame/FlameCheckUpdate.h @@ -8,7 +8,10 @@ class FlameCheckUpdate : public CheckUpdateTask { Q_OBJECT public: - FlameCheckUpdate(QList& mods, std::list& mcVersions, std::optional loaders, std::shared_ptr mods_folder) + FlameCheckUpdate(QList& mods, + std::list& mcVersions, + std::optional loaders, + std::shared_ptr mods_folder) : CheckUpdateTask(mods, mcVersions, loaders, mods_folder) {} @@ -19,6 +22,9 @@ class FlameCheckUpdate : public CheckUpdateTask { void executeTask() override; private: + ModPlatform::IndexedPack getProjectInfo(ModPlatform::IndexedVersion& ver_info); + ModPlatform::IndexedVersion getFileInfo(int addonId, int fileId); + NetJob* m_net_job = nullptr; bool m_was_aborted = false; diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index b57db288a..fa5057e5c 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -229,6 +229,7 @@ bool FlameCreationTask::updateInstance() m_files_to_remove.append(old_minecraft_dir.absoluteFilePath(relative_path)); } }); + connect(job.get(), &Task::failed, this, [](QString reason) { qCritical() << "Failed to get files: " << reason; }); connect(job.get(), &Task::finished, &loop, &QEventLoop::quit); m_process_update_file_info_job = job; diff --git a/launcher/modplatform/flame/FlamePackExportTask.cpp b/launcher/modplatform/flame/FlamePackExportTask.cpp index ac0da2142..69f88127e 100644 --- a/launcher/modplatform/flame/FlamePackExportTask.cpp +++ b/launcher/modplatform/flame/FlamePackExportTask.cpp @@ -327,6 +327,7 @@ void FlamePackExportTask::getProjectsInfo() } buildZip(); }); + connect(projTask.get(), &Task::failed, this, &FlamePackExportTask::emitFailed); task.reset(projTask); task->start(); } diff --git a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp index a7c22832a..c83ef2fd4 100644 --- a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp +++ b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp @@ -73,8 +73,6 @@ void ModrinthCheckUpdate::executeTask() auto response = std::make_shared(); auto job = api.latestVersions(hashes, best_hash_type, m_game_versions, m_loaders, response); - QEventLoop lock; - connect(job.get(), &Task::succeeded, this, [this, response, &mappings, best_hash_type, job] { QJsonParseError parse_error{}; QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); @@ -83,7 +81,7 @@ void ModrinthCheckUpdate::executeTask() << " reason: " << parse_error.errorString(); qWarning() << *response; - failed(parse_error.errorString()); + emitFailed(parse_error.errorString()); return; } @@ -167,19 +165,17 @@ void ModrinthCheckUpdate::executeTask() } } } catch (Json::JsonException& e) { - failed(e.cause() + " : " + e.what()); + emitFailed(e.cause() + " : " + e.what()); + return; } + emitSucceeded(); }); - connect(job.get(), &Task::finished, &lock, &QEventLoop::quit); + connect(job.get(), &Task::failed, this, &ModrinthCheckUpdate::emitFailed); setStatus(tr("Waiting for the API response from Modrinth...")); setProgress(1, 3); m_net_job = qSharedPointerObjectCast(job); job->start(); - - lock.exec(); - - emitSucceeded(); } diff --git a/launcher/ui/dialogs/ModUpdateDialog.cpp b/launcher/ui/dialogs/ModUpdateDialog.cpp index 8618b9240..df45cbbcf 100644 --- a/launcher/ui/dialogs/ModUpdateDialog.cpp +++ b/launcher/ui/dialogs/ModUpdateDialog.cpp @@ -271,6 +271,8 @@ auto ModUpdateDialog::ensureMetadata() -> bool connect(modrinth_task.get(), &EnsureMetadataTask::metadataFailed, [this, &should_try_others](Mod* candidate) { onMetadataFailed(candidate, should_try_others.find(candidate->internal_id()).value(), ModPlatform::ResourceProvider::MODRINTH); }); + connect(modrinth_task.get(), &EnsureMetadataTask::failed, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); }); if (modrinth_task->getHashingTask()) seq.addTask(modrinth_task->getHashingTask()); @@ -284,6 +286,8 @@ auto ModUpdateDialog::ensureMetadata() -> bool connect(flame_task.get(), &EnsureMetadataTask::metadataFailed, [this, &should_try_others](Mod* candidate) { onMetadataFailed(candidate, should_try_others.find(candidate->internal_id()).value(), ModPlatform::ResourceProvider::FLAME); }); + connect(flame_task.get(), &EnsureMetadataTask::failed, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); }); if (flame_task->getHashingTask()) seq.addTask(flame_task->getHashingTask()); @@ -337,12 +341,14 @@ void ModUpdateDialog::onMetadataFailed(Mod* mod, bool try_others, ModPlatform::R auto task = makeShared(mod, index_dir, next(first_choice)); connect(task.get(), &EnsureMetadataTask::metadataReady, [this](Mod* candidate) { onMetadataEnsured(candidate); }); connect(task.get(), &EnsureMetadataTask::metadataFailed, [this](Mod* candidate) { onMetadataFailed(candidate, false); }); + connect(task.get(), &EnsureMetadataTask::failed, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); }); m_second_try_metadata->addTask(task); } else { QString reason{ tr("Couldn't find a valid version on the selected mod provider(s)") }; - m_failed_metadata.append({mod, reason}); + m_failed_metadata.append({ mod, reason }); } } diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.cpp b/launcher/ui/pages/modplatform/flame/FlamePage.cpp index cef26bb6b..133a3981a 100644 --- a/launcher/ui/pages/modplatform/flame/FlamePage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlamePage.cpp @@ -34,6 +34,7 @@ */ #include "FlamePage.h" +#include "ui/dialogs/CustomMessageBox.h" #include "ui_FlamePage.h" #include @@ -42,9 +43,9 @@ #include "FlameModel.h" #include "InstanceImportTask.h" #include "Json.h" +#include "modplatform/flame/FlameAPI.h" #include "ui/dialogs/NewInstanceDialog.h" #include "ui/widgets/ProjectItem.h" -#include "modplatform/flame/FlameAPI.h" static FlameAPI api; @@ -171,6 +172,8 @@ void FlamePage::onSelectionChanged(QModelIndex curr, QModelIndex prev) suggestCurrent(); }); QObject::connect(netJob, &NetJob::finished, this, [response, netJob] { netJob->deleteLater(); }); + connect(netJob, &NetJob::failed, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); }); netJob->start(); } else { for (auto version : current.versions) { @@ -252,10 +255,8 @@ void FlamePage::updateUi() text += "
" + tr(" by ") + authorStrs.join(", "); } - if(current.extraInfoLoaded) { - if (!current.extra.issuesUrl.isEmpty() - || !current.extra.sourceUrl.isEmpty() - || !current.extra.wikiUrl.isEmpty()) { + if (current.extraInfoLoaded) { + if (!current.extra.issuesUrl.isEmpty() || !current.extra.sourceUrl.isEmpty() || !current.extra.wikiUrl.isEmpty()) { text += "

" + tr("External links:") + "
"; } @@ -267,7 +268,6 @@ void FlamePage::updateUi() text += "- " + tr("Source code: %1").arg(current.extra.sourceUrl) + "
"; } - text += "
"; text += api.getModDescription(current.addonId).toUtf8(); diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index c71dd9038..68ce8fd63 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -35,6 +35,7 @@ */ #include "ModrinthPage.h" +#include "ui/dialogs/CustomMessageBox.h" #include "ui_ModrinthPage.h" #include "ModrinthModel.h" @@ -163,6 +164,8 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev) suggestCurrent(); }); QObject::connect(netJob, &NetJob::finished, this, [response, netJob] { netJob->deleteLater(); }); + connect(netJob, &NetJob::failed, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); }); netJob->start(); } else updateUI(); @@ -215,6 +218,8 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, QModelIndex prev) suggestCurrent(); }); QObject::connect(netJob, &NetJob::finished, this, [response, netJob] { netJob->deleteLater(); }); + connect(netJob, &NetJob::failed, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); }); netJob->start(); } else { diff --git a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp index fc678fa20..c7f74d5ac 100644 --- a/launcher/ui/pages/modplatform/technic/TechnicPage.cpp +++ b/launcher/ui/pages/modplatform/technic/TechnicPage.cpp @@ -34,6 +34,7 @@ */ #include "TechnicPage.h" +#include "ui/dialogs/CustomMessageBox.h" #include "ui_TechnicPage.h" #include @@ -41,16 +42,15 @@ #include "ui/dialogs/NewInstanceDialog.h" #include "BuildConfig.h" +#include "Json.h" #include "TechnicModel.h" #include "modplatform/technic/SingleZipPackInstallTask.h" #include "modplatform/technic/SolderPackInstallTask.h" -#include "Json.h" #include "Application.h" #include "modplatform/technic/SolderPackManifest.h" -TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget *parent) - : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog) +TechnicPage::TechnicPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), ui(new Ui::TechnicPage), dialog(dialog) { ui->setupUi(this); connect(ui->searchButton, &QPushButton::clicked, this, &TechnicPage::triggerSearch); @@ -201,6 +201,8 @@ void TechnicPage::suggestCurrent() metadataLoaded(); }); + connect(jobPtr.get(), &NetJob::failed, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); }); jobPtr = netJob; jobPtr->start(); @@ -252,6 +254,8 @@ void TechnicPage::metadataLoaded() netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), response)); QObject::connect(netJob.get(), &NetJob::succeeded, this, &TechnicPage::onSolderLoaded); + connect(jobPtr.get(), &NetJob::failed, + [this](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->exec(); }); jobPtr = netJob; jobPtr->start(); diff --git a/launcher/ui/widgets/VariableSizedImageObject.cpp b/launcher/ui/widgets/VariableSizedImageObject.cpp index 991b4a047..a787f61e6 100644 --- a/launcher/ui/widgets/VariableSizedImageObject.cpp +++ b/launcher/ui/widgets/VariableSizedImageObject.cpp @@ -101,14 +101,7 @@ void VariableSizedImageObject::loadImage(QTextDocument* doc, const QUrl& source, auto full_entry_path = entry->getFullPath(); auto source_url = source; - connect(job, &NetJob::succeeded, this, [this, doc, full_entry_path, source_url, posInDocument] { - qDebug() << "Loaded resource at" << full_entry_path; - - // If we flushed, don't proceed. - if (!m_fetching_images.contains(source_url)) - return; - - QImage image(full_entry_path); + auto loadImage = [this, doc, full_entry_path, source_url, posInDocument](const QImage& image) { doc->addResource(QTextDocument::ImageResource, source_url, image); parseImage(doc, image, posInDocument); @@ -120,6 +113,23 @@ void VariableSizedImageObject::loadImage(QTextDocument* doc, const QUrl& source, doc->setPageSize(size); m_fetching_images.remove(source_url); + }; + connect(job, &NetJob::succeeded, this, [this, full_entry_path, source_url, loadImage] { + qDebug() << "Loaded resource at:" << full_entry_path; + // If we flushed, don't proceed. + if (!m_fetching_images.contains(source_url)) + return; + + QImage image(full_entry_path); + loadImage(image); + }); + connect(job, &NetJob::failed, this, [this, full_entry_path, source_url, loadImage](QString reason) { + qWarning() << "Failed resource at:" << full_entry_path << " because:" << reason; + // If we flushed, don't proceed. + if (!m_fetching_images.contains(source_url)) + return; + + loadImage(QImage()); }); connect(job, &NetJob::finished, job, &NetJob::deleteLater); From 6cf7c0a647e513978e692f02babd0140d909c3af Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 15 Jul 2023 20:17:16 +0300 Subject: [PATCH 05/37] Connected last fail signals Signed-off-by: Trial97 --- .../mod/tasks/GetModDependenciesTask.cpp | 4 +++- launcher/modplatform/ResourceAPI.h | 3 +++ .../modplatform/helpers/NetworkResourceAPI.cpp | 15 ++++++++++++++- launcher/ui/pages/modplatform/ResourceModel.cpp | 8 ++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp b/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp index f8ecdb33e..09fc66f59 100644 --- a/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp +++ b/launcher/minecraft/mod/tasks/GetModDependenciesTask.cpp @@ -180,7 +180,9 @@ Task::Ptr GetModDependenciesTask::prepareDependencyTask(const ModPlatform::Depen ResourceAPI::DependencySearchArgs args = { dep, m_version, m_loaderType }; ResourceAPI::DependencySearchCallbacks callbacks; - + callbacks.on_fail = [](QString reason, int) { + qCritical() << tr("A network error occurred. Could not load project dependenies:%1").arg(reason); + }; callbacks.on_succeed = [dep, provider, pDep, level, this](auto& doc, auto& pack) { try { QJsonArray arr; diff --git a/launcher/modplatform/ResourceAPI.h b/launcher/modplatform/ResourceAPI.h index d3277761e..6f92fa108 100644 --- a/launcher/modplatform/ResourceAPI.h +++ b/launcher/modplatform/ResourceAPI.h @@ -99,6 +99,7 @@ class ResourceAPI { }; struct VersionSearchCallbacks { std::function on_succeed; + std::function on_fail; }; struct ProjectInfoArgs { @@ -109,6 +110,7 @@ class ResourceAPI { }; struct ProjectInfoCallbacks { std::function on_succeed; + std::function on_fail; }; struct DependencySearchArgs { @@ -119,6 +121,7 @@ class ResourceAPI { struct DependencySearchCallbacks { std::function on_succeed; + std::function on_fail; }; public: diff --git a/launcher/modplatform/helpers/NetworkResourceAPI.cpp b/launcher/modplatform/helpers/NetworkResourceAPI.cpp index c278f800d..771486005 100644 --- a/launcher/modplatform/helpers/NetworkResourceAPI.cpp +++ b/launcher/modplatform/helpers/NetworkResourceAPI.cpp @@ -70,7 +70,7 @@ Task::Ptr NetworkResourceAPI::getProjectInfo(ProjectInfoArgs&& args, ProjectInfo callbacks.on_succeed(doc, args.pack); }); - + QObject::connect(job.get(), &NetJob::failed, [callbacks](QString reason) { callbacks.on_fail(reason); }); return job; } @@ -99,6 +99,13 @@ Task::Ptr NetworkResourceAPI::getProjectVersions(VersionSearchArgs&& args, Versi callbacks.on_succeed(doc, args.pack); }); + QObject::connect(netJob.get(), &NetJob::failed, [&netJob, callbacks](QString reason) { + int network_error_code = -1; + if (auto* failed_action = netJob->getFailedActions().at(0); failed_action && failed_action->m_reply) + network_error_code = failed_action->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + callbacks.on_fail(reason, network_error_code); + }); return netJob; } @@ -143,6 +150,12 @@ Task::Ptr NetworkResourceAPI::getDependencyVersion(DependencySearchArgs&& args, callbacks.on_succeed(doc, args.dependency); }); + QObject::connect(netJob.get(), &NetJob::failed, [&netJob, callbacks](QString reason) { + int network_error_code = -1; + if (auto* failed_action = netJob->getFailedActions().at(0); failed_action && failed_action->m_reply) + network_error_code = failed_action->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + callbacks.on_fail(reason, network_error_code); + }); return netJob; }; diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp index 49405a02b..170b016ad 100644 --- a/launcher/ui/pages/modplatform/ResourceModel.cpp +++ b/launcher/ui/pages/modplatform/ResourceModel.cpp @@ -178,6 +178,10 @@ void ResourceModel::loadEntry(QModelIndex& entry) return; versionRequestSucceeded(doc, pack, entry); }; + if (!callbacks.on_fail) + callbacks.on_fail = [](QString reason, int) { + QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load project versions:%1").arg(reason)); + }; if (auto job = m_api->getProjectVersions(std::move(args), std::move(callbacks)); job) runInfoJob(job); @@ -194,6 +198,10 @@ void ResourceModel::loadEntry(QModelIndex& entry) return; infoRequestSucceeded(doc, pack, entry); }; + if (!callbacks.on_fail) + callbacks.on_fail = [](QString reason) { + QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load project info:%1").arg(reason)); + }; if (auto job = m_api->getProjectInfo(std::move(args), std::move(callbacks)); job) runInfoJob(job); From f42514a1a3848f750241661138b89fdead1a3370 Mon Sep 17 00:00:00 2001 From: Alexandru Ionut Tripon Date: Sun, 16 Jul 2023 00:38:39 +0300 Subject: [PATCH 06/37] Update launcher/tasks/ConcurrentTask.cpp Co-authored-by: seth Signed-off-by: Alexandru Ionut Tripon --- launcher/tasks/ConcurrentTask.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index 7bb02e57d..b8d6ae598 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -134,8 +134,7 @@ void ConcurrentTask::startNext() connect(next.get(), &Task::succeeded, this, [this, next]() { subTaskSucceeded(next); }); connect(next.get(), &Task::failed, this, [this, next](QString msg) { subTaskFailed(next, msg); }); - // this should never happen but if it does better to fail the task that being stuck - // most + // this should never happen but if it does, it's better to fail the task than get stuck connect(next.get(), &Task::aborted, this, [this, next] { subTaskFailed(next, "Aborted"); }); connect(next.get(), &Task::status, this, [this, next](QString msg) { subTaskStatus(next, msg); }); From 47dbb0911509804d8df795d2db0581ab73955e87 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 7 Oct 2023 00:21:40 +0300 Subject: [PATCH 07/37] Improvements to concurrent task Signed-off-by: Trial97 --- launcher/tasks/ConcurrentTask.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index 6cfd864cc..2ab69d04f 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -152,8 +152,12 @@ void ConcurrentTask::startNext() QMetaObject::invokeMethod(next.get(), &Task::start, Qt::QueuedConnection); // Allow going up the number of concurrent tasks in case of tasks being added in the middle of a running task. - for (int i = 0; i < num_starts; i++) + for (int i = 0; i < num_starts; i++) { + QCoreApplication::processEvents(); + if (m_aborted || m_doing.count() > m_total_max_size) + return; QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection); + } } void ConcurrentTask::subTaskSucceeded(Task::Ptr task) From 8dd640819dd961d1195f515713e0d8938763da54 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 9 Oct 2023 01:50:14 +0300 Subject: [PATCH 08/37] removed processEvents from ConcurrentTask Signed-off-by: Trial97 --- launcher/net/NetJob.cpp | 18 +++-- launcher/net/NetJob.h | 5 +- launcher/tasks/ConcurrentTask.cpp | 96 ++++++++++++-------------- launcher/tasks/ConcurrentTask.h | 9 +-- launcher/tasks/MultipleOptionsTask.cpp | 11 ++- launcher/tasks/MultipleOptionsTask.h | 6 +- launcher/tasks/SequentialTask.cpp | 13 ++-- launcher/tasks/SequentialTask.h | 4 +- tests/Task_test.cpp | 9 ++- 9 files changed, 84 insertions(+), 87 deletions(-) diff --git a/launcher/net/NetJob.cpp b/launcher/net/NetJob.cpp index b99c5acb0..52f6f1517 100644 --- a/launcher/net/NetJob.cpp +++ b/launcher/net/NetJob.cpp @@ -37,6 +37,7 @@ #include "NetJob.h" #include "Application.h" +#include "tasks/ConcurrentTask.h" NetJob::NetJob(QString job_name, shared_qobject_ptr network) : ConcurrentTask(nullptr, job_name, APPLICATION->settings()->get("NumberOfConcurrentDownloads").toInt()), m_network(network) @@ -51,18 +52,15 @@ auto NetJob::addNetAction(NetAction::Ptr action) -> bool return true; } -void NetJob::startNext() +void NetJob::executeNextSubTask() { - if (m_queue.isEmpty() && m_doing.isEmpty()) { - // We're finished, check for failures and retry if we can (up to 3 times) - if (!m_failed.isEmpty() && m_try < 3) { - m_try += 1; - while (!m_failed.isEmpty()) - m_queue.enqueue(m_failed.take(*m_failed.keyBegin())); - } + // We're finished, check for failures and retry if we can (up to 3 times) + if (isRunning() && m_queue.isEmpty() && m_doing.isEmpty() && !m_failed.isEmpty() && m_try < 3) { + m_try += 1; + while (!m_failed.isEmpty()) + m_queue.enqueue(m_failed.take(*m_failed.keyBegin())); } - - ConcurrentTask::startNext(); + ConcurrentTask::executeNextSubTask(); } auto NetJob::size() const -> int diff --git a/launcher/net/NetJob.h b/launcher/net/NetJob.h index 1c4337ec6..f6c005809 100644 --- a/launcher/net/NetJob.h +++ b/launcher/net/NetJob.h @@ -55,8 +55,6 @@ class NetJob : public ConcurrentTask { explicit NetJob(QString job_name, shared_qobject_ptr network); ~NetJob() override = default; - void startNext() override; - auto size() const -> int; auto canAbort() const -> bool override; @@ -69,6 +67,9 @@ class NetJob : public ConcurrentTask { // Qt can't handle auto at the start for some reason? bool abort() override; + protected slots: + void executeNextSubTask() override; + protected: void updateState() override; diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index 2ab69d04f..97406d58f 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -35,7 +35,6 @@ */ #include "ConcurrentTask.h" -#include #include #include "tasks/Task.h" @@ -51,6 +50,10 @@ ConcurrentTask::~ConcurrentTask() if (task) task->deleteLater(); } + for (auto task : m_done) { + if (task) + task->deleteLater(); + } } auto ConcurrentTask::getStepProgress() const -> TaskStepProgressList @@ -65,15 +68,13 @@ void ConcurrentTask::addTask(Task::Ptr task) void ConcurrentTask::executeTask() { - // Start one task, startNext handles starting the up to the m_total_max_size - // while tracking the number currently being done - QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection); + for (auto i = 0; i <= m_total_max_size; i++) + executeNextSubTask(); } bool ConcurrentTask::abort() { m_queue.clear(); - m_aborted = true; if (m_doing.isEmpty()) { // Don't call emitAborted() here, we want to bypass the 'is the task running' check @@ -108,27 +109,33 @@ void ConcurrentTask::clear() m_failed.clear(); m_queue.clear(); - m_aborted = false; - m_progress = 0; m_stepProgress = 0; } -void ConcurrentTask::startNext() +void ConcurrentTask::executeNextSubTask() { - if (m_aborted || m_doing.count() > m_total_max_size) + if (!isRunning()) { return; - - if (m_queue.isEmpty() && m_doing.isEmpty() && !wasSuccessful()) { - emitSucceeded(); + } + if (m_queue.isEmpty()) { + if (m_doing.isEmpty()) { + // if (m_failed.isEmpty()) + emitSucceeded(); + // else + // emitFailed(tr("One or more subtasks failed")); + } + return; + } + if (m_doing.count() > m_total_max_size) { return; } - if (m_queue.isEmpty()) - return; - - Task::Ptr next = m_queue.dequeue(); + startSubTask(m_queue.dequeue()); +} +void ConcurrentTask::startSubTask(Task::Ptr next) +{ connect(next.get(), &Task::succeeded, this, [this, next]() { subTaskSucceeded(next); }); connect(next.get(), &Task::failed, this, [this, next](QString msg) { subTaskFailed(next, msg); }); connect(next.get(), &Task::aborted, this, [this, next] { subTaskFailed(next, "Aborted"); }); @@ -140,59 +147,42 @@ void ConcurrentTask::startNext() connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total) { subTaskProgress(next, current, total); }); m_doing.insert(next.get(), next); - qsizetype num_starts = qMin(m_queue.size(), m_total_max_size - m_doing.size()); + auto task_progress = std::make_shared(next->getUid()); m_task_progress.insert(next->getUid(), task_progress); updateState(); updateStepProgress(*task_progress.get(), Operation::ADDED); - QCoreApplication::processEvents(); - QMetaObject::invokeMethod(next.get(), &Task::start, Qt::QueuedConnection); +} - // Allow going up the number of concurrent tasks in case of tasks being added in the middle of a running task. - for (int i = 0; i < num_starts; i++) { - QCoreApplication::processEvents(); - if (m_aborted || m_doing.count() > m_total_max_size) - return; - QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection); - } +void ConcurrentTask::subTaskFinished(Task::Ptr task, TaskStepState state) +{ + m_done.insert(task.get(), task); + (state == TaskStepState::Succeeded ? m_succeeded : m_failed).insert(task.get(), task); + + m_doing.remove(task.get()); + + auto task_progress = m_task_progress.value(task->getUid()); + task_progress->state = state; + + disconnect(task.get(), 0, this, 0); + + emit stepProgress(*task_progress); + updateState(); + updateStepProgress(*task_progress, Operation::REMOVED); + QMetaObject::invokeMethod(this, &ConcurrentTask::executeNextSubTask, Qt::QueuedConnection); } void ConcurrentTask::subTaskSucceeded(Task::Ptr task) { - m_done.insert(task.get(), task); - m_succeeded.insert(task.get(), task); - - m_doing.remove(task.get()); - auto task_progress = m_task_progress.value(task->getUid()); - task_progress->state = TaskStepState::Succeeded; - - disconnect(task.get(), 0, this, 0); - - emit stepProgress(*task_progress); - updateState(); - updateStepProgress(*task_progress, Operation::REMOVED); - startNext(); + subTaskFinished(task, TaskStepState::Succeeded); } void ConcurrentTask::subTaskFailed(Task::Ptr task, [[maybe_unused]] const QString& msg) { - m_done.insert(task.get(), task); - m_failed.insert(task.get(), task); - - m_doing.remove(task.get()); - - auto task_progress = m_task_progress.value(task->getUid()); - task_progress->state = TaskStepState::Failed; - - disconnect(task.get(), 0, this, 0); - - emit stepProgress(*task_progress); - updateState(); - updateStepProgress(*task_progress, Operation::REMOVED); - startNext(); + subTaskFinished(task, TaskStepState::Failed); } void ConcurrentTask::subTaskStatus(Task::Ptr task, const QString& msg) diff --git a/launcher/tasks/ConcurrentTask.h b/launcher/tasks/ConcurrentTask.h index 00b1d48d6..07ea58575 100644 --- a/launcher/tasks/ConcurrentTask.h +++ b/launcher/tasks/ConcurrentTask.h @@ -72,10 +72,11 @@ class ConcurrentTask : public Task { protected slots: void executeTask() override; - virtual void startNext(); + virtual void executeNextSubTask(); void subTaskSucceeded(Task::Ptr); - void subTaskFailed(Task::Ptr, const QString& msg); + virtual void subTaskFailed(Task::Ptr, const QString& msg); + void subTaskFinished(Task::Ptr, TaskStepState); void subTaskStatus(Task::Ptr task, const QString& msg); void subTaskDetails(Task::Ptr task, const QString& msg); void subTaskProgress(Task::Ptr task, qint64 current, qint64 total); @@ -90,6 +91,8 @@ class ConcurrentTask : public Task { virtual void updateState(); + void startSubTask(Task::Ptr task); + protected: QString m_name; QString m_step_status; @@ -107,6 +110,4 @@ class ConcurrentTask : public Task { qint64 m_stepProgress = 0; qint64 m_stepTotalProgress = 100; - - bool m_aborted = false; }; diff --git a/launcher/tasks/MultipleOptionsTask.cpp b/launcher/tasks/MultipleOptionsTask.cpp index 89187a26d..b95fc3d5e 100644 --- a/launcher/tasks/MultipleOptionsTask.cpp +++ b/launcher/tasks/MultipleOptionsTask.cpp @@ -34,11 +34,12 @@ */ #include "MultipleOptionsTask.h" +#include #include -MultipleOptionsTask::MultipleOptionsTask(QObject* parent, const QString& task_name) : SequentialTask(parent, task_name) {} +MultipleOptionsTask::MultipleOptionsTask(QObject* parent, const QString& task_name) : ConcurrentTask(parent, task_name, 1) {} -void MultipleOptionsTask::startNext() +void MultipleOptionsTask::executeNextSubTask() { if (m_done.size() != m_failed.size()) { emitSucceeded(); @@ -51,7 +52,11 @@ void MultipleOptionsTask::startNext() return; } - ConcurrentTask::startNext(); + ConcurrentTask::executeNextSubTask(); + // not sure why this is needed here but tests fail without it + // as the MultipleOptionsTask is yet to be used not sure if + // it works correcly + QCoreApplication::processEvents(); } void MultipleOptionsTask::updateState() diff --git a/launcher/tasks/MultipleOptionsTask.h b/launcher/tasks/MultipleOptionsTask.h index a344343ef..9a88a9999 100644 --- a/launcher/tasks/MultipleOptionsTask.h +++ b/launcher/tasks/MultipleOptionsTask.h @@ -34,18 +34,18 @@ */ #pragma once -#include "SequentialTask.h" +#include "ConcurrentTask.h" /* This task type will attempt to do run each of it's subtasks in sequence, * until one of them succeeds. When that happens, the remaining tasks will not run. * */ -class MultipleOptionsTask : public SequentialTask { +class MultipleOptionsTask : public ConcurrentTask { Q_OBJECT public: explicit MultipleOptionsTask(QObject* parent = nullptr, const QString& task_name = ""); ~MultipleOptionsTask() override = default; private slots: - void startNext() override; + void executeNextSubTask() override; void updateState() override; }; diff --git a/launcher/tasks/SequentialTask.cpp b/launcher/tasks/SequentialTask.cpp index abf7536b9..180430c8c 100644 --- a/launcher/tasks/SequentialTask.cpp +++ b/launcher/tasks/SequentialTask.cpp @@ -36,18 +36,15 @@ #include "SequentialTask.h" #include +#include "tasks/ConcurrentTask.h" SequentialTask::SequentialTask(QObject* parent, QString task_name) : ConcurrentTask(parent, task_name, 1) {} -void SequentialTask::startNext() +void SequentialTask::subTaskFailed(Task::Ptr task, const QString& msg) { - if (m_failed.size() > 0) { - emitFailed(tr("One of the tasks failed!")); - qWarning() << m_failed.constBegin()->get()->failReason(); - return; - } - - ConcurrentTask::startNext(); + emitFailed(msg); + qWarning() << m_failed.constBegin()->get()->failReason(); + ConcurrentTask::subTaskFailed(task, msg); } void SequentialTask::updateState() diff --git a/launcher/tasks/SequentialTask.h b/launcher/tasks/SequentialTask.h index cec3b2be8..a7c101ab4 100644 --- a/launcher/tasks/SequentialTask.h +++ b/launcher/tasks/SequentialTask.h @@ -50,7 +50,9 @@ class SequentialTask : public ConcurrentTask { explicit SequentialTask(QObject* parent = nullptr, QString task_name = ""); ~SequentialTask() override = default; + protected slots: + virtual void subTaskFailed(Task::Ptr, const QString& msg) override; + protected: - void startNext() override; void updateState() override; }; diff --git a/tests/Task_test.cpp b/tests/Task_test.cpp index abc9be905..0740ba0a3 100644 --- a/tests/Task_test.cpp +++ b/tests/Task_test.cpp @@ -37,13 +37,13 @@ class BasicTask_MultiStep : public Task { class BigConcurrentTask : public ConcurrentTask { Q_OBJECT - void startNext() override + void executeNextSubTask() override { // This is here only to help fill the stack a bit more quickly (if there's an issue, of course :^)) // Each tasks thus adds 1024 * 4 bytes to the stack, at the very least. [[maybe_unused]] volatile std::array some_data_on_the_stack{}; - ConcurrentTask::startNext(); + ConcurrentTask::executeNextSubTask(); } }; @@ -71,11 +71,14 @@ class BigConcurrentTaskThread : public QThread { quit(); }); - m_deadline.start(); + if (thread() != QThread::currentThread()) { + QMetaObject::invokeMethod(this, &BigConcurrentTaskThread::start_timer, Qt::QueuedConnection); + } big_task.run(); exec(); } + void start_timer() { m_deadline.start(); } public: bool passed_the_deadline = false; From b075711be08b4d3e3badb1def5b0f4d24e0ad51a Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 15 Oct 2023 16:03:14 +0300 Subject: [PATCH 09/37] ensured totalTimePlayed is allways greater than 0 Signed-off-by: Trial97 --- launcher/BaseInstance.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/launcher/BaseInstance.cpp b/launcher/BaseInstance.cpp index 725036395..66b44b229 100644 --- a/launcher/BaseInstance.cpp +++ b/launcher/BaseInstance.cpp @@ -278,6 +278,8 @@ void BaseInstance::setRunning(bool running) QDateTime timeEnded = QDateTime::currentDateTime(); qint64 current = settings()->get("totalTimePlayed").toLongLong(); + if (current < 0) + current = 0; settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded)); settings()->set("lastTimePlayed", m_timeStarted.secsTo(timeEnded)); @@ -290,6 +292,8 @@ void BaseInstance::setRunning(bool running) int64_t BaseInstance::totalTimePlayed() const { qint64 current = m_settings->get("totalTimePlayed").toLongLong(); + if (current < 0) + current = 0; if (m_isRunning) { QDateTime timeNow = QDateTime::currentDateTime(); return current + m_timeStarted.secsTo(timeNow); From 52c94eb568a22e95e7696af0a1177b1b3bf54aec Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 15 Oct 2023 16:24:23 +0300 Subject: [PATCH 10/37] reset the setting if is under 0 Signed-off-by: Trial97 --- launcher/BaseInstance.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/launcher/BaseInstance.cpp b/launcher/BaseInstance.cpp index 66b44b229..d0b0ad3bc 100644 --- a/launcher/BaseInstance.cpp +++ b/launcher/BaseInstance.cpp @@ -64,6 +64,8 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s m_settings->registerSetting("lastLaunchTime", 0); m_settings->registerSetting("totalTimePlayed", 0); + if (m_settings->get("totalTimePlayed").toLongLong() < 0) + m_settings->set("totalTimePlayed", 0); m_settings->registerSetting("lastTimePlayed", 0); m_settings->registerSetting("linkedInstances", "[]"); @@ -278,8 +280,6 @@ void BaseInstance::setRunning(bool running) QDateTime timeEnded = QDateTime::currentDateTime(); qint64 current = settings()->get("totalTimePlayed").toLongLong(); - if (current < 0) - current = 0; settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded)); settings()->set("lastTimePlayed", m_timeStarted.secsTo(timeEnded)); @@ -292,8 +292,6 @@ void BaseInstance::setRunning(bool running) int64_t BaseInstance::totalTimePlayed() const { qint64 current = m_settings->get("totalTimePlayed").toLongLong(); - if (current < 0) - current = 0; if (m_isRunning) { QDateTime timeNow = QDateTime::currentDateTime(); return current + m_timeStarted.secsTo(timeNow); From 03a27d5b5a43116bafbd08aa8a2f5b7a592710b8 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 19 Oct 2023 19:47:48 +0300 Subject: [PATCH 11/37] Updated Managed Packs Signed-off-by: Trial97 --- .../flame/FlameInstanceCreationTask.cpp | 3 +++ .../modrinth/ModrinthInstanceCreationTask.cpp | 5 +++- .../ui/pages/instance/ManagedPackPage.cpp | 23 +++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index 2a26ce944..c8df8b627 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -427,6 +427,9 @@ bool FlameCreationTask::createInstance() // Don't add managed info to packs without an ID (most likely imported from ZIP) if (!m_managed_id.isEmpty()) instance.setManagedPack("flame", m_managed_id, m_pack.name, m_managed_version_id, m_pack.version); + else + instance.setManagedPack("flame", "", name(), "", ""); + instance.setName(name()); m_mod_id_resolver.reset(new Flame::FileResolvingTask(APPLICATION->network(), m_pack)); diff --git a/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp b/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp index e732ad39c..96d9c84d2 100644 --- a/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp +++ b/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp @@ -226,6 +226,9 @@ bool ModrinthCreationTask::createInstance() // Don't add managed info to packs without an ID (most likely imported from ZIP) if (!m_managed_id.isEmpty()) instance.setManagedPack("modrinth", m_managed_id, m_managed_name, m_managed_version_id, version()); + else + instance.setManagedPack("modrinth", "", name(), "", ""); + instance.setName(name()); instance.saveNow(); @@ -289,7 +292,7 @@ bool ModrinthCreationTask::createInstance() // Only change the name if it didn't use a custom name, so that the previous custom name // is preserved, but if we're using the original one, we update the version string. // NOTE: This needs to come before the copyManagedPack call! - if (inst->name().contains(inst->getManagedPackVersionName())) { + if (inst->name().contains(inst->getManagedPackVersionName()) && inst->name() != instance.name()) { if (askForChangingInstanceName(m_parent, inst->name(), instance.name()) == InstanceNameChange::ShouldChange) inst->setName(instance.name()); } diff --git a/launcher/ui/pages/instance/ManagedPackPage.cpp b/launcher/ui/pages/instance/ManagedPackPage.cpp index 26a8302db..c419066a0 100644 --- a/launcher/ui/pages/instance/ManagedPackPage.cpp +++ b/launcher/ui/pages/instance/ManagedPackPage.cpp @@ -131,6 +131,22 @@ ManagedPackPage::~ManagedPackPage() void ManagedPackPage::openedImpl() { + if (m_inst->getManagedPackID().isEmpty()) { + ui->packVersion->hide(); + ui->packVersionLabel->hide(); + ui->packOrigin->hide(); + ui->packOriginLabel->hide(); + ui->versionsComboBox->hide(); + ui->updateButton->hide(); + ui->updateToVersionLabel->hide(); + ui->updateFromFileButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + + ui->packName->setText(m_inst->name()); + ui->changelogTextBrowser->setText(tr("This is a local modpack.\n" + "This can be updated only using a file in %1 format\n") + .arg(displayName())); + return; + } ui->packName->setText(m_inst->getManagedPackName()); ui->packVersion->setText(m_inst->getManagedPackVersionName()); ui->packOrigin->setText(tr("Website: %2 | Pack ID: %3 | Version ID: %4") @@ -355,6 +371,8 @@ void ModrinthManagedPackPage::update() void ModrinthManagedPackPage::updateFromFile() { auto output = QFileDialog::getOpenFileUrl(this, tr("Choose update file"), QDir::homePath(), "Modrinth pack (*.mrpack *.zip)"); + if (output.isEmpty()) + return; QMap extra_info; extra_info.insert("pack_id", m_inst->getManagedPackID()); extra_info.insert("pack_version_id", QString()); @@ -471,8 +489,7 @@ void FlameManagedPackPage::parseManagedPack() QString FlameManagedPackPage::url() const { - // FIXME: We should display the websiteUrl field, but this requires doing the API request first :( - return {}; + return "https://www.curseforge.com/projects/" + m_inst->getManagedPackID(); } void FlameManagedPackPage::suggestVersion() @@ -519,6 +536,8 @@ void FlameManagedPackPage::update() void FlameManagedPackPage::updateFromFile() { auto output = QFileDialog::getOpenFileUrl(this, tr("Choose update file"), QDir::homePath(), "CurseForge pack (*.zip)"); + if (output.isEmpty()) + return; QMap extra_info; extra_info.insert("pack_id", m_inst->getManagedPackID()); From 1ac9757a86884d3c8299b8bf3749a82c9e7339ff Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 19 Oct 2023 21:51:51 +0300 Subject: [PATCH 12/37] Added back the processEvents Signed-off-by: Trial97 --- launcher/tasks/ConcurrentTask.cpp | 3 +++ launcher/tasks/MultipleOptionsTask.cpp | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index 77d9ab29d..0183b5124 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -35,6 +35,7 @@ */ #include "ConcurrentTask.h" +#include #include #include "tasks/Task.h" @@ -132,6 +133,8 @@ void ConcurrentTask::executeNextSubTask() } startSubTask(m_queue.dequeue()); + + QCoreApplication::processEvents(); } void ConcurrentTask::startSubTask(Task::Ptr next) diff --git a/launcher/tasks/MultipleOptionsTask.cpp b/launcher/tasks/MultipleOptionsTask.cpp index b95fc3d5e..5afe03964 100644 --- a/launcher/tasks/MultipleOptionsTask.cpp +++ b/launcher/tasks/MultipleOptionsTask.cpp @@ -34,7 +34,6 @@ */ #include "MultipleOptionsTask.h" -#include #include MultipleOptionsTask::MultipleOptionsTask(QObject* parent, const QString& task_name) : ConcurrentTask(parent, task_name, 1) {} @@ -53,10 +52,6 @@ void MultipleOptionsTask::executeNextSubTask() } ConcurrentTask::executeNextSubTask(); - // not sure why this is needed here but tests fail without it - // as the MultipleOptionsTask is yet to be used not sure if - // it works correcly - QCoreApplication::processEvents(); } void MultipleOptionsTask::updateState() From 35a8ab2393e132481e7e0ee2a2eca338918d17f6 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 20 Oct 2023 10:32:45 +0300 Subject: [PATCH 13/37] Removed processEvents Signed-off-by: Trial97 --- launcher/tasks/ConcurrentTask.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index 0183b5124..92b13cfa8 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -35,7 +35,6 @@ */ #include "ConcurrentTask.h" -#include #include #include "tasks/Task.h" @@ -69,7 +68,7 @@ void ConcurrentTask::addTask(Task::Ptr task) void ConcurrentTask::executeTask() { - for (auto i = 0; i <= m_total_max_size; i++) + for (auto i = 0; i < m_total_max_size; i++) executeNextSubTask(); } @@ -133,8 +132,6 @@ void ConcurrentTask::executeNextSubTask() } startSubTask(m_queue.dequeue()); - - QCoreApplication::processEvents(); } void ConcurrentTask::startSubTask(Task::Ptr next) From a9d7af909614404b6cc58ccc568d46d505f541cd Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 20 Oct 2023 16:44:37 +0300 Subject: [PATCH 14/37] removed some unused stuff Signed-off-by: Trial97 --- launcher/ui/dialogs/AboutDialog.h | 4 ---- launcher/ui/pages/instance/VersionPage.cpp | 7 ------- launcher/ui/pages/instance/VersionPage.h | 1 - 3 files changed, 12 deletions(-) diff --git a/launcher/ui/dialogs/AboutDialog.h b/launcher/ui/dialogs/AboutDialog.h index 356f005e0..5da686b5f 100644 --- a/launcher/ui/dialogs/AboutDialog.h +++ b/launcher/ui/dialogs/AboutDialog.h @@ -15,7 +15,6 @@ #pragma once -#include #include namespace Ui { @@ -31,7 +30,4 @@ class AboutDialog : public QDialog { private: Ui::AboutDialog* ui; - - NetJob::Ptr netJob; - QByteArray dataSink; }; diff --git a/launcher/ui/pages/instance/VersionPage.cpp b/launcher/ui/pages/instance/VersionPage.cpp index 2918261d2..e425269c8 100644 --- a/launcher/ui/pages/instance/VersionPage.cpp +++ b/launcher/ui/pages/instance/VersionPage.cpp @@ -295,13 +295,6 @@ void VersionPage::on_actionRemove_triggered() m_container->refreshContainer(); } -void VersionPage::on_actionInstall_mods_triggered() -{ - if (m_container) { - m_container->selectPage("mods"); - } -} - void VersionPage::on_actionAdd_to_Minecraft_jar_triggered() { auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), diff --git a/launcher/ui/pages/instance/VersionPage.h b/launcher/ui/pages/instance/VersionPage.h index 6915be883..951643743 100644 --- a/launcher/ui/pages/instance/VersionPage.h +++ b/launcher/ui/pages/instance/VersionPage.h @@ -80,7 +80,6 @@ class VersionPage : public QMainWindow, public BasePage { void on_actionAdd_Agents_triggered(); void on_actionRevert_triggered(); void on_actionEdit_triggered(); - void on_actionInstall_mods_triggered(); void on_actionCustomize_triggered(); void on_actionDownload_All_triggered(); From 0ca3873f1c492ad78257eb9ca2c1568a90c353c0 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 22 Oct 2023 17:48:19 +0300 Subject: [PATCH 15/37] small fix Signed-off-by: Trial97 --- launcher/tasks/ConcurrentTask.cpp | 4 ++-- launcher/tasks/SequentialTask.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index 92b13cfa8..c042894b4 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -69,7 +69,7 @@ void ConcurrentTask::addTask(Task::Ptr task) void ConcurrentTask::executeTask() { for (auto i = 0; i < m_total_max_size; i++) - executeNextSubTask(); + QMetaObject::invokeMethod(this, &ConcurrentTask::executeNextSubTask, Qt::QueuedConnection); } bool ConcurrentTask::abort() @@ -127,7 +127,7 @@ void ConcurrentTask::executeNextSubTask() } return; } - if (m_doing.count() > m_total_max_size) { + if (m_doing.count() >= m_total_max_size) { return; } diff --git a/launcher/tasks/SequentialTask.cpp b/launcher/tasks/SequentialTask.cpp index 180430c8c..509d91cf7 100644 --- a/launcher/tasks/SequentialTask.cpp +++ b/launcher/tasks/SequentialTask.cpp @@ -43,7 +43,7 @@ SequentialTask::SequentialTask(QObject* parent, QString task_name) : ConcurrentT void SequentialTask::subTaskFailed(Task::Ptr task, const QString& msg) { emitFailed(msg); - qWarning() << m_failed.constBegin()->get()->failReason(); + qWarning() << msg; ConcurrentTask::subTaskFailed(task, msg); } From 2aeb8291767e1832f81f3a4e3f8e3736613175ed Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 22 Oct 2023 19:58:10 +0300 Subject: [PATCH 16/37] removed the concurent task destructor behaivior Signed-off-by: Trial97 --- launcher/modplatform/EnsureMetadataTask.cpp | 1 - launcher/tasks/ConcurrentTask.cpp | 14 +++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/launcher/modplatform/EnsureMetadataTask.cpp b/launcher/modplatform/EnsureMetadataTask.cpp index a9ed30119..ce53ee62d 100644 --- a/launcher/modplatform/EnsureMetadataTask.cpp +++ b/launcher/modplatform/EnsureMetadataTask.cpp @@ -160,7 +160,6 @@ void EnsureMetadataTask::executeTask() if (m_current_task) m_current_task.reset(); }); - connect(version_task.get(), &Task::failed, this, &EnsureMetadataTask::emitFailed); if (m_mods.size() > 1) setStatus(tr("Requesting metadata information from %1...").arg(ProviderCaps.readableName(m_provider))); diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp index c042894b4..6f4a94e7f 100644 --- a/launcher/tasks/ConcurrentTask.cpp +++ b/launcher/tasks/ConcurrentTask.cpp @@ -46,13 +46,9 @@ ConcurrentTask::ConcurrentTask(QObject* parent, QString task_name, int max_concu ConcurrentTask::~ConcurrentTask() { - for (auto task : m_queue) { + for (auto task : m_doing) { if (task) - task->deleteLater(); - } - for (auto task : m_done) { - if (task) - task->deleteLater(); + task->disconnect(this); } } @@ -118,6 +114,9 @@ void ConcurrentTask::executeNextSubTask() if (!isRunning()) { return; } + if (m_doing.count() >= m_total_max_size) { + return; + } if (m_queue.isEmpty()) { if (m_doing.isEmpty()) { if (m_failed.isEmpty()) @@ -127,9 +126,6 @@ void ConcurrentTask::executeNextSubTask() } return; } - if (m_doing.count() >= m_total_max_size) { - return; - } startSubTask(m_queue.dequeue()); } From dba54332fb7785400ffc6d9eac1f3a0b9d3412cd Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 26 Oct 2023 18:31:52 +0300 Subject: [PATCH 17/37] fixed some asan stuf Signed-off-by: Trial97 --- launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp | 2 +- launcher/screenshots/ImgurUpload.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp index e56fc3d1d..e78061f27 100644 --- a/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp +++ b/launcher/modplatform/modrinth/ModrinthCheckUpdate.cpp @@ -72,7 +72,7 @@ void ModrinthCheckUpdate::executeTask() auto response = std::make_shared(); auto job = api.latestVersions(hashes, best_hash_type, m_game_versions, m_loaders, response); - connect(job.get(), &Task::succeeded, this, [this, response, &mappings, best_hash_type, job] { + connect(job.get(), &Task::succeeded, this, [this, response, mappings, best_hash_type, job] { QJsonParseError parse_error{}; QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); if (parse_error.error != QJsonParseError::NoError) { diff --git a/launcher/screenshots/ImgurUpload.cpp b/launcher/screenshots/ImgurUpload.cpp index 7ed672eb7..15fb043e4 100644 --- a/launcher/screenshots/ImgurUpload.cpp +++ b/launcher/screenshots/ImgurUpload.cpp @@ -58,14 +58,14 @@ void ImgurUpload::init() QNetworkReply* ImgurUpload::getReply(QNetworkRequest& request) { - auto file = new QFile(m_fileInfo.absoluteFilePath()); + auto file = new QFile(m_fileInfo.absoluteFilePath(), this); if (!file->open(QFile::ReadOnly)) { emitFailed(); return nullptr; } - QHttpMultiPart* multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + QHttpMultiPart* multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType, this); file->setParent(multipart); QHttpPart filePart; filePart.setBodyDevice(file); From a531f32b693cd621de5abfbe0e6cf97b344f51a4 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 16 Nov 2023 13:26:29 +0200 Subject: [PATCH 18/37] fixed settings saving Signed-off-by: Trial97 --- launcher/InstanceCopyTask.cpp | 3 +-- launcher/settings/INIFile.cpp | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/InstanceCopyTask.cpp b/launcher/InstanceCopyTask.cpp index 8abf30640..cdcd61ba6 100644 --- a/launcher/InstanceCopyTask.cpp +++ b/launcher/InstanceCopyTask.cpp @@ -142,9 +142,8 @@ void InstanceCopyTask::copyFinished() if (!m_keepPlaytime) { inst->resetTimePlayed(); } - if (m_useLinks) - inst->addLinkedInstanceId(m_origInstance->id()); if (m_useLinks) { + inst->addLinkedInstanceId(m_origInstance->id()); auto allowed_symlinks_file = QFileInfo(FS::PathCombine(inst->gameRoot(), "allowed_symlinks.txt")); QByteArray allowed_symlinks; diff --git a/launcher/settings/INIFile.cpp b/launcher/settings/INIFile.cpp index 4fb11ed35..e97741f20 100644 --- a/launcher/settings/INIFile.cpp +++ b/launcher/settings/INIFile.cpp @@ -54,6 +54,7 @@ bool INIFile::saveFile(QString fileName) insert("ConfigVersion", "1.2"); QSettings _settings_obj{ fileName, QSettings::Format::IniFormat }; _settings_obj.setFallbacksEnabled(false); + _settings_obj.clear(); for (Iterator iter = begin(); iter != end(); iter++) _settings_obj.setValue(iter.key(), iter.value()); From 4e3132e8b2b18057f905668d3177098157ba2dac Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 17 Nov 2023 22:40:36 +0200 Subject: [PATCH 19/37] reseted the setting Signed-off-by: Trial97 --- launcher/BaseInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/BaseInstance.cpp b/launcher/BaseInstance.cpp index d0b0ad3bc..3b6d69a78 100644 --- a/launcher/BaseInstance.cpp +++ b/launcher/BaseInstance.cpp @@ -65,7 +65,7 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s m_settings->registerSetting("lastLaunchTime", 0); m_settings->registerSetting("totalTimePlayed", 0); if (m_settings->get("totalTimePlayed").toLongLong() < 0) - m_settings->set("totalTimePlayed", 0); + m_settings->reset("totalTimePlayed"); m_settings->registerSetting("lastTimePlayed", 0); m_settings->registerSetting("linkedInstances", "[]"); From 681e76c551df3e1c9daf07d0b8075d2cca77c832 Mon Sep 17 00:00:00 2001 From: bit6tream Date: Wed, 22 Nov 2023 01:48:31 +0300 Subject: [PATCH 20/37] (#1693) Notify user if /tmp directory has `noexec` mount option Minecraft versions starting from 1.19 would not start at all if /tmp is mounted as `noexec`. Signed-off-by: bit6tream --- launcher/Application.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index be252f1c5..619215162 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -82,6 +82,7 @@ #include #include +#include #include #include @@ -132,6 +133,10 @@ #include "gamemode_client.h" #endif +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) +#include +#endif + #if defined(Q_OS_MAC) #if defined(SPARKLE_ENABLED) #include "updater/MacSparkleUpdater.h" @@ -988,6 +993,36 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) } } +#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) + + // notify user if /tmp is mounted with `noexec` (#1693) + { + FILE* description = setmntent(MOUNTED, "r"); + mntent* info = nullptr; + + while ((info = getmntent(description)) != nullptr) { + std::string_view directory = info->mnt_dir; + std::string_view options = info->mnt_opts; + + if (directory == "/tmp" && options.rfind("noexec") != std::string_view::npos) { + auto infoMsg = + tr("Your /tmp directory is currently mounted with the 'noexec' flag enabled.\n" + "Some versions of Minecraft may not launch.\n"); + auto msgBox = new QMessageBox(QMessageBox::Information, tr("Incompatible system configuration"), infoMsg, QMessageBox::Ok); + msgBox->setDefaultButton(QMessageBox::Ok); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->setMinimumWidth(460); + msgBox->adjustSize(); + msgBox->open(); + break; + } + } + + endmntent(description); + } + +#endif + if (createSetupWizard()) { return; } From 6169af70db9a58304e5517a8caeb05515a083aa6 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 23 Nov 2023 11:59:35 +0200 Subject: [PATCH 21/37] Added back the FIXME comment Signed-off-by: Trial97 --- launcher/ui/pages/instance/ManagedPackPage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/launcher/ui/pages/instance/ManagedPackPage.cpp b/launcher/ui/pages/instance/ManagedPackPage.cpp index c419066a0..2210d0263 100644 --- a/launcher/ui/pages/instance/ManagedPackPage.cpp +++ b/launcher/ui/pages/instance/ManagedPackPage.cpp @@ -489,6 +489,7 @@ void FlameManagedPackPage::parseManagedPack() QString FlameManagedPackPage::url() const { + // FIXME: We should display the websiteUrl field, but this requires doing the API request first :( return "https://www.curseforge.com/projects/" + m_inst->getManagedPackID(); } From d414599974c6a8dc1a11fa769dff9e0f8feb5f01 Mon Sep 17 00:00:00 2001 From: bit6tream Date: Thu, 23 Nov 2023 15:19:04 +0300 Subject: [PATCH 22/37] (#1693) Use a better approach to detect a noexec mount option Signed-off-by: bit6tream --- launcher/Application.cpp | 55 ++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 619215162..cfede9dc1 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -82,7 +82,6 @@ #include #include -#include #include #include @@ -133,8 +132,13 @@ #include "gamemode_client.h" #endif -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) -#include +#if defined(Q_OS_LINUX) +#include +#endif + +#if defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) +#include +#include #endif #if defined(Q_OS_MAC) @@ -993,36 +997,37 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) } } -#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) - // notify user if /tmp is mounted with `noexec` (#1693) { - FILE* description = setmntent(MOUNTED, "r"); - mntent* info = nullptr; + bool is_tmp_noexec = false; - while ((info = getmntent(description)) != nullptr) { - std::string_view directory = info->mnt_dir; - std::string_view options = info->mnt_opts; +#if defined(Q_OS_LINUX) - if (directory == "/tmp" && options.rfind("noexec") != std::string_view::npos) { - auto infoMsg = - tr("Your /tmp directory is currently mounted with the 'noexec' flag enabled.\n" - "Some versions of Minecraft may not launch.\n"); - auto msgBox = new QMessageBox(QMessageBox::Information, tr("Incompatible system configuration"), infoMsg, QMessageBox::Ok); - msgBox->setDefaultButton(QMessageBox::Ok); - msgBox->setAttribute(Qt::WA_DeleteOnClose); - msgBox->setMinimumWidth(460); - msgBox->adjustSize(); - msgBox->open(); - break; - } - } + struct statvfs tmp_stat; + statvfs("/tmp", &tmp_stat); + is_tmp_noexec = tmp_stat.f_flag & ST_NOEXEC; - endmntent(description); - } +#elif defined(Q_OS_FREEBSD) || defined(Q_OS_OPENBSD) + + struct statfs tmp_stat; + statfs("/tmp", &tmp_stat); + is_tmp_noexec = tmp_stat.f_flags & MNT_NOEXEC; #endif + if (is_tmp_noexec) { + auto infoMsg = + tr("Your /tmp directory is currently mounted with the 'noexec' flag enabled.\n" + "Some versions of Minecraft may not launch.\n"); + auto msgBox = new QMessageBox(QMessageBox::Information, tr("Incompatible system configuration"), infoMsg, QMessageBox::Ok); + msgBox->setDefaultButton(QMessageBox::Ok); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->setMinimumWidth(460); + msgBox->adjustSize(); + msgBox->open(); + } + } + if (createSetupWizard()) { return; } From 67b51b7a184bd9d8432f253ffb6fee4fa1259c33 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 26 Nov 2023 00:19:22 +0000 Subject: [PATCH 23/37] chore(nix): update lockfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nixpkgs': 'github:nixos/nixpkgs/7414e9ee0b3e9903c24d3379f577a417f0aae5f1' (2023-11-16) → 'github:nixos/nixpkgs/0bd59c54ef06bc34eca01e37d689f5e46b3fe2f1' (2023-11-24) • Updated input 'pre-commit-hooks': 'github:cachix/pre-commit-hooks.nix/e558068cba67b23b4fbc5537173dbb43748a17e8' (2023-11-15) → 'github:cachix/pre-commit-hooks.nix/e5ee5c5f3844550c01d2131096c7271cec5e9b78' (2023-11-25) --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 3422af0ac..18ae9c463 100644 --- a/flake.lock +++ b/flake.lock @@ -106,11 +106,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1700108881, - "narHash": "sha256-+Lqybl8kj0+nD/IlAWPPG/RDTa47gff9nbei0u7BntE=", + "lastModified": 1700856099, + "narHash": "sha256-RnEA7iJ36Ay9jI0WwP+/y4zjEhmeN6Cjs9VOFBH7eVQ=", "owner": "nixos", "repo": "nixpkgs", - "rev": "7414e9ee0b3e9903c24d3379f577a417f0aae5f1", + "rev": "0bd59c54ef06bc34eca01e37d689f5e46b3fe2f1", "type": "github" }, "original": { @@ -153,11 +153,11 @@ ] }, "locked": { - "lastModified": 1700064067, - "narHash": "sha256-1ZWNDzhu8UlVCK7+DUN9dVQfiHX1bv6OQP9VxstY/gs=", + "lastModified": 1700922917, + "narHash": "sha256-ej2fch/T584b5K9sk1UhmZF7W6wEfDHuoUYpFN8dtvM=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "e558068cba67b23b4fbc5537173dbb43748a17e8", + "rev": "e5ee5c5f3844550c01d2131096c7271cec5e9b78", "type": "github" }, "original": { From 2d91bd09d413177c9382e7b101cc4cd8f7d78b45 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sun, 26 Nov 2023 23:49:56 +0200 Subject: [PATCH 24/37] Fixed crash on abort function not initialized Signed-off-by: Trial97 --- launcher/ui/pages/modplatform/ResourceModel.cpp | 6 ++++++ launcher/ui/pages/modplatform/flame/FlameModel.cpp | 4 ++++ launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp index c83e844c3..6c02150bd 100644 --- a/launcher/ui/pages/modplatform/ResourceModel.cpp +++ b/launcher/ui/pages/modplatform/ResourceModel.cpp @@ -234,6 +234,12 @@ void ResourceModel::loadEntry(QModelIndex& entry) return; QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load project info:%1").arg(reason)); }; + if (!callbacks.on_abort) + callbacks.on_abort = [this] { + if (!s_running_models.constFind(this).value()) + return; + qCritical() << tr("The request was abborted for an unknown reason"); + }; if (auto job = m_api->getProjectInfo(std::move(args), std::move(callbacks)); job) runInfoJob(job); diff --git a/launcher/ui/pages/modplatform/flame/FlameModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModel.cpp index 8875a9452..3b266bcef 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModel.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModel.cpp @@ -170,6 +170,10 @@ void ListModel::performPaginatedSearch() callbacks.on_fail = [this](QString reason) { searchRequestFailed(reason); }; callbacks.on_succeed = [this](auto& doc, auto& pack) { searchRequestForOneSucceeded(doc); }; + callbacks.on_abort = [this] { + qCritical() << "Search task aborted by an unknown reason!"; + searchRequestFailed("Abborted"); + }; static const FlameAPI api; if (auto job = api.getProjectInfo({ projectId }, std::move(callbacks)); job) { jobPtr = job; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index f691a185d..227ed646b 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -140,6 +140,10 @@ void ModpackListModel::performPaginatedSearch() callbacks.on_fail = [this](QString reason) { searchRequestFailed(reason); }; callbacks.on_succeed = [this](auto& doc, auto& pack) { searchRequestForOneSucceeded(doc); }; + callbacks.on_abort = [this] { + qCritical() << "Search task aborted by an unknown reason!"; + searchRequestFailed("Abborted"); + }; static const ModrinthAPI api; if (auto job = api.getProjectInfo({ projectId }, std::move(callbacks)); job) { jobPtr = job; From 463ff4c6ae9362c70e4f70eea0805ce7b6931145 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 27 Nov 2023 11:30:07 +0200 Subject: [PATCH 25/37] Removed assert permanantly Signed-off-by: Trial97 --- launcher/minecraft/mod/ResourceFolderModel.h | 1 - 1 file changed, 1 deletion(-) diff --git a/launcher/minecraft/mod/ResourceFolderModel.h b/launcher/minecraft/mod/ResourceFolderModel.h index d764280b6..90e3aac2d 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.h +++ b/launcher/minecraft/mod/ResourceFolderModel.h @@ -306,7 +306,6 @@ void ResourceFolderModel::applyUpdates(QSet& current_set, QSet auto removed_it = m_resources.begin() + removed_index; Q_ASSERT(removed_it != m_resources.end()); - Q_ASSERT(removed_set.contains(removed_it->get()->internal_id())); if ((*removed_it)->isResolving()) { auto ticket = (*removed_it)->resolutionTicket(); From a74c3d57b44a297760863e2ed42dfa643beade0d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 28 Nov 2023 20:27:48 +0000 Subject: [PATCH 26/37] chore(deps): update cachix/install-nix-action action to v24 --- .github/workflows/update-flake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-flake.yml b/.github/workflows/update-flake.yml index 6a16b0369..538972968 100644 --- a/.github/workflows/update-flake.yml +++ b/.github/workflows/update-flake.yml @@ -17,7 +17,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@6a9a9e84a173d90b3ffb42c5ddaf9ea033fad011 # v23 + - uses: cachix/install-nix-action@7ac1ec25491415c381d9b62f0657c7a028df52a7 # v24 - uses: DeterminateSystems/update-flake-lock@v20 with: From eb011e6729fe49da867e6ae1ab2524424eedac46 Mon Sep 17 00:00:00 2001 From: DioEgizio <83089242+DioEgizio@users.noreply.github.com> Date: Sat, 2 Dec 2023 17:42:24 +0100 Subject: [PATCH 27/37] chore: update qt to qt 6.6.1 Signed-off-by: DioEgizio <83089242+DioEgizio@users.noreply.github.com> --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4fb2d6794..24e7194ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -61,7 +61,7 @@ jobs: qt_ver: 6 qt_host: windows qt_arch: '' - qt_version: '6.6.0' + qt_version: '6.6.1' qt_modules: 'qt5compat qtimageformats' qt_tools: '' @@ -73,7 +73,7 @@ jobs: qt_ver: 6 qt_host: windows qt_arch: 'win64_msvc2019_arm64' - qt_version: '6.6.0' + qt_version: '6.6.1' qt_modules: 'qt5compat qtimageformats' qt_tools: '' @@ -83,7 +83,7 @@ jobs: qt_ver: 6 qt_host: mac qt_arch: '' - qt_version: '6.6.0' + qt_version: '6.6.1' qt_modules: 'qt5compat qtimageformats' qt_tools: '' From 8b4b0f2f018b84d545e4fba1071cf4b0456cec87 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 3 Dec 2023 00:19:28 +0000 Subject: [PATCH 28/37] chore(nix): update lockfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'flake-parts': 'github:hercules-ci/flake-parts/8c9fa2545007b49a5db5f650ae91f227672c3877' (2023-11-01) → 'github:hercules-ci/flake-parts/34fed993f1674c8d06d58b37ce1e0fe5eebcb9f5' (2023-12-01) • Updated input 'flake-parts/nixpkgs-lib': 'github:NixOS/nixpkgs/0cbe9f69c234a7700596e943bfae7ef27a31b735?dir=lib' (2023-10-29) → 'github:NixOS/nixpkgs/e92039b55bcd58469325ded85d4f58dd5a4eaf58?dir=lib' (2023-11-29) • Updated input 'nixpkgs': 'github:nixos/nixpkgs/0bd59c54ef06bc34eca01e37d689f5e46b3fe2f1' (2023-11-24) → 'github:nixos/nixpkgs/f5c27c6136db4d76c30e533c20517df6864c46ee' (2023-11-30) --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index 18ae9c463..efaa524f6 100644 --- a/flake.lock +++ b/flake.lock @@ -21,11 +21,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1698882062, - "narHash": "sha256-HkhafUayIqxXyHH1X8d9RDl1M2CkFgZLjKD3MzabiEo=", + "lastModified": 1701473968, + "narHash": "sha256-YcVE5emp1qQ8ieHUnxt1wCZCC3ZfAS+SRRWZ2TMda7E=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "8c9fa2545007b49a5db5f650ae91f227672c3877", + "rev": "34fed993f1674c8d06d58b37ce1e0fe5eebcb9f5", "type": "github" }, "original": { @@ -106,11 +106,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1700856099, - "narHash": "sha256-RnEA7iJ36Ay9jI0WwP+/y4zjEhmeN6Cjs9VOFBH7eVQ=", + "lastModified": 1701336116, + "narHash": "sha256-kEmpezCR/FpITc6yMbAh4WrOCiT2zg5pSjnKrq51h5Y=", "owner": "nixos", "repo": "nixpkgs", - "rev": "0bd59c54ef06bc34eca01e37d689f5e46b3fe2f1", + "rev": "f5c27c6136db4d76c30e533c20517df6864c46ee", "type": "github" }, "original": { @@ -123,11 +123,11 @@ "nixpkgs-lib": { "locked": { "dir": "lib", - "lastModified": 1698611440, - "narHash": "sha256-jPjHjrerhYDy3q9+s5EAsuhyhuknNfowY6yt6pjn9pc=", + "lastModified": 1701253981, + "narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0cbe9f69c234a7700596e943bfae7ef27a31b735", + "rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58", "type": "github" }, "original": { From 132344df1cff26f2dbc16dd3a7dfacc53091b975 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:06:39 +0000 Subject: [PATCH 29/37] chore(deps): update korthout/backport-action action to v2.2.0 --- .github/workflows/backport.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml index e5443439d..12850d697 100644 --- a/.github/workflows/backport.yml +++ b/.github/workflows/backport.yml @@ -24,7 +24,7 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} - name: Create backport PRs - uses: korthout/backport-action@v2.1.1 + uses: korthout/backport-action@v2.2.0 with: # Config README: https://github.com/korthout/backport-action#backport-action pull_description: |- From faedd0fd65123d328f4f767649d6529424642299 Mon Sep 17 00:00:00 2001 From: Archy <59789660+IceCryptonym@users.noreply.github.com> Date: Wed, 6 Dec 2023 22:40:46 +1000 Subject: [PATCH 30/37] Add togglable status bar Signed-off-by: Archy <59789660+IceCryptonym@users.noreply.github.com> --- launcher/Application.cpp | 2 ++ launcher/ui/MainWindow.cpp | 15 +++++++++++++++ launcher/ui/MainWindow.h | 2 ++ launcher/ui/MainWindow.ui | 9 +++++++++ 4 files changed, 28 insertions(+) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index cfede9dc1..ff5eb2a66 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -668,6 +668,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) // The cat m_settings->registerSetting("TheCat", false); + m_settings->registerSetting("StatusBarVisible", true); + m_settings->registerSetting("ToolbarsLocked", false); m_settings->registerSetting("InstSortMode", "Name"); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 7b4d1c8a5..42de6c2c0 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -186,6 +186,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi ui->instanceToolBar->addContextMenuAction(ui->newsToolBar->toggleViewAction()); ui->instanceToolBar->addContextMenuAction(ui->instanceToolBar->toggleViewAction()); + ui->instanceToolBar->addContextMenuAction(ui->actionToggleStatusBar); ui->instanceToolBar->addContextMenuAction(ui->actionLockToolbars); } @@ -319,6 +320,14 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi setCatBackground(cat_enable); } + // Togglable status bar + { + bool statusBarVisible = APPLICATION->settings()->get("StatusBarVisible").toBool(); + ui->actionToggleStatusBar->setChecked(statusBarVisible); + connect(ui->actionToggleStatusBar, &QAction::toggled, this, &MainWindow::setStatusBarVisibility); + setStatusBarVisibility(statusBarVisible); + } + // Lock toolbars { bool toolbarsLocked = APPLICATION->settings()->get("ToolbarsLocked").toBool(); @@ -451,10 +460,16 @@ QMenu* MainWindow::createPopupMenu() QMenu* filteredMenu = QMainWindow::createPopupMenu(); filteredMenu->removeAction(ui->mainToolBar->toggleViewAction()); + filteredMenu->addAction(ui->actionToggleStatusBar); filteredMenu->addAction(ui->actionLockToolbars); return filteredMenu; } +void MainWindow::setStatusBarVisibility(bool state) +{ + statusBar()->setVisible(state); + APPLICATION->settings()->set("StatusBarVisible", state); +} void MainWindow::lockToolbars(bool state) { ui->mainToolBar->setMovable(!state); diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index d2e154643..07a6e1eba 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -205,6 +205,8 @@ class MainWindow : public QMainWindow { void globalSettingsClosed(); + void setStatusBarVisibility(bool); + void lockToolbars(bool); #ifndef Q_OS_MAC diff --git a/launcher/ui/MainWindow.ui b/launcher/ui/MainWindow.ui index 1ee3a5632..889012105 100644 --- a/launcher/ui/MainWindow.ui +++ b/launcher/ui/MainWindow.ui @@ -176,6 +176,7 @@ + @@ -257,6 +258,14 @@ It's a fluffy kitty :3 + + + true + + + Status Bar + + true From 877eb4172a737c44505b3c784e84ab710b291e5e Mon Sep 17 00:00:00 2001 From: Tayou Date: Thu, 7 Dec 2023 17:26:47 +0100 Subject: [PATCH 31/37] add line back to group separator Signed-off-by: Tayou --- launcher/ui/instanceview/VisualGroup.cpp | 28 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/launcher/ui/instanceview/VisualGroup.cpp b/launcher/ui/instanceview/VisualGroup.cpp index aaf31941d..7bff727fe 100644 --- a/launcher/ui/instanceview/VisualGroup.cpp +++ b/launcher/ui/instanceview/VisualGroup.cpp @@ -158,13 +158,14 @@ void VisualGroup::drawHeader(QPainter* painter, const QStyleOptionViewItem& opti painter->setRenderHint(QPainter::Antialiasing); // sizes and offsets, to keep things consistent below - int arrowOffsetLeft = fontMetrics.height() / 2 + 7; - int textOffsetLeft = arrowOffsetLeft * 2; - int arrowSize = 6; - int centerHeight = optRect.top() + fontMetrics.height() / 2; + const int arrowOffsetLeft = fontMetrics.height() / 2 + 7; + const int textOffsetLeft = arrowOffsetLeft * 2; + const int centerHeight = optRect.top() + fontMetrics.height() / 2; + const QString& textToDraw = text.isEmpty() ? QObject::tr("Ungrouped") : text; // BEGIN: arrow { + constexpr int arrowSize = 6; QPolygon arrowPolygon; if (collapsed) { arrowPolygon << QPoint(arrowOffsetLeft - arrowSize / 2, centerHeight - arrowSize) @@ -188,9 +189,26 @@ void VisualGroup::drawHeader(QPainter* painter, const QStyleOptionViewItem& opti textRect.setHeight(fontMetrics.height()); textRect.setRight(textRect.right() - 7); - painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, !text.isEmpty() ? text : QObject::tr("Ungrouped")); + painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, textToDraw); } // END: text + + // BEGIN: horizontal line + { + penColor.setAlphaF(0.05); + pen.setColor(penColor); + painter->setPen(pen); + // startPoint is left + arrow + text + space + const int startPoint = + optRect.left() + fontMetrics.height() + fontMetrics.size(Qt::AlignLeft | Qt::AlignVCenter, textToDraw).width() + 20; + painter->setRenderHint(QPainter::Antialiasing, false); + QPolygon polygon; + // for some reason the height (yPos) doesn't look centered, so we are adding 1 to the center height + const int lineHeight = centerHeight + 1; + polygon << QPoint(startPoint, lineHeight) << QPoint(optRect.right() - 3, lineHeight); + painter->drawPolyline(polygon); + } + // END: horizontal line } int VisualGroup::totalHeight() const From d7cb139235c732abb68ffbee70c45a76c998f2db Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 10 Dec 2023 00:20:06 +0000 Subject: [PATCH 32/37] chore(nix): update lockfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'nix-filter': 'github:numtide/nix-filter/41fd48e00c22b4ced525af521ead8792402de0ea' (2023-09-16) → 'github:numtide/nix-filter/c843418ecfd0344ecb85844b082ff5675e02c443' (2023-12-04) • Updated input 'nixpkgs': 'github:nixos/nixpkgs/f5c27c6136db4d76c30e533c20517df6864c46ee' (2023-11-30) → 'github:nixos/nixpkgs/09dc04054ba2ff1f861357d0e7e76d021b273cd7' (2023-12-08) --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index efaa524f6..afc584a24 100644 --- a/flake.lock +++ b/flake.lock @@ -91,11 +91,11 @@ }, "nix-filter": { "locked": { - "lastModified": 1694857738, - "narHash": "sha256-bxxNyLHjhu0N8T3REINXQ2ZkJco0ABFPn6PIe2QUfqo=", + "lastModified": 1701697642, + "narHash": "sha256-L217WytWZHSY8GW9Gx1A64OnNctbuDbfslaTEofXXRw=", "owner": "numtide", "repo": "nix-filter", - "rev": "41fd48e00c22b4ced525af521ead8792402de0ea", + "rev": "c843418ecfd0344ecb85844b082ff5675e02c443", "type": "github" }, "original": { @@ -106,11 +106,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1701336116, - "narHash": "sha256-kEmpezCR/FpITc6yMbAh4WrOCiT2zg5pSjnKrq51h5Y=", + "lastModified": 1701998057, + "narHash": "sha256-gAJGhcTO9cso7XDfAScXUlPcva427AUT2q02qrmXPdo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "f5c27c6136db4d76c30e533c20517df6864c46ee", + "rev": "09dc04054ba2ff1f861357d0e7e76d021b273cd7", "type": "github" }, "original": { From 3567369d44c6ba9a3b702caf2db18b126f1b4fc4 Mon Sep 17 00:00:00 2001 From: theMackabu Date: Tue, 12 Dec 2023 13:18:12 -0800 Subject: [PATCH 33/37] #1945 resolve minimized windows pull from dock Signed-off-by: theMackabu --- .gitignore | 3 +++ launcher/Application.cpp | 8 ++++++++ maidfile.toml | 13 +++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 maidfile.toml diff --git a/.gitignore b/.gitignore index b5523f685..9f69e985c 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ flatbuild # Snap *.snap + +# maid build +.maid \ No newline at end of file diff --git a/launcher/Application.cpp b/launcher/Application.cpp index ff5eb2a66..9e95712a7 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1513,6 +1513,13 @@ InstanceWindow* Application::showInstanceWindow(InstancePtr instance, QString pa auto& window = extras.window; if (window) { + // If the window is minimized on macOS, activate and bring it up + #ifdef Q_OS_MACOS + if (window->isMinimized()) { + window->setWindowState(window->windowState() & ~Qt::WindowMinimized); + } + #endif + window->raise(); window->activateWindow(); } else { @@ -1520,6 +1527,7 @@ InstanceWindow* Application::showInstanceWindow(InstancePtr instance, QString pa m_openWindows++; connect(window, &InstanceWindow::isClosing, this, &Application::on_windowClose); } + if (!page.isEmpty()) { window->selectPage(page); } diff --git a/maidfile.toml b/maidfile.toml new file mode 100644 index 000000000..fbd76b2e7 --- /dev/null +++ b/maidfile.toml @@ -0,0 +1,13 @@ +[project] +name = "Prism" +version = "8.0" + +[tasks] +run = { script = "./build/prismlauncher.app/Contents/MacOS/prismlauncher" } +clean = { script = ["rm -rf build", "mkdir build"] } +build = { script = ["maid init -q", "bash -c 'cd build && ninja'"] } + +[tasks.init] +depends = ["clean"] +path = "build" +script = "cmake -G Ninja -DCMAKE_INSTALL_PREFIX=install -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH='/opt/homebrew/opt/qt' -DQt6_DIR='/opt/homebrew/opt/qt' -DLauncher_BUILD_PLATFORM=macOS -DENABLE_LTO=ON .." From 836f74cd4629748ce8056f9f186284fc55d0d8b4 Mon Sep 17 00:00:00 2001 From: theMackabu Date: Tue, 12 Dec 2023 13:19:16 -0800 Subject: [PATCH 34/37] #1945 resolve issue on windows Signed-off-by: theMackabu --- launcher/Application.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 9e95712a7..6715a0709 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1513,13 +1513,17 @@ InstanceWindow* Application::showInstanceWindow(InstancePtr instance, QString pa auto& window = extras.window; if (window) { - // If the window is minimized on macOS, activate and bring it up + // If the window is minimized on macOS or Windows, activate and bring it up #ifdef Q_OS_MACOS if (window->isMinimized()) { window->setWindowState(window->windowState() & ~Qt::WindowMinimized); } + #elif defined(Q_OS_WIN) + if (window->isMinimized()) { + window->showNormal(); + } #endif - + window->raise(); window->activateWindow(); } else { From 201c9783d56cef2e1bba1fdbffdc377bdf294468 Mon Sep 17 00:00:00 2001 From: theMackabu Date: Tue, 12 Dec 2023 13:31:18 -0800 Subject: [PATCH 35/37] clang-format: fix formatting Signed-off-by: theMackabu --- launcher/Application.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 6715a0709..5f524219e 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1513,17 +1513,17 @@ InstanceWindow* Application::showInstanceWindow(InstancePtr instance, QString pa auto& window = extras.window; if (window) { - // If the window is minimized on macOS or Windows, activate and bring it up - #ifdef Q_OS_MACOS +// If the window is minimized on macOS or Windows, activate and bring it up +#ifdef Q_OS_MACOS if (window->isMinimized()) { window->setWindowState(window->windowState() & ~Qt::WindowMinimized); } - #elif defined(Q_OS_WIN) +#elif defined(Q_OS_WIN) if (window->isMinimized()) { window->showNormal(); } - #endif - +#endif + window->raise(); window->activateWindow(); } else { From 7c33a8e448d238960b89f1e1c2f14a18d12040eb Mon Sep 17 00:00:00 2001 From: theMackabu Date: Tue, 12 Dec 2023 13:37:24 -0800 Subject: [PATCH 36/37] remove: maidfile.toml (local build tool) Signed-off-by: theMackabu --- .gitignore | 5 +---- maidfile.toml | 13 ------------- 2 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 maidfile.toml diff --git a/.gitignore b/.gitignore index 9f69e985c..c699a54c3 100644 --- a/.gitignore +++ b/.gitignore @@ -55,7 +55,4 @@ result flatbuild # Snap -*.snap - -# maid build -.maid \ No newline at end of file +*.snap \ No newline at end of file diff --git a/maidfile.toml b/maidfile.toml deleted file mode 100644 index fbd76b2e7..000000000 --- a/maidfile.toml +++ /dev/null @@ -1,13 +0,0 @@ -[project] -name = "Prism" -version = "8.0" - -[tasks] -run = { script = "./build/prismlauncher.app/Contents/MacOS/prismlauncher" } -clean = { script = ["rm -rf build", "mkdir build"] } -build = { script = ["maid init -q", "bash -c 'cd build && ninja'"] } - -[tasks.init] -depends = ["clean"] -path = "build" -script = "cmake -G Ninja -DCMAKE_INSTALL_PREFIX=install -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH='/opt/homebrew/opt/qt' -DQt6_DIR='/opt/homebrew/opt/qt' -DLauncher_BUILD_PLATFORM=macOS -DENABLE_LTO=ON .." From 2391ad200f80ef6a84ffef246ed236d66928f0e4 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 12 Dec 2023 23:21:34 +0000 Subject: [PATCH 37/37] Revert change to .gitignore Signed-off-by: TheKodeToad --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c699a54c3..b5523f685 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,4 @@ result flatbuild # Snap -*.snap \ No newline at end of file +*.snap