From 20c393321c894adb4cb938a3f865f331c985cda9 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Thu, 1 Jul 2021 19:24:29 +0100 Subject: NOISSUE Use constants for user agents Here lies yet another early-stage move to debrand the MultiMC codebase, as well as reducing the burden of updating strings across the codebase for a future MultiMC6. --- api/logic/net/Download.cpp | 3 ++- api/logic/net/PasteUpload.cpp | 3 ++- api/logic/screenshots/ImgurAlbumCreation.cpp | 2 +- api/logic/screenshots/ImgurUpload.cpp | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'api') diff --git a/api/logic/net/Download.cpp b/api/logic/net/Download.cpp index 340f8657..3f183b7d 100644 --- a/api/logic/net/Download.cpp +++ b/api/logic/net/Download.cpp @@ -15,6 +15,7 @@ #include "Download.h" +#include "BuildConfig.h" #include #include #include @@ -94,7 +95,7 @@ void Download::start() return; } - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0"); + request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT); QNetworkReply *rep = ENV.qnam().get(request); diff --git a/api/logic/net/PasteUpload.cpp b/api/logic/net/PasteUpload.cpp index 3526e207..cb470c49 100644 --- a/api/logic/net/PasteUpload.cpp +++ b/api/logic/net/PasteUpload.cpp @@ -5,6 +5,7 @@ #include #include #include +#include PasteUpload::PasteUpload(QWidget *window, QString text, QString key) : m_window(window) { @@ -34,7 +35,7 @@ bool PasteUpload::validateText() void PasteUpload::executeTask() { QNetworkRequest request(QUrl("https://api.paste.ee/v1/pastes")); - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED); request.setRawHeader("Content-Type", "application/json"); request.setRawHeader("Content-Length", QByteArray::number(m_jsonContent.size())); diff --git a/api/logic/screenshots/ImgurAlbumCreation.cpp b/api/logic/screenshots/ImgurAlbumCreation.cpp index ff9ec6fd..07ae6fe1 100644 --- a/api/logic/screenshots/ImgurAlbumCreation.cpp +++ b/api/logic/screenshots/ImgurAlbumCreation.cpp @@ -20,7 +20,7 @@ void ImgurAlbumCreation::start() { m_status = Job_InProgress; QNetworkRequest request(m_url); - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); request.setRawHeader("Accept", "application/json"); diff --git a/api/logic/screenshots/ImgurUpload.cpp b/api/logic/screenshots/ImgurUpload.cpp index 1585b061..062c589f 100644 --- a/api/logic/screenshots/ImgurUpload.cpp +++ b/api/logic/screenshots/ImgurUpload.cpp @@ -23,7 +23,7 @@ void ImgurUpload::start() finished = false; m_status = Job_InProgress; QNetworkRequest request(m_url); - request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)"); + request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED); request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); request.setRawHeader("Accept", "application/json"); -- cgit From 4401b9e137a92effb566a82cbe4b904b545f0cdf Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Thu, 1 Jul 2021 19:49:38 +0100 Subject: NOISSUE Specify Imgur client ID at build time --- CMakeLists.txt | 3 +++ api/logic/screenshots/ImgurAlbumCreation.cpp | 2 +- api/logic/screenshots/ImgurUpload.cpp | 2 +- buildconfig/BuildConfig.cpp.in | 1 + buildconfig/BuildConfig.h | 5 +++++ 5 files changed, 11 insertions(+), 2 deletions(-) (limited to 'api') diff --git a/CMakeLists.txt b/CMakeLists.txt index bcf931c0..5e3d6cea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,9 @@ set(MultiMC_META_URL "https://meta.multimc.org/v1/" CACHE STRING "URL to fetch M # paste.ee API key set(MultiMC_PASTE_EE_API_KEY "utLvciUouSURFzfjPxLBf5W4ISsUX4pwBDF7N1AfZ" CACHE STRING "API key you can get from paste.ee when you register an account") +# Imgur API Client ID +set(MultiMC_IMGUR_CLIENT_ID "5b97b0713fba4a3" CACHE STRING "Client ID you can get from Imgur when you register an application") + # Google analytics ID set(MultiMC_ANALYTICS_ID "UA-87731965-2" CACHE STRING "ID you can get from Google analytics") diff --git a/api/logic/screenshots/ImgurAlbumCreation.cpp b/api/logic/screenshots/ImgurAlbumCreation.cpp index 07ae6fe1..1f195f00 100644 --- a/api/logic/screenshots/ImgurAlbumCreation.cpp +++ b/api/logic/screenshots/ImgurAlbumCreation.cpp @@ -22,7 +22,7 @@ void ImgurAlbumCreation::start() QNetworkRequest request(m_url); request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); - request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); + request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str()); request.setRawHeader("Accept", "application/json"); QStringList hashes; diff --git a/api/logic/screenshots/ImgurUpload.cpp b/api/logic/screenshots/ImgurUpload.cpp index 062c589f..7e95d5ca 100644 --- a/api/logic/screenshots/ImgurUpload.cpp +++ b/api/logic/screenshots/ImgurUpload.cpp @@ -24,7 +24,7 @@ void ImgurUpload::start() m_status = Job_InProgress; QNetworkRequest request(m_url); request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED); - request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3"); + request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str()); request.setRawHeader("Accept", "application/json"); QFile f(m_shot->m_file.absoluteFilePath()); diff --git a/buildconfig/BuildConfig.cpp.in b/buildconfig/BuildConfig.cpp.in index 577bdcb2..60d417a6 100644 --- a/buildconfig/BuildConfig.cpp.in +++ b/buildconfig/BuildConfig.cpp.in @@ -33,6 +33,7 @@ Config::Config() VERSION_STR = "@MultiMC_VERSION_STRING@"; NEWS_RSS_URL = "@MultiMC_NEWS_RSS_URL@"; PASTE_EE_KEY = "@MultiMC_PASTE_EE_API_KEY@"; + IMGUR_CLIENT_ID = "@MultiMC_IMGUR_CLIENT_ID@"; META_URL = "@MultiMC_META_URL@"; BUG_TRACKER_URL = "@MultiMC_BUG_TRACKER_URL@"; diff --git a/buildconfig/BuildConfig.h b/buildconfig/BuildConfig.h index 07d7a23a..185bebad 100644 --- a/buildconfig/BuildConfig.h +++ b/buildconfig/BuildConfig.h @@ -65,6 +65,11 @@ public: */ QString PASTE_EE_KEY; + /** + * Client ID you can get from Imgur when you register an application + */ + QString IMGUR_CLIENT_ID; + /** * MultiMC Metadata repository URL prefix */ -- cgit From 74f5255eef8b14455ca741c5004a97cd00fed667 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Tue, 13 Jul 2021 16:59:33 +0100 Subject: GH-3930 Track duration of previous game sessions --- api/logic/BaseInstance.cpp | 17 ++++++++++++++++- api/logic/BaseInstance.h | 1 + api/logic/minecraft/MinecraftInstance.cpp | 10 ++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) (limited to 'api') diff --git a/api/logic/BaseInstance.cpp b/api/logic/BaseInstance.cpp index cff16631..46b45827 100644 --- a/api/logic/BaseInstance.cpp +++ b/api/logic/BaseInstance.cpp @@ -37,6 +37,7 @@ BaseInstance::BaseInstance(SettingsObjectPtr globalSettings, SettingsObjectPtr s m_settings->registerSetting("notes", ""); m_settings->registerSetting("lastLaunchTime", 0); m_settings->registerSetting("totalTimePlayed", 0); + m_settings->registerSetting("lastTimePlayed", 0); // Custom Commands auto commandSetting = m_settings->registerSetting({"OverrideCommands","OverrideLaunchCmd"}, false); @@ -146,9 +147,12 @@ void BaseInstance::setRunning(bool running) } else { - qint64 current = settings()->get("totalTimePlayed").toLongLong(); QDateTime timeEnded = QDateTime::currentDateTime(); + + qint64 current = settings()->get("totalTimePlayed").toLongLong(); settings()->set("totalTimePlayed", current + m_timeStarted.secsTo(timeEnded)); + settings()->set("lastTimePlayed", m_timeStarted.secsTo(timeEnded)); + emit propertiesChanged(this); } @@ -166,9 +170,20 @@ int64_t BaseInstance::totalTimePlayed() const return current; } +int64_t BaseInstance::lastTimePlayed() const +{ + if(m_isRunning) + { + QDateTime timeNow = QDateTime::currentDateTime(); + return m_timeStarted.secsTo(timeNow); + } + return settings()->get("lastTimePlayed").toLongLong(); +} + void BaseInstance::resetTimePlayed() { settings()->reset("totalTimePlayed"); + settings()->reset("lastTimePlayed"); } QString BaseInstance::instanceType() const diff --git a/api/logic/BaseInstance.h b/api/logic/BaseInstance.h index 64de4bb3..d250e03e 100644 --- a/api/logic/BaseInstance.h +++ b/api/logic/BaseInstance.h @@ -87,6 +87,7 @@ public: void setRunning(bool running); bool isRunning() const; int64_t totalTimePlayed() const; + int64_t lastTimePlayed() const; void resetTimePlayed(); /// get the type of this instance diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp index ea1e47b6..dbf9f816 100644 --- a/api/logic/minecraft/MinecraftInstance.cpp +++ b/api/logic/minecraft/MinecraftInstance.cpp @@ -798,9 +798,15 @@ QString MinecraftInstance::getStatusbarDescription() QString description; description.append(tr("Minecraft %1 (%2)").arg(m_components->getComponentVersion("net.minecraft")).arg(typeName())); - if(m_settings->get("ShowGameTime").toBool() && totalTimePlayed() > 0) + if(m_settings->get("ShowGameTime").toBool()) { - description.append(tr(", played for %1").arg(prettifyTimeDuration(totalTimePlayed()))); + if (lastTimePlayed() > 0) { + description.append(tr(", last played for %1").arg(prettifyTimeDuration(lastTimePlayed()))); + } + + if (totalTimePlayed() > 0) { + description.append(tr(", total played for %1").arg(prettifyTimeDuration(totalTimePlayed()))); + } } if(hasCrashed()) { -- cgit