From 3d84635b24e52c35b70e044bed67060adb1dcfd6 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 26 Oct 2023 20:09:12 +0300 Subject: [PATCH 01/17] Remove file on mod duplication Signed-off-by: Trial97 --- launcher/InstanceList.cpp | 12 ++++++------ launcher/InstanceList.h | 2 +- launcher/minecraft/mod/Resource.cpp | 10 +++++----- launcher/minecraft/mod/ResourceFolderModel.cpp | 3 --- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index 756ff93dd..e245fc2c6 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -371,13 +371,13 @@ void InstanceList::undoTrashInstance() auto top = m_trashHistory.pop(); - while (QDir(top.polyPath).exists()) { + while (QDir(top.rootPath).exists()) { top.id += "1"; - top.polyPath += "1"; + top.rootPath += "1"; } - qDebug() << "Moving" << top.trashPath << "back to" << top.polyPath; - QFile(top.trashPath).rename(top.polyPath); + qDebug() << "Moving" << top.trashPath << "back to" << top.rootPath; + QFile(top.trashPath).rename(top.rootPath); m_instanceGroupIndex[top.id] = top.groupName; increaseGroupCount(top.groupName); @@ -634,8 +634,8 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id) QString inst_type = instanceSettings->get("InstanceType").toString(); - // NOTE: Some PolyMC versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a OneSix - // instance + // NOTE: Some PrismLauncher versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a + // OneSix instance if (inst_type == "OneSix" || inst_type.isEmpty()) { inst.reset(new MinecraftInstance(m_globalSettings, instanceSettings, instanceRoot)); } else { diff --git a/launcher/InstanceList.h b/launcher/InstanceList.h index 6b0bcd810..1a70b57b9 100644 --- a/launcher/InstanceList.h +++ b/launcher/InstanceList.h @@ -58,7 +58,7 @@ enum class GroupsState { NotLoaded, Steady, Dirty }; struct TrashHistoryItem { QString id; - QString polyPath; + QString rootPath; QString trashPath; QString groupName; }; diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index da806f0f4..05940fcb4 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -130,15 +130,15 @@ bool Resource::enable(EnableAction action) if (!path.endsWith(".disabled")) return false; path.chop(9); - - if (!file.rename(path)) - return false; } else { path += ".disabled"; - - if (!file.rename(path)) + } + if (QFileInfo::exists(path)) { // the path exists so just remove the file at path + if (!QFile::remove(path)) return false; } + if (!file.rename(path)) + return false; setFile(QFileInfo(path)); diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp index 0503b660b..8f2c87747 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.cpp +++ b/launcher/minecraft/mod/ResourceFolderModel.cpp @@ -213,9 +213,6 @@ bool ResourceFolderModel::setResourceEnabled(const QModelIndexList& indexes, Ena } auto new_id = resource->internal_id(); - if (m_resources_index.contains(new_id)) { - // FIXME: https://github.com/PolyMC/PolyMC/issues/550 - } m_resources_index.remove(old_id); m_resources_index[new_id] = row; From 60a7628dbbf21c27cdc8021b01278b173f56dedb Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 26 Oct 2023 20:43:26 +0300 Subject: [PATCH 02/17] delete duplicate mods Signed-off-by: Trial97 --- launcher/minecraft/mod/tasks/BasicFolderLoadTask.h | 10 ++++++++-- launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h b/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h index 23a2b649a..6e8b8ed43 100644 --- a/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h +++ b/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h @@ -49,10 +49,16 @@ class BasicFolderLoadTask : public Task { connect(this, &Task::finished, this->thread(), &QThread::quit); m_dir.refresh(); + QStringList names; for (auto entry : m_dir.entryInfoList()) { auto resource = m_create_func(entry); - resource->moveToThread(m_thread_to_spawn_into); - m_result->resources.insert(resource->internal_id(), resource); + if (names.contains(resource->name())) { + resource->destroy(); + } else { + names << resource->name(); + resource->moveToThread(m_thread_to_spawn_into); + m_result->resources.insert(resource->internal_id(), resource); + } } if (m_aborted) diff --git a/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp b/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp index 2094df4fc..c11759dd2 100644 --- a/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp +++ b/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp @@ -62,9 +62,15 @@ void ModFolderLoadTask::executeTask() // Read JAR files that don't have metadata m_mods_dir.refresh(); + QStringList names; for (auto entry : m_mods_dir.entryInfoList()) { Mod* mod(new Mod(entry)); + if (names.contains(mod->name())) { + mod->destroy(m_index_dir, true); + continue; + } + names << mod->name(); if (mod->enabled()) { if (m_result->mods.contains(mod->internal_id())) { m_result->mods[mod->internal_id()]->setStatus(ModStatus::Installed); From 76a656a017b67453e15c669671b453cfdfd0e7f9 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Sat, 18 May 2024 22:27:11 +0300 Subject: [PATCH 03/17] retry auth step on fail Signed-off-by: Trial97 --- .../minecraft/auth/steps/EntitlementsStep.cpp | 10 ++++-- .../minecraft/auth/steps/EntitlementsStep.h | 4 ++- launcher/minecraft/auth/steps/GetSkinStep.cpp | 9 +++-- launcher/minecraft/auth/steps/GetSkinStep.h | 4 ++- .../auth/steps/LauncherLoginStep.cpp | 20 ++++++----- .../minecraft/auth/steps/LauncherLoginStep.h | 4 ++- .../auth/steps/MSADeviceCodeStep.cpp | 29 ++++++++------- .../minecraft/auth/steps/MSADeviceCodeStep.h | 4 ++- .../auth/steps/MinecraftProfileStep.cpp | 26 ++++++++------ .../auth/steps/MinecraftProfileStep.h | 4 ++- .../auth/steps/XboxAuthorizationStep.cpp | 23 ++++++------ .../auth/steps/XboxAuthorizationStep.h | 4 ++- .../minecraft/auth/steps/XboxProfileStep.cpp | 19 +++++----- .../minecraft/auth/steps/XboxProfileStep.h | 4 ++- .../minecraft/auth/steps/XboxUserStep.cpp | 19 +++++----- launcher/minecraft/auth/steps/XboxUserStep.h | 4 ++- launcher/net/NetJob.cpp | 35 +++++++++++-------- launcher/net/NetJob.h | 2 ++ 18 files changed, 138 insertions(+), 86 deletions(-) diff --git a/launcher/minecraft/auth/steps/EntitlementsStep.cpp b/launcher/minecraft/auth/steps/EntitlementsStep.cpp index 19cbe6898..4c4809fae 100644 --- a/launcher/minecraft/auth/steps/EntitlementsStep.cpp +++ b/launcher/minecraft/auth/steps/EntitlementsStep.cpp @@ -10,6 +10,7 @@ #include "Logging.h" #include "minecraft/auth/Parsers.h" #include "net/Download.h" +#include "net/NetJob.h" #include "net/StaticHeaderProxy.h" #include "tasks/Task.h" @@ -31,12 +32,15 @@ void EntitlementsStep::perform() { "Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8() } }; m_response.reset(new QByteArray()); - m_task = Net::Download::makeByteArray(url, m_response); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_request = Net::Download::makeByteArray(url, m_response); + m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + + m_task.reset(new NetJob("EntitlementsStep", APPLICATION->network())); + m_task->setAskRetry(false); + m_task->addNetAction(m_request); connect(m_task.get(), &Task::finished, this, &EntitlementsStep::onRequestDone); - m_task->setNetwork(APPLICATION->network()); m_task->start(); qDebug() << "Getting entitlements..."; } diff --git a/launcher/minecraft/auth/steps/EntitlementsStep.h b/launcher/minecraft/auth/steps/EntitlementsStep.h index dd8ec7aaa..f20fcac08 100644 --- a/launcher/minecraft/auth/steps/EntitlementsStep.h +++ b/launcher/minecraft/auth/steps/EntitlementsStep.h @@ -4,6 +4,7 @@ #include "minecraft/auth/AuthStep.h" #include "net/Download.h" +#include "net/NetJob.h" class EntitlementsStep : public AuthStep { Q_OBJECT @@ -22,5 +23,6 @@ class EntitlementsStep : public AuthStep { private: QString m_entitlements_request_id; std::shared_ptr m_response; - Net::Download::Ptr m_task; + Net::Download::Ptr m_request; + NetJob::Ptr m_task; }; diff --git a/launcher/minecraft/auth/steps/GetSkinStep.cpp b/launcher/minecraft/auth/steps/GetSkinStep.cpp index d9785b16a..a0c039cea 100644 --- a/launcher/minecraft/auth/steps/GetSkinStep.cpp +++ b/launcher/minecraft/auth/steps/GetSkinStep.cpp @@ -17,17 +17,20 @@ void GetSkinStep::perform() QUrl url(m_data->minecraftProfile.skin.url); m_response.reset(new QByteArray()); - m_task = Net::Download::makeByteArray(url, m_response); + m_request = Net::Download::makeByteArray(url, m_response); + + m_task.reset(new NetJob("GetSkinStep", APPLICATION->network())); + m_task->setAskRetry(false); + m_task->addNetAction(m_request); connect(m_task.get(), &Task::finished, this, &GetSkinStep::onRequestDone); - m_task->setNetwork(APPLICATION->network()); m_task->start(); } void GetSkinStep::onRequestDone() { - if (m_task->error() == QNetworkReply::NoError) + if (m_request->error() == QNetworkReply::NoError) m_data->minecraftProfile.skin.data = *m_response; emit finished(AccountTaskState::STATE_SUCCEEDED, tr("Got skin")); } diff --git a/launcher/minecraft/auth/steps/GetSkinStep.h b/launcher/minecraft/auth/steps/GetSkinStep.h index fffd8be03..c598f05d9 100644 --- a/launcher/minecraft/auth/steps/GetSkinStep.h +++ b/launcher/minecraft/auth/steps/GetSkinStep.h @@ -4,6 +4,7 @@ #include "minecraft/auth/AuthStep.h" #include "net/Download.h" +#include "net/NetJob.h" class GetSkinStep : public AuthStep { Q_OBJECT @@ -21,5 +22,6 @@ class GetSkinStep : public AuthStep { private: std::shared_ptr m_response; - Net::Download::Ptr m_task; + Net::Download::Ptr m_request; + NetJob::Ptr m_task; }; diff --git a/launcher/minecraft/auth/steps/LauncherLoginStep.cpp b/launcher/minecraft/auth/steps/LauncherLoginStep.cpp index d72346c74..08e1b3b1f 100644 --- a/launcher/minecraft/auth/steps/LauncherLoginStep.cpp +++ b/launcher/minecraft/auth/steps/LauncherLoginStep.cpp @@ -37,12 +37,15 @@ void LauncherLoginStep::perform() }; m_response.reset(new QByteArray()); - m_task = Net::Upload::makeByteArray(url, m_response, requestBody.toUtf8()); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_request = Net::Upload::makeByteArray(url, m_response, requestBody.toUtf8()); + m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + + m_task.reset(new NetJob("LauncherLoginStep", APPLICATION->network())); + m_task->setAskRetry(false); + m_task->addNetAction(m_request); connect(m_task.get(), &Task::finished, this, &LauncherLoginStep::onRequestDone); - m_task->setNetwork(APPLICATION->network()); m_task->start(); qDebug() << "Getting Minecraft access token..."; } @@ -50,12 +53,13 @@ void LauncherLoginStep::perform() void LauncherLoginStep::onRequestDone() { qCDebug(authCredentials()) << *m_response; - if (m_task->error() != QNetworkReply::NoError) { - qWarning() << "Reply error:" << m_task->error(); - if (Net::isApplicationError(m_task->error())) { - emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to get Minecraft access token: %1").arg(m_task->errorString())); + if (m_request->error() != QNetworkReply::NoError) { + qWarning() << "Reply error:" << m_request->error(); + if (Net::isApplicationError(m_request->error())) { + emit finished(AccountTaskState::STATE_FAILED_SOFT, + tr("Failed to get Minecraft access token: %1").arg(m_request->errorString())); } else { - emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to get Minecraft access token: %1").arg(m_task->errorString())); + emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to get Minecraft access token: %1").arg(m_request->errorString())); } return; } diff --git a/launcher/minecraft/auth/steps/LauncherLoginStep.h b/launcher/minecraft/auth/steps/LauncherLoginStep.h index 21a2a4920..0b5969f2b 100644 --- a/launcher/minecraft/auth/steps/LauncherLoginStep.h +++ b/launcher/minecraft/auth/steps/LauncherLoginStep.h @@ -3,6 +3,7 @@ #include #include "minecraft/auth/AuthStep.h" +#include "net/NetJob.h" #include "net/Upload.h" class LauncherLoginStep : public AuthStep { @@ -21,5 +22,6 @@ class LauncherLoginStep : public AuthStep { private: std::shared_ptr m_response; - Net::Upload::Ptr m_task; + Net::Upload::Ptr m_request; + NetJob::Ptr m_task; }; diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp index 22f5d4069..ebb9b6653 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.cpp @@ -65,12 +65,15 @@ void MSADeviceCodeStep::perform() { "Accept", "application/json" }, }; m_response.reset(new QByteArray()); - m_task = Net::Upload::makeByteArray(url, m_response, payload); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_request = Net::Upload::makeByteArray(url, m_response, payload); + m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + + m_task.reset(new NetJob("MSADeviceCodeStep", APPLICATION->network())); + m_task->setAskRetry(false); + m_task->addNetAction(m_request); connect(m_task.get(), &Task::finished, this, &MSADeviceCodeStep::deviceAutorizationFinished); - m_task->setNetwork(APPLICATION->network()); m_task->start(); } @@ -115,7 +118,7 @@ void MSADeviceCodeStep::deviceAutorizationFinished() tr("Device authorization failed: %1").arg(rsp.error_description.isEmpty() ? rsp.error : rsp.error_description)); return; } - if (!m_task->wasSuccessful() || m_task->error() != QNetworkReply::NoError) { + if (!m_request->wasSuccessful() || m_request->error() != QNetworkReply::NoError) { emit finished(AccountTaskState::STATE_FAILED_HARD, tr("Failed to retrieve device authorization")); qDebug() << *m_response; return; @@ -145,8 +148,8 @@ void MSADeviceCodeStep::abort() { m_expiration_timer.stop(); m_pool_timer.stop(); - if (m_task) { - m_task->abort(); + if (m_request) { + m_request->abort(); } m_is_aborted = true; emit finished(AccountTaskState::STATE_FAILED_HARD, tr("Task aborted")); @@ -175,13 +178,13 @@ void MSADeviceCodeStep::authenticateUser() { "Accept", "application/json" }, }; m_response.reset(new QByteArray()); - m_task = Net::Upload::makeByteArray(url, m_response, payload); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_request = Net::Upload::makeByteArray(url, m_response, payload); + m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers)); - connect(m_task.get(), &Task::finished, this, &MSADeviceCodeStep::authenticationFinished); + connect(m_request.get(), &Task::finished, this, &MSADeviceCodeStep::authenticationFinished); - m_task->setNetwork(APPLICATION->network()); - m_task->start(); + m_request->setNetwork(APPLICATION->network()); + m_request->start(); } struct AuthenticationResponse { @@ -221,7 +224,7 @@ AuthenticationResponse parseAuthenticationResponse(const QByteArray& data) void MSADeviceCodeStep::authenticationFinished() { - if (m_task->error() == QNetworkReply::TimeoutError) { + if (m_request->error() == QNetworkReply::TimeoutError) { // rfc8628#section-3.5 // "On encountering a connection timeout, clients MUST unilaterally // reduce their polling frequency before retrying. The use of an @@ -254,7 +257,7 @@ void MSADeviceCodeStep::authenticationFinished() tr("Device Access failed: %1").arg(rsp.error_description.isEmpty() ? rsp.error : rsp.error_description)); return; } - if (!m_task->wasSuccessful() || m_task->error() != QNetworkReply::NoError) { + if (!m_request->wasSuccessful() || m_request->error() != QNetworkReply::NoError) { startPoolTimer(); // it failed so just try again without increasing the interval return; } diff --git a/launcher/minecraft/auth/steps/MSADeviceCodeStep.h b/launcher/minecraft/auth/steps/MSADeviceCodeStep.h index e53eebc62..87e0ce6e2 100644 --- a/launcher/minecraft/auth/steps/MSADeviceCodeStep.h +++ b/launcher/minecraft/auth/steps/MSADeviceCodeStep.h @@ -38,6 +38,7 @@ #include #include "minecraft/auth/AuthStep.h" +#include "net/NetJob.h" #include "net/Upload.h" class MSADeviceCodeStep : public AuthStep { @@ -72,5 +73,6 @@ class MSADeviceCodeStep : public AuthStep { QTimer m_expiration_timer; std::shared_ptr m_response; - Net::Upload::Ptr m_task; + Net::Upload::Ptr m_request; + NetJob::Ptr m_task; }; diff --git a/launcher/minecraft/auth/steps/MinecraftProfileStep.cpp b/launcher/minecraft/auth/steps/MinecraftProfileStep.cpp index 305f44320..81b6511f5 100644 --- a/launcher/minecraft/auth/steps/MinecraftProfileStep.cpp +++ b/launcher/minecraft/auth/steps/MinecraftProfileStep.cpp @@ -22,37 +22,41 @@ void MinecraftProfileStep::perform() { "Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8() } }; m_response.reset(new QByteArray()); - m_task = Net::Download::makeByteArray(url, m_response); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_request = Net::Download::makeByteArray(url, m_response); + m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + + m_task.reset(new NetJob("MinecraftProfileStep", APPLICATION->network())); + m_task->setAskRetry(false); + m_task->addNetAction(m_request); connect(m_task.get(), &Task::finished, this, &MinecraftProfileStep::onRequestDone); - m_task->setNetwork(APPLICATION->network()); m_task->start(); } void MinecraftProfileStep::onRequestDone() { - if (m_task->error() == QNetworkReply::ContentNotFoundError) { + if (m_request->error() == QNetworkReply::ContentNotFoundError) { // NOTE: Succeed even if we do not have a profile. This is a valid account state. m_data->minecraftProfile = MinecraftProfile(); emit finished(AccountTaskState::STATE_SUCCEEDED, tr("Account has no Minecraft profile.")); return; } - if (m_task->error() != QNetworkReply::NoError) { + if (m_request->error() != QNetworkReply::NoError) { qWarning() << "Error getting profile:"; - qWarning() << " HTTP Status: " << m_task->replyStatusCode(); - qWarning() << " Internal error no.: " << m_task->error(); - qWarning() << " Error string: " << m_task->errorString(); + qWarning() << " HTTP Status: " << m_request->replyStatusCode(); + qWarning() << " Internal error no.: " << m_request->error(); + qWarning() << " Error string: " << m_request->errorString(); qWarning() << " Response:"; qWarning() << QString::fromUtf8(*m_response); - if (Net::isApplicationError(m_task->error())) { + if (Net::isApplicationError(m_request->error())) { emit finished(AccountTaskState::STATE_FAILED_SOFT, - tr("Minecraft Java profile acquisition failed: %1").arg(m_task->errorString())); + tr("Minecraft Java profile acquisition failed: %1").arg(m_request->errorString())); } else { - emit finished(AccountTaskState::STATE_OFFLINE, tr("Minecraft Java profile acquisition failed: %1").arg(m_task->errorString())); + emit finished(AccountTaskState::STATE_OFFLINE, + tr("Minecraft Java profile acquisition failed: %1").arg(m_request->errorString())); } return; } diff --git a/launcher/minecraft/auth/steps/MinecraftProfileStep.h b/launcher/minecraft/auth/steps/MinecraftProfileStep.h index 831cd52f7..e8b35b875 100644 --- a/launcher/minecraft/auth/steps/MinecraftProfileStep.h +++ b/launcher/minecraft/auth/steps/MinecraftProfileStep.h @@ -4,6 +4,7 @@ #include "minecraft/auth/AuthStep.h" #include "net/Download.h" +#include "net/NetJob.h" class MinecraftProfileStep : public AuthStep { Q_OBJECT @@ -21,5 +22,6 @@ class MinecraftProfileStep : public AuthStep { private: std::shared_ptr m_response; - Net::Download::Ptr m_task; + Net::Download::Ptr m_request; + NetJob::Ptr m_task; }; diff --git a/launcher/minecraft/auth/steps/XboxAuthorizationStep.cpp b/launcher/minecraft/auth/steps/XboxAuthorizationStep.cpp index f07220986..4f5f14a33 100644 --- a/launcher/minecraft/auth/steps/XboxAuthorizationStep.cpp +++ b/launcher/minecraft/auth/steps/XboxAuthorizationStep.cpp @@ -42,12 +42,15 @@ void XboxAuthorizationStep::perform() { "Accept", "application/json" }, }; m_response.reset(new QByteArray()); - m_task = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8()); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_request = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8()); + m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + + m_task.reset(new NetJob("XboxAuthorizationStep", APPLICATION->network())); + m_task->setAskRetry(false); + m_task->addNetAction(m_request); connect(m_task.get(), &Task::finished, this, &XboxAuthorizationStep::onRequestDone); - m_task->setNetwork(APPLICATION->network()); m_task->start(); qDebug() << "Getting authorization token for " << m_relyingParty; } @@ -55,19 +58,19 @@ void XboxAuthorizationStep::perform() void XboxAuthorizationStep::onRequestDone() { qCDebug(authCredentials()) << *m_response; - if (m_task->error() != QNetworkReply::NoError) { - qWarning() << "Reply error:" << m_task->error(); - if (Net::isApplicationError(m_task->error())) { + if (m_request->error() != QNetworkReply::NoError) { + qWarning() << "Reply error:" << m_request->error(); + if (Net::isApplicationError(m_request->error())) { if (!processSTSError()) { emit finished(AccountTaskState::STATE_FAILED_SOFT, - tr("Failed to get authorization for %1 services. Error %2.").arg(m_authorizationKind, m_task->error())); + tr("Failed to get authorization for %1 services. Error %2.").arg(m_authorizationKind, m_request->error())); } else { emit finished(AccountTaskState::STATE_FAILED_SOFT, - tr("Unknown STS error for %1 services: %2").arg(m_authorizationKind, m_task->errorString())); + tr("Unknown STS error for %1 services: %2").arg(m_authorizationKind, m_request->errorString())); } } else { emit finished(AccountTaskState::STATE_OFFLINE, - tr("Failed to get authorization for %1 services: %2").arg(m_authorizationKind, m_task->errorString())); + tr("Failed to get authorization for %1 services: %2").arg(m_authorizationKind, m_request->errorString())); } return; } @@ -92,7 +95,7 @@ void XboxAuthorizationStep::onRequestDone() bool XboxAuthorizationStep::processSTSError() { - if (m_task->error() == QNetworkReply::AuthenticationRequiredError) { + if (m_request->error() == QNetworkReply::AuthenticationRequiredError) { QJsonParseError jsonError; QJsonDocument doc = QJsonDocument::fromJson(*m_response, &jsonError); if (jsonError.error) { diff --git a/launcher/minecraft/auth/steps/XboxAuthorizationStep.h b/launcher/minecraft/auth/steps/XboxAuthorizationStep.h index f6329b7f0..8418727c4 100644 --- a/launcher/minecraft/auth/steps/XboxAuthorizationStep.h +++ b/launcher/minecraft/auth/steps/XboxAuthorizationStep.h @@ -3,6 +3,7 @@ #include #include "minecraft/auth/AuthStep.h" +#include "net/NetJob.h" #include "net/Upload.h" class XboxAuthorizationStep : public AuthStep { @@ -28,5 +29,6 @@ class XboxAuthorizationStep : public AuthStep { QString m_authorizationKind; std::shared_ptr m_response; - Net::Upload::Ptr m_task; + Net::Upload::Ptr m_request; + NetJob::Ptr m_task; }; diff --git a/launcher/minecraft/auth/steps/XboxProfileStep.cpp b/launcher/minecraft/auth/steps/XboxProfileStep.cpp index 440a4657c..a784fa195 100644 --- a/launcher/minecraft/auth/steps/XboxProfileStep.cpp +++ b/launcher/minecraft/auth/steps/XboxProfileStep.cpp @@ -34,25 +34,28 @@ void XboxProfileStep::perform() }; m_response.reset(new QByteArray()); - m_task = Net::Download::makeByteArray(url, m_response); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_request = Net::Download::makeByteArray(url, m_response); + m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + + m_task.reset(new NetJob("XboxProfileStep", APPLICATION->network())); + m_task->setAskRetry(false); + m_task->addNetAction(m_request); connect(m_task.get(), &Task::finished, this, &XboxProfileStep::onRequestDone); - m_task->setNetwork(APPLICATION->network()); m_task->start(); qDebug() << "Getting Xbox profile..."; } void XboxProfileStep::onRequestDone() { - if (m_task->error() != QNetworkReply::NoError) { - qWarning() << "Reply error:" << m_task->error(); + if (m_request->error() != QNetworkReply::NoError) { + qWarning() << "Reply error:" << m_request->error(); qCDebug(authCredentials()) << *m_response; - if (Net::isApplicationError(m_task->error())) { - emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to retrieve the Xbox profile: %1").arg(m_task->errorString())); + if (Net::isApplicationError(m_request->error())) { + emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to retrieve the Xbox profile: %1").arg(m_request->errorString())); } else { - emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to retrieve the Xbox profile: %1").arg(m_task->errorString())); + emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to retrieve the Xbox profile: %1").arg(m_request->errorString())); } return; } diff --git a/launcher/minecraft/auth/steps/XboxProfileStep.h b/launcher/minecraft/auth/steps/XboxProfileStep.h index dfa273d9c..f2ab874f2 100644 --- a/launcher/minecraft/auth/steps/XboxProfileStep.h +++ b/launcher/minecraft/auth/steps/XboxProfileStep.h @@ -4,6 +4,7 @@ #include "minecraft/auth/AuthStep.h" #include "net/Download.h" +#include "net/NetJob.h" class XboxProfileStep : public AuthStep { Q_OBJECT @@ -21,5 +22,6 @@ class XboxProfileStep : public AuthStep { private: std::shared_ptr m_response; - Net::Download::Ptr m_task; + Net::Download::Ptr m_request; + NetJob::Ptr m_task; }; diff --git a/launcher/minecraft/auth/steps/XboxUserStep.cpp b/launcher/minecraft/auth/steps/XboxUserStep.cpp index c9453dba1..3e697b506 100644 --- a/launcher/minecraft/auth/steps/XboxUserStep.cpp +++ b/launcher/minecraft/auth/steps/XboxUserStep.cpp @@ -38,24 +38,27 @@ void XboxUserStep::perform() { "x-xbl-contract-version", "1" } }; m_response.reset(new QByteArray()); - m_task = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8()); - m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + m_request = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8()); + m_request->addHeaderProxy(new Net::StaticHeaderProxy(headers)); + + m_task.reset(new NetJob("XboxUserStep", APPLICATION->network())); + m_task->setAskRetry(false); + m_task->addNetAction(m_request); connect(m_task.get(), &Task::finished, this, &XboxUserStep::onRequestDone); - m_task->setNetwork(APPLICATION->network()); m_task->start(); qDebug() << "First layer of XBox auth ... commencing."; } void XboxUserStep::onRequestDone() { - if (m_task->error() != QNetworkReply::NoError) { - qWarning() << "Reply error:" << m_task->error(); - if (Net::isApplicationError(m_task->error())) { - emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("XBox user authentication failed: %1").arg(m_task->errorString())); + if (m_request->error() != QNetworkReply::NoError) { + qWarning() << "Reply error:" << m_request->error(); + if (Net::isApplicationError(m_request->error())) { + emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("XBox user authentication failed: %1").arg(m_request->errorString())); } else { - emit finished(AccountTaskState::STATE_OFFLINE, tr("XBox user authentication failed: %1").arg(m_task->errorString())); + emit finished(AccountTaskState::STATE_OFFLINE, tr("XBox user authentication failed: %1").arg(m_request->errorString())); } return; } diff --git a/launcher/minecraft/auth/steps/XboxUserStep.h b/launcher/minecraft/auth/steps/XboxUserStep.h index 934a00c52..f6cc822f2 100644 --- a/launcher/minecraft/auth/steps/XboxUserStep.h +++ b/launcher/minecraft/auth/steps/XboxUserStep.h @@ -3,6 +3,7 @@ #include #include "minecraft/auth/AuthStep.h" +#include "net/NetJob.h" #include "net/Upload.h" class XboxUserStep : public AuthStep { @@ -21,5 +22,6 @@ class XboxUserStep : public AuthStep { private: std::shared_ptr m_response; - Net::Upload::Ptr m_task; + Net::Upload::Ptr m_request; + NetJob::Ptr m_task; }; diff --git a/launcher/net/NetJob.cpp b/launcher/net/NetJob.cpp index 65d6ec3a4..e8df8c3a8 100644 --- a/launcher/net/NetJob.cpp +++ b/launcher/net/NetJob.cpp @@ -144,21 +144,28 @@ void NetJob::updateState() void NetJob::emitFailed(QString reason) { #if defined(LAUNCHER_APPLICATION) - auto response = CustomMessageBox::selectable(nullptr, "Confirm retry", - "The tasks failed\n" - "Failed urls\n" + - getFailedFiles().join("\n\t") + - "\n" - "If this continues to happen please check the logs of the application" - "Do you want to retry?", - QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) - ->exec(); + if (m_ask_retry) { + auto response = CustomMessageBox::selectable(nullptr, "Confirm retry", + "The tasks failed\n" + "Failed urls\n" + + getFailedFiles().join("\n\t") + + "\n" + "If this continues to happen please check the logs of the application" + "Do you want to retry?", + QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) + ->exec(); - if (response == QMessageBox::Yes) { - m_try = 0; - executeNextSubTask(); - return; + if (response == QMessageBox::Yes) { + m_try = 0; + executeNextSubTask(); + return; + } } #endif ConcurrentTask::emitFailed(reason); -} \ No newline at end of file +} + +void NetJob::setAskRetry(bool askRetry) +{ + m_ask_retry = askRetry; +} diff --git a/launcher/net/NetJob.h b/launcher/net/NetJob.h index 09da95771..b421d2450 100644 --- a/launcher/net/NetJob.h +++ b/launcher/net/NetJob.h @@ -62,6 +62,7 @@ class NetJob : public ConcurrentTask { auto getFailedActions() -> QList; auto getFailedFiles() -> QList; + void setAskRetry(bool askRetry); public slots: // Qt can't handle auto at the start for some reason? @@ -78,4 +79,5 @@ class NetJob : public ConcurrentTask { shared_qobject_ptr m_network; int m_try = 1; + bool m_ask_retry = true; }; From d2510b851ba9576304f89c7e146bbd41215542a6 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 14 Jun 2024 22:45:15 +0300 Subject: [PATCH 04/17] mark files as duplicate Signed-off-by: Trial97 --- launcher/FileSystem.cpp | 26 +++++++++++++++++++ launcher/FileSystem.h | 2 ++ launcher/minecraft/mod/Resource.cpp | 7 +++-- .../minecraft/mod/tasks/BasicFolderLoadTask.h | 17 ++++++------ .../minecraft/mod/tasks/ModFolderLoadTask.cpp | 13 +++++----- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index cafc4f25a..36410f03e 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -1701,4 +1701,30 @@ QString getPathNameInLocal8bit(const QString& file) } #endif +QString getUniqueResourceName(const QString& filePath) +{ + auto newFileName = filePath; + if (!newFileName.endsWith(".disabled")) { + return newFileName; // prioritize enabled mods + } + newFileName.chop(9); + if (!QFile::exists(newFileName)) { + return filePath; + } + QFileInfo fileInfo(filePath); + auto baseName = fileInfo.completeBaseName(); + auto path = fileInfo.absolutePath(); + + int counter = 1; + do { + if (counter == 1) { + newFileName = FS::PathCombine(path, baseName + ".duplicate"); + } else { + newFileName = FS::PathCombine(path, baseName + ".duplicate" + QString::number(counter)); + } + counter++; + } while (QFile::exists(newFileName)); + + return newFileName; +} } // namespace FS diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index 23bf5f16e..66adf7a36 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -560,4 +560,6 @@ uintmax_t hardLinkCount(const QString& path); QString getPathNameInLocal8bit(const QString& file); #endif +QString getUniqueResourceName(const QString& filePath); + } // namespace FS diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index 62bf6b9a2..6066f02db 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -161,10 +161,13 @@ bool Resource::enable(EnableAction action) path.chop(9); } else { path += ".disabled"; + auto newFilePath = FS::getUniqueResourceName(path); + if (newFilePath != path) { + FS::move(path, newFilePath); + } } if (QFileInfo::exists(path)) { // the path exists so just remove the file at path - if (!QFile::remove(path)) - return false; + return false; } if (!file.rename(path)) return false; diff --git a/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h b/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h index 6e8b8ed43..2bce2c137 100644 --- a/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h +++ b/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h @@ -7,6 +7,7 @@ #include +#include "FileSystem.h" #include "minecraft/mod/Resource.h" #include "tasks/Task.h" @@ -49,16 +50,16 @@ class BasicFolderLoadTask : public Task { connect(this, &Task::finished, this->thread(), &QThread::quit); m_dir.refresh(); - QStringList names; for (auto entry : m_dir.entryInfoList()) { - auto resource = m_create_func(entry); - if (names.contains(resource->name())) { - resource->destroy(); - } else { - names << resource->name(); - resource->moveToThread(m_thread_to_spawn_into); - m_result->resources.insert(resource->internal_id(), resource); + auto filePath = entry.absoluteFilePath(); + auto newFilePath = FS::getUniqueResourceName(filePath); + if (newFilePath != filePath) { + FS::move(filePath, newFilePath); + entry = QFileInfo(newFilePath); } + auto resource = m_create_func(entry); + resource->moveToThread(m_thread_to_spawn_into); + m_result->resources.insert(resource->internal_id(), resource); } if (m_aborted) diff --git a/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp b/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp index c11759dd2..501d5be13 100644 --- a/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp +++ b/launcher/minecraft/mod/tasks/ModFolderLoadTask.cpp @@ -36,6 +36,7 @@ #include "ModFolderLoadTask.h" +#include "FileSystem.h" #include "minecraft/mod/MetadataHandler.h" #include @@ -62,15 +63,15 @@ void ModFolderLoadTask::executeTask() // Read JAR files that don't have metadata m_mods_dir.refresh(); - QStringList names; for (auto entry : m_mods_dir.entryInfoList()) { + auto filePath = entry.absoluteFilePath(); + auto newFilePath = FS::getUniqueResourceName(filePath); + if (newFilePath != filePath) { + FS::move(filePath, newFilePath); + entry = QFileInfo(newFilePath); + } Mod* mod(new Mod(entry)); - if (names.contains(mod->name())) { - mod->destroy(m_index_dir, true); - continue; - } - names << mod->name(); if (mod->enabled()) { if (m_result->mods.contains(mod->internal_id())) { m_result->mods[mod->internal_id()]->setStatus(ModStatus::Installed); From b872f88617fa282f0b1a23e0a134225d360a000c Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 14 Jun 2024 22:46:39 +0300 Subject: [PATCH 05/17] do not double rename Signed-off-by: Trial97 --- launcher/minecraft/mod/Resource.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index 6066f02db..9228d5165 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -161,10 +161,7 @@ bool Resource::enable(EnableAction action) path.chop(9); } else { path += ".disabled"; - auto newFilePath = FS::getUniqueResourceName(path); - if (newFilePath != path) { - FS::move(path, newFilePath); - } + path = FS::getUniqueResourceName(path); } if (QFileInfo::exists(path)) { // the path exists so just remove the file at path return false; From 1a84dc9bcabbd212d1402d04f3f8a41021bdca8f Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 14 Jun 2024 22:47:42 +0300 Subject: [PATCH 06/17] no need for extra exist check Signed-off-by: Trial97 --- launcher/minecraft/mod/Resource.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index 9228d5165..62871cbf2 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -163,9 +163,6 @@ bool Resource::enable(EnableAction action) path += ".disabled"; path = FS::getUniqueResourceName(path); } - if (QFileInfo::exists(path)) { // the path exists so just remove the file at path - return false; - } if (!file.rename(path)) return false; From 8cdaf5d05f714fadc899081a1100f594f0e19782 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 14 Jun 2024 23:27:27 +0300 Subject: [PATCH 07/17] fix tests Signed-off-by: Trial97 --- launcher/minecraft/mod/Resource.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index 62871cbf2..2a7626953 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -161,7 +161,9 @@ bool Resource::enable(EnableAction action) path.chop(9); } else { path += ".disabled"; - path = FS::getUniqueResourceName(path); + if (QFile::exists(path)) { + path = FS::getUniqueResourceName(path); + } } if (!file.rename(path)) return false; From 046e3588afc57df5669e1b9c230275b7a5b44bc0 Mon Sep 17 00:00:00 2001 From: Tayou Date: Sun, 30 Jun 2024 21:35:03 +0200 Subject: [PATCH 08/17] more system themes initial changes Signed-off-by: Tayou --- launcher/Application.cpp | 4 ++-- launcher/ui/themes/SystemTheme.cpp | 34 +++++++++++++++++++++-------- launcher/ui/themes/SystemTheme.h | 6 +++-- launcher/ui/themes/ThemeManager.cpp | 30 +++++++++++++++++++++---- launcher/ui/themes/ThemeManager.h | 1 + 5 files changed, 58 insertions(+), 17 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 7ae66e13a..327b63b02 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1073,8 +1073,8 @@ bool Application::createSetupWizard() // set default theme after going into theme wizard if (!validIcons) settings()->set("IconTheme", QString("pe_colored")); - if (!validWidgets) - settings()->set("ApplicationTheme", QString("system")); + //if (!validWidgets) + //settings()->set("ApplicationTheme", QString("system")); m_themeManager->applyCurrentlySelectedTheme(true); diff --git a/launcher/ui/themes/SystemTheme.cpp b/launcher/ui/themes/SystemTheme.cpp index cefe664db..d927d2207 100644 --- a/launcher/ui/themes/SystemTheme.cpp +++ b/launcher/ui/themes/SystemTheme.cpp @@ -43,25 +43,33 @@ SystemTheme::SystemTheme() { + themeName = QObject::tr("System"); themeDebugLog() << "Determining System Theme..."; const auto& style = QApplication::style(); - systemPalette = QApplication::palette(); - QString lowerThemeName = style->objectName(); + colorPalette = QApplication::palette(); + QString lowerThemeName = style->name(); themeDebugLog() << "System theme seems to be:" << lowerThemeName; QStringList styles = QStyleFactory::keys(); for (auto& st : styles) { themeDebugLog() << "Considering theme from theme factory:" << st.toLower(); if (st.toLower() == lowerThemeName) { - systemTheme = st; - themeDebugLog() << "System theme has been determined to be:" << systemTheme; + widgetTheme = st; + themeDebugLog() << "System theme has been determined to be:" << widgetTheme; return; } } // fall back to fusion if we can't find the current theme. - systemTheme = "Fusion"; + widgetTheme = "Fusion"; themeDebugLog() << "System theme not found, defaulted to Fusion"; } +SystemTheme::SystemTheme(QString& styleName) +{ + themeName = styleName; + widgetTheme = styleName; + colorPalette = QApplication::palette(); +} + void SystemTheme::apply(bool initial) { // See https://github.com/MultiMC/Launcher/issues/1790 @@ -76,22 +84,30 @@ void SystemTheme::apply(bool initial) QString SystemTheme::id() { - return "system"; + return themeName; } QString SystemTheme::name() { - return QObject::tr("System"); + if (themeName.toLower() == "windowsvista") { + return QObject::tr("Windows Vista"); + } else if (themeName.toLower() == "windows") { + return QObject::tr("Windows 9x"); + } else if (themeName.toLower() == "windows11") { + return QObject::tr("Windows 11"); + } else { + return themeName; + } } QString SystemTheme::qtTheme() { - return systemTheme; + return widgetTheme; } QPalette SystemTheme::colorScheme() { - return systemPalette; + return colorPalette; } QString SystemTheme::appStyleSheet() diff --git a/launcher/ui/themes/SystemTheme.h b/launcher/ui/themes/SystemTheme.h index 4f7d83e57..a0e77fae1 100644 --- a/launcher/ui/themes/SystemTheme.h +++ b/launcher/ui/themes/SystemTheme.h @@ -39,6 +39,7 @@ class SystemTheme : public ITheme { public: SystemTheme(); + explicit SystemTheme(QString& themeName); virtual ~SystemTheme() {} void apply(bool initial) override; @@ -53,6 +54,7 @@ class SystemTheme : public ITheme { QColor fadeColor() override; private: - QPalette systemPalette; - QString systemTheme; + QPalette colorPalette; + QString widgetTheme; + QString themeName; }; diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index 1cb83ca26..601bc66c2 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "Exception.h" #include "ui/themes/BrightTheme.h" #include "ui/themes/CatPack.h" @@ -119,14 +121,30 @@ void ThemeManager::initializeIcons() void ThemeManager::initializeWidgets() { + themeDebugLog() << "Determining System Widget Theme..."; + const auto& style = QApplication::style(); + currentlySelectedSystemTheme = style->name(); + themeDebugLog() << "System theme seems to be:" << currentlySelectedSystemTheme; + themeDebugLog() << "<> Initializing Widget Themes"; - themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); + //themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); auto darkThemeId = addTheme(std::make_unique()); themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); - // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in - // dropdown?) + themeDebugLog() << "<> Initializing System Themes"; + QStringList styles = QStyleFactory::keys(); + for (auto& st : styles) { +#if Q_OS_WINDOWS + if (QSysInfo::productVersion() != "11" && st == "windows11") { + continue; + } +#endif + themeDebugLog() << "Loading System Theme:" << addTheme(std::make_unique(st)); + } + + // TODO: need some way to differentiate same name themes in different subdirectories + // (maybe smaller grey text next to theme name in dropdown?) if (!m_applicationThemeFolder.mkpath(".")) themeWarningLog() << "Couldn't create theme folder"; @@ -238,7 +256,11 @@ void ThemeManager::applyCurrentlySelectedTheme(bool initial) auto settings = APPLICATION->settings(); setIconTheme(settings->get("IconTheme").toString()); themeDebugLog() << "<> Icon theme set."; - setApplicationTheme(settings->get("ApplicationTheme").toString(), initial); + auto applicationTheme = settings->get("ApplicationTheme").toString(); + if (applicationTheme == "") { + applicationTheme = currentlySelectedSystemTheme; + } + setApplicationTheme(applicationTheme, initial); themeDebugLog() << "<> Application theme set."; } diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h index 47b9589e3..ddf619a80 100644 --- a/launcher/ui/themes/ThemeManager.h +++ b/launcher/ui/themes/ThemeManager.h @@ -64,6 +64,7 @@ class ThemeManager { QDir m_applicationThemeFolder{ "themes" }; QDir m_catPacksFolder{ "catpacks" }; std::map> m_cat_packs; + QString currentlySelectedSystemTheme; void initializeThemes(); void initializeCatPacks(); From f0c9b520557e467b99a2547360260c494f9f218d Mon Sep 17 00:00:00 2001 From: Tayou Date: Sun, 30 Jun 2024 21:41:37 +0200 Subject: [PATCH 09/17] oop Signed-off-by: Tayou --- launcher/ui/themes/SystemTheme.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/themes/SystemTheme.cpp b/launcher/ui/themes/SystemTheme.cpp index d927d2207..aa5af95bf 100644 --- a/launcher/ui/themes/SystemTheme.cpp +++ b/launcher/ui/themes/SystemTheme.cpp @@ -47,7 +47,7 @@ SystemTheme::SystemTheme() themeDebugLog() << "Determining System Theme..."; const auto& style = QApplication::style(); colorPalette = QApplication::palette(); - QString lowerThemeName = style->name(); + QString lowerThemeName = style->objectName(); themeDebugLog() << "System theme seems to be:" << lowerThemeName; QStringList styles = QStyleFactory::keys(); for (auto& st : styles) { From a184b26a00be14c84bc86663de2fedd2c9ca8610 Mon Sep 17 00:00:00 2001 From: Tayou Date: Sun, 30 Jun 2024 21:47:52 +0200 Subject: [PATCH 10/17] #ifdef, not #if... I'm smort Signed-off-by: Tayou --- launcher/ui/themes/ThemeManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index 601bc66c2..e4ad49db3 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -135,7 +135,7 @@ void ThemeManager::initializeWidgets() themeDebugLog() << "<> Initializing System Themes"; QStringList styles = QStyleFactory::keys(); for (auto& st : styles) { -#if Q_OS_WINDOWS +#ifdef Q_OS_WINDOWS if (QSysInfo::productVersion() != "11" && st == "windows11") { continue; } From 7104f8909dace5139dcc75b8f6be75cd9ef063a1 Mon Sep 17 00:00:00 2001 From: Tayou Date: Sun, 30 Jun 2024 21:52:26 +0200 Subject: [PATCH 11/17] another oop Signed-off-by: Tayou --- launcher/ui/themes/ThemeManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index e4ad49db3..00b89b780 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -123,7 +123,7 @@ void ThemeManager::initializeWidgets() { themeDebugLog() << "Determining System Widget Theme..."; const auto& style = QApplication::style(); - currentlySelectedSystemTheme = style->name(); + currentlySelectedSystemTheme = style->objectName(); themeDebugLog() << "System theme seems to be:" << currentlySelectedSystemTheme; themeDebugLog() << "<> Initializing Widget Themes"; From 4f795eb6efd967e3d38fd6f7417bc8313dd6659a Mon Sep 17 00:00:00 2001 From: Tayou Date: Sun, 30 Jun 2024 22:06:01 +0200 Subject: [PATCH 12/17] format Signed-off-by: Tayou --- launcher/Application.cpp | 4 ++-- launcher/ui/themes/ThemeManager.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 327b63b02..6254e38fe 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1073,8 +1073,8 @@ bool Application::createSetupWizard() // set default theme after going into theme wizard if (!validIcons) settings()->set("IconTheme", QString("pe_colored")); - //if (!validWidgets) - //settings()->set("ApplicationTheme", QString("system")); + // if (!validWidgets) + // settings()->set("ApplicationTheme", QString("system")); m_themeManager->applyCurrentlySelectedTheme(true); diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index 00b89b780..b3461f654 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -23,8 +23,8 @@ #include #include #include -#include #include +#include #include "Exception.h" #include "ui/themes/BrightTheme.h" #include "ui/themes/CatPack.h" @@ -127,7 +127,7 @@ void ThemeManager::initializeWidgets() themeDebugLog() << "System theme seems to be:" << currentlySelectedSystemTheme; themeDebugLog() << "<> Initializing Widget Themes"; - //themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); + // themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); auto darkThemeId = addTheme(std::make_unique()); themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); From d70be5121c3f67c1fa171116fd183be5b814f60b Mon Sep 17 00:00:00 2001 From: Tayou Date: Sun, 30 Jun 2024 23:27:45 +0200 Subject: [PATCH 13/17] tooltips Signed-off-by: Tayou --- launcher/ui/themes/BrightTheme.cpp | 38 +++++++++++++++++++ launcher/ui/themes/BrightTheme.h | 35 +++++++++++++++++ launcher/ui/themes/CustomTheme.cpp | 6 ++- launcher/ui/themes/CustomTheme.h | 9 ++++- launcher/ui/themes/DarkTheme.cpp | 38 +++++++++++++++++++ launcher/ui/themes/DarkTheme.h | 35 +++++++++++++++++ launcher/ui/themes/ITheme.h | 1 + launcher/ui/themes/SystemTheme.cpp | 20 +++++++++- launcher/ui/themes/SystemTheme.h | 3 +- launcher/ui/themes/ThemeManager.cpp | 6 +-- launcher/ui/themes/ThemeManager.h | 2 +- .../ui/widgets/ThemeCustomizationWidget.cpp | 6 ++- 12 files changed, 189 insertions(+), 10 deletions(-) diff --git a/launcher/ui/themes/BrightTheme.cpp b/launcher/ui/themes/BrightTheme.cpp index ffccdaab1..39a5bfd14 100644 --- a/launcher/ui/themes/BrightTheme.cpp +++ b/launcher/ui/themes/BrightTheme.cpp @@ -1,3 +1,37 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2024 Tayou + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "BrightTheme.h" #include @@ -55,3 +89,7 @@ QString BrightTheme::appStyleSheet() { return QString(); } +QString BrightTheme::tooltip() +{ + return QString(); +} diff --git a/launcher/ui/themes/BrightTheme.h b/launcher/ui/themes/BrightTheme.h index 44a767492..750e7bfc5 100644 --- a/launcher/ui/themes/BrightTheme.h +++ b/launcher/ui/themes/BrightTheme.h @@ -1,3 +1,37 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2024 Tayou + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #pragma once #include "FusionTheme.h" @@ -8,6 +42,7 @@ class BrightTheme : public FusionTheme { QString id() override; QString name() override; + QString tooltip() override; bool hasStyleSheet() override; QString appStyleSheet() override; bool hasColorScheme() override; diff --git a/launcher/ui/themes/CustomTheme.cpp b/launcher/ui/themes/CustomTheme.cpp index 4859983c6..22b366b62 100644 --- a/launcher/ui/themes/CustomTheme.cpp +++ b/launcher/ui/themes/CustomTheme.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 Tayou + * Copyright (C) 2024 Tayou * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -285,3 +285,7 @@ QString CustomTheme::qtTheme() { return m_widgets; } +QString CustomTheme::tooltip() +{ + return m_tooltip; +} diff --git a/launcher/ui/themes/CustomTheme.h b/launcher/ui/themes/CustomTheme.h index 3ec4cafa2..761a2bd90 100644 --- a/launcher/ui/themes/CustomTheme.h +++ b/launcher/ui/themes/CustomTheme.h @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 Tayou + * Copyright (C) 2024 Tayou * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,6 +44,7 @@ class CustomTheme : public ITheme { QString id() override; QString name() override; + QString tooltip() override; bool hasStyleSheet() override; QString appStyleSheet() override; bool hasColorScheme() override; @@ -62,4 +63,10 @@ class CustomTheme : public ITheme { QString m_id; QString m_widgets; QString m_qssFilePath; + /** + * The tooltip could be defined in the theme json, + * or composed of other fields that could be in there. + * like author, license, etc. + */ + QString m_tooltip = ""; }; diff --git a/launcher/ui/themes/DarkTheme.cpp b/launcher/ui/themes/DarkTheme.cpp index c3a68a2d4..429d046ac 100644 --- a/launcher/ui/themes/DarkTheme.cpp +++ b/launcher/ui/themes/DarkTheme.cpp @@ -1,3 +1,37 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2024 Tayou + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "DarkTheme.h" #include @@ -56,3 +90,7 @@ QString DarkTheme::appStyleSheet() { return "QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"; } +QString DarkTheme::tooltip() +{ + return ""; +} diff --git a/launcher/ui/themes/DarkTheme.h b/launcher/ui/themes/DarkTheme.h index 431e9a735..819f6a934 100644 --- a/launcher/ui/themes/DarkTheme.h +++ b/launcher/ui/themes/DarkTheme.h @@ -1,3 +1,37 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2024 Tayou + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #pragma once #include "FusionTheme.h" @@ -8,6 +42,7 @@ class DarkTheme : public FusionTheme { QString id() override; QString name() override; + QString tooltip() override; bool hasStyleSheet() override; QString appStyleSheet() override; bool hasColorScheme() override; diff --git a/launcher/ui/themes/ITheme.h b/launcher/ui/themes/ITheme.h index d85e7f983..45d3e2739 100644 --- a/launcher/ui/themes/ITheme.h +++ b/launcher/ui/themes/ITheme.h @@ -44,6 +44,7 @@ class ITheme { virtual void apply(bool initial); virtual QString id() = 0; virtual QString name() = 0; + virtual QString tooltip() = 0; virtual bool hasStyleSheet() = 0; virtual QString appStyleSheet() = 0; virtual QString qtTheme() = 0; diff --git a/launcher/ui/themes/SystemTheme.cpp b/launcher/ui/themes/SystemTheme.cpp index aa5af95bf..a46b2002a 100644 --- a/launcher/ui/themes/SystemTheme.cpp +++ b/launcher/ui/themes/SystemTheme.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 Tayou + * Copyright (C) 2024 Tayou * Copyright (C) 2024 TheKodeToad * * This program is free software: you can redistribute it and/or modify @@ -35,7 +35,6 @@ */ #include "SystemTheme.h" #include -#include #include #include #include "HintOverrideProxyStyle.h" @@ -100,6 +99,23 @@ QString SystemTheme::name() } } +QString SystemTheme::tooltip() +{ + if (themeName.toLower() == "windowsvista") { + return QObject::tr("Widget style trying to look like your win32 theme"); + } else if (themeName.toLower() == "windows") { + return QObject::tr("Windows 9x inspired widget style"); + } else if (themeName.toLower() == "windows11") { + return QObject::tr("WinUI 3 inspired Qt widget style"); + } else if (themeName.toLower() == "fusion") { + return QObject::tr("The default Qt widget style"); + } else if (themeName.toLower() == "system") { + return QObject::tr("Your current system theme") + " (" + widgetTheme + ")"; + } else { + return ""; + } +} + QString SystemTheme::qtTheme() { return widgetTheme; diff --git a/launcher/ui/themes/SystemTheme.h b/launcher/ui/themes/SystemTheme.h index a0e77fae1..bcfe34288 100644 --- a/launcher/ui/themes/SystemTheme.h +++ b/launcher/ui/themes/SystemTheme.h @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 Tayou + * Copyright (C) 2024 Tayou * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,6 +45,7 @@ class SystemTheme : public ITheme { QString id() override; QString name() override; + QString tooltip() override; QString qtTheme() override; bool hasStyleSheet() override; QString appStyleSheet() override; diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index b3461f654..ac2bf26dc 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 Tayou + * Copyright (C) 2024 Tayou * Copyright (C) 2023 TheKodeToad * * This program is free software: you can redistribute it and/or modify @@ -127,12 +127,12 @@ void ThemeManager::initializeWidgets() themeDebugLog() << "System theme seems to be:" << currentlySelectedSystemTheme; themeDebugLog() << "<> Initializing Widget Themes"; - // themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); + themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); auto darkThemeId = addTheme(std::make_unique()); themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); - themeDebugLog() << "<> Initializing System Themes"; + themeDebugLog() << "<> Initializing System Widget Themes"; QStringList styles = QStyleFactory::keys(); for (auto& st : styles) { #ifdef Q_OS_WINDOWS diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h index ddf619a80..9d01d38e7 100644 --- a/launcher/ui/themes/ThemeManager.h +++ b/launcher/ui/themes/ThemeManager.h @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 Tayou + * Copyright (C) 2024 Tayou * Copyright (C) 2023 TheKodeToad * * This program is free software: you can redistribute it and/or modify diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.cpp b/launcher/ui/widgets/ThemeCustomizationWidget.cpp index 9c5df0067..7a54bd390 100644 --- a/launcher/ui/widgets/ThemeCustomizationWidget.cpp +++ b/launcher/ui/widgets/ThemeCustomizationWidget.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only /* * Prism Launcher - Minecraft Launcher - * Copyright (C) 2022 Tayou + * Copyright (C) 2024 Tayou * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -151,6 +151,10 @@ void ThemeCustomizationWidget::loadSettings() int idx = 0; for (auto& theme : themes) { ui->widgetStyleComboBox->addItem(theme->name(), theme->id()); + if (theme->tooltip() != "") { + int index = ui->widgetStyleComboBox->count() - 1; + ui->widgetStyleComboBox->setItemData(index, theme->tooltip(), Qt::ToolTipRole); + } if (currentTheme == theme->id()) { ui->widgetStyleComboBox->setCurrentIndex(idx); } From dbcfefca1b0e537aaec2bfe0ddc091c5f994317d Mon Sep 17 00:00:00 2001 From: Tayou Date: Mon, 1 Jul 2024 23:05:54 +0200 Subject: [PATCH 14/17] fix system theme Signed-off-by: Tayou --- launcher/Application.cpp | 4 ++-- launcher/ui/themes/SystemTheme.cpp | 30 +++++------------------------ launcher/ui/themes/SystemTheme.h | 3 +-- launcher/ui/themes/ThemeManager.cpp | 2 +- 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 6254e38fe..7ae66e13a 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1073,8 +1073,8 @@ bool Application::createSetupWizard() // set default theme after going into theme wizard if (!validIcons) settings()->set("IconTheme", QString("pe_colored")); - // if (!validWidgets) - // settings()->set("ApplicationTheme", QString("system")); + if (!validWidgets) + settings()->set("ApplicationTheme", QString("system")); m_themeManager->applyCurrentlySelectedTheme(true); diff --git a/launcher/ui/themes/SystemTheme.cpp b/launcher/ui/themes/SystemTheme.cpp index a46b2002a..70de21894 100644 --- a/launcher/ui/themes/SystemTheme.cpp +++ b/launcher/ui/themes/SystemTheme.cpp @@ -40,31 +40,9 @@ #include "HintOverrideProxyStyle.h" #include "ThemeManager.h" -SystemTheme::SystemTheme() +SystemTheme::SystemTheme(QString& styleName, bool isSystemTheme) { - themeName = QObject::tr("System"); - themeDebugLog() << "Determining System Theme..."; - const auto& style = QApplication::style(); - colorPalette = QApplication::palette(); - QString lowerThemeName = style->objectName(); - themeDebugLog() << "System theme seems to be:" << lowerThemeName; - QStringList styles = QStyleFactory::keys(); - for (auto& st : styles) { - themeDebugLog() << "Considering theme from theme factory:" << st.toLower(); - if (st.toLower() == lowerThemeName) { - widgetTheme = st; - themeDebugLog() << "System theme has been determined to be:" << widgetTheme; - return; - } - } - // fall back to fusion if we can't find the current theme. - widgetTheme = "Fusion"; - themeDebugLog() << "System theme not found, defaulted to Fusion"; -} - -SystemTheme::SystemTheme(QString& styleName) -{ - themeName = styleName; + themeName = isSystemTheme ? "system" : styleName; widgetTheme = styleName; colorPalette = QApplication::palette(); } @@ -94,6 +72,8 @@ QString SystemTheme::name() return QObject::tr("Windows 9x"); } else if (themeName.toLower() == "windows11") { return QObject::tr("Windows 11"); + } else if (themeName.toLower() == "system") { + return QObject::tr("System"); } else { return themeName; } @@ -110,7 +90,7 @@ QString SystemTheme::tooltip() } else if (themeName.toLower() == "fusion") { return QObject::tr("The default Qt widget style"); } else if (themeName.toLower() == "system") { - return QObject::tr("Your current system theme") + " (" + widgetTheme + ")"; + return QObject::tr("Your current system theme"); } else { return ""; } diff --git a/launcher/ui/themes/SystemTheme.h b/launcher/ui/themes/SystemTheme.h index bcfe34288..5c58856cb 100644 --- a/launcher/ui/themes/SystemTheme.h +++ b/launcher/ui/themes/SystemTheme.h @@ -38,8 +38,7 @@ class SystemTheme : public ITheme { public: - SystemTheme(); - explicit SystemTheme(QString& themeName); + SystemTheme(QString& themeName, bool isSystemTheme = false); virtual ~SystemTheme() {} void apply(bool initial) override; diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index ac2bf26dc..d57e166f4 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -127,7 +127,7 @@ void ThemeManager::initializeWidgets() themeDebugLog() << "System theme seems to be:" << currentlySelectedSystemTheme; themeDebugLog() << "<> Initializing Widget Themes"; - themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); + themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique(currentlySelectedSystemTheme, true)); auto darkThemeId = addTheme(std::make_unique()); themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); From e49e2622fc6ebd3f8061dc13b56a24493ce4019e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 7 Jul 2024 00:21:50 +0000 Subject: [PATCH 15/17] 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/2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8?narHash=sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw%3D' (2024-06-01) → 'github:hercules-ci/flake-parts/9227223f6d922fee3c7b190b2cc238a99527bbb7?narHash=sha256-pQMhCCHyQGRzdfAkdJ4cIWiw%2BJNuWsTX7f0ZYSyz0VY%3D' (2024-07-03) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/3f84a279f1a6290ce154c5531378acc827836fbb?narHash=sha256-u1fA0DYQYdeG%2B5kDm1bOoGcHtX0rtC7qs2YA2N1X%2B%2BI%3D' (2024-06-13) → 'github:NixOS/nixpkgs/9f4128e00b0ae8ec65918efeba59db998750ead6?narHash=sha256-rwz8NJZV%2B387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ%3D' (2024-07-03) • Updated input 'pre-commit-hooks': 'github:cachix/pre-commit-hooks.nix/cc4d466cb1254af050ff7bdf47f6d404a7c646d1?narHash=sha256-7XfBuLULizXjXfBYy/VV%2BSpYMHreNRHk9nKMsm1bgb4%3D' (2024-06-06) → 'github:cachix/pre-commit-hooks.nix/0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07?narHash=sha256-F1h%2BXIsGKT9TkGO3omxDLEb/9jOOsI6NnzsXFsZhry4%3D' (2024-06-24) --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index caed1a708..961cb2044 100644 --- a/flake.lock +++ b/flake.lock @@ -23,11 +23,11 @@ ] }, "locked": { - "lastModified": 1717285511, - "narHash": "sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw=", + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", "type": "github" }, "original": { @@ -75,11 +75,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1718276985, - "narHash": "sha256-u1fA0DYQYdeG+5kDm1bOoGcHtX0rtC7qs2YA2N1X++I=", + "lastModified": 1720031269, + "narHash": "sha256-rwz8NJZV+387rnWpTYcXaRNvzUSnnF9aHONoJIYmiUQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3f84a279f1a6290ce154c5531378acc827836fbb", + "rev": "9f4128e00b0ae8ec65918efeba59db998750ead6", "type": "github" }, "original": { @@ -103,11 +103,11 @@ ] }, "locked": { - "lastModified": 1717664902, - "narHash": "sha256-7XfBuLULizXjXfBYy/VV+SpYMHreNRHk9nKMsm1bgb4=", + "lastModified": 1719259945, + "narHash": "sha256-F1h+XIsGKT9TkGO3omxDLEb/9jOOsI6NnzsXFsZhry4=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "cc4d466cb1254af050ff7bdf47f6d404a7c646d1", + "rev": "0ff4381bbb8f7a52ca4a851660fc7a437a4c6e07", "type": "github" }, "original": { From fdcd1068f3e5d859e13eac56964b2eaeb4ac6485 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 8 Jul 2024 14:53:39 +0300 Subject: [PATCH 16/17] remove some poly mentions from the code Signed-off-by: Trial97 --- launcher/InstanceList.cpp | 12 ++++++------ launcher/InstanceList.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index 3f835cfaf..ab92a6c3c 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -372,13 +372,13 @@ void InstanceList::undoTrashInstance() auto top = m_trashHistory.pop(); - while (QDir(top.polyPath).exists()) { + while (QDir(top.path).exists()) { top.id += "1"; - top.polyPath += "1"; + top.path += "1"; } - qDebug() << "Moving" << top.trashPath << "back to" << top.polyPath; - QFile(top.trashPath).rename(top.polyPath); + qDebug() << "Moving" << top.trashPath << "back to" << top.path; + QFile(top.trashPath).rename(top.path); m_instanceGroupIndex[top.id] = top.groupName; increaseGroupCount(top.groupName); @@ -635,8 +635,8 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id) QString inst_type = instanceSettings->get("InstanceType").toString(); - // NOTE: Some PolyMC versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a OneSix - // instance + // NOTE: Some PrismMC versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a + // OneSix instance if (inst_type == "OneSix" || inst_type.isEmpty()) { inst.reset(new MinecraftInstance(m_globalSettings, instanceSettings, instanceRoot)); } else { diff --git a/launcher/InstanceList.h b/launcher/InstanceList.h index 5ddddee95..c85fe55c7 100644 --- a/launcher/InstanceList.h +++ b/launcher/InstanceList.h @@ -58,7 +58,7 @@ enum class GroupsState { NotLoaded, Steady, Dirty }; struct TrashHistoryItem { QString id; - QString polyPath; + QString path; QString trashPath; QString groupName; }; From aeb7f29a5b4a65cccd35d0ff65cfd7101124bb35 Mon Sep 17 00:00:00 2001 From: Alexandru Ionut Tripon Date: Mon, 8 Jul 2024 15:04:27 +0300 Subject: [PATCH 17/17] Update launcher/InstanceList.cpp Co-authored-by: Tayou Signed-off-by: Alexandru Ionut Tripon --- launcher/InstanceList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index ab92a6c3c..e1fa755dd 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -635,7 +635,7 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id) QString inst_type = instanceSettings->get("InstanceType").toString(); - // NOTE: Some PrismMC versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a + // NOTE: Some launcher versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a // OneSix instance if (inst_type == "OneSix" || inst_type.isEmpty()) { inst.reset(new MinecraftInstance(m_globalSettings, instanceSettings, instanceRoot));