Merge pull request #708 from ryanccn/custom-user-agent
This commit is contained in:
commit
2257c875f5
@ -711,6 +711,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
|
|||||||
// Custom MSA credentials
|
// Custom MSA credentials
|
||||||
m_settings->registerSetting("MSAClientIDOverride", "");
|
m_settings->registerSetting("MSAClientIDOverride", "");
|
||||||
m_settings->registerSetting("CFKeyOverride", "");
|
m_settings->registerSetting("CFKeyOverride", "");
|
||||||
|
m_settings->registerSetting("UserAgentOverride", "");
|
||||||
|
|
||||||
// Init page provider
|
// Init page provider
|
||||||
{
|
{
|
||||||
@ -1556,3 +1557,24 @@ QString Application::getCurseKey()
|
|||||||
|
|
||||||
return BuildConfig.CURSEFORGE_API_KEY;
|
return BuildConfig.CURSEFORGE_API_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Application::getUserAgent()
|
||||||
|
{
|
||||||
|
QString uaOverride = m_settings->get("UserAgentOverride").toString();
|
||||||
|
if (!uaOverride.isEmpty()) {
|
||||||
|
return uaOverride.replace("$LAUNCHER_VER", BuildConfig.printableVersionString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return BuildConfig.USER_AGENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Application::getUserAgentUncached()
|
||||||
|
{
|
||||||
|
QString uaOverride = m_settings->get("UserAgentOverride").toString();
|
||||||
|
if (!uaOverride.isEmpty()) {
|
||||||
|
uaOverride += " (Uncached)";
|
||||||
|
return uaOverride.replace("$LAUNCHER_VER", BuildConfig.printableVersionString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return BuildConfig.USER_AGENT_UNCACHED;
|
||||||
|
}
|
||||||
|
@ -156,6 +156,8 @@ public:
|
|||||||
|
|
||||||
QString getMSAClientID();
|
QString getMSAClientID();
|
||||||
QString getCurseKey();
|
QString getCurseKey();
|
||||||
|
QString getUserAgent();
|
||||||
|
QString getUserAgentUncached();
|
||||||
|
|
||||||
/// this is the root of the 'installation'. Used for automatic updates
|
/// this is the root of the 'installation'. Used for automatic updates
|
||||||
const QString &root() {
|
const QString &root() {
|
||||||
|
@ -116,7 +116,7 @@ void Download::executeTask()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
|
||||||
if (request.url().host().contains("api.curseforge.com")) {
|
if (request.url().host().contains("api.curseforge.com")) {
|
||||||
request.setRawHeader("x-api-key", APPLICATION->getCurseKey().toUtf8());
|
request.setRawHeader("x-api-key", APPLICATION->getCurseKey().toUtf8());
|
||||||
};
|
};
|
||||||
|
@ -71,7 +71,7 @@ void PasteUpload::executeTask()
|
|||||||
QNetworkRequest request{QUrl(m_uploadUrl)};
|
QNetworkRequest request{QUrl(m_uploadUrl)};
|
||||||
QNetworkReply *rep{};
|
QNetworkReply *rep{};
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgentUncached().toUtf8());
|
||||||
|
|
||||||
switch (m_pasteType) {
|
switch (m_pasteType) {
|
||||||
case NullPointer: {
|
case NullPointer: {
|
||||||
@ -91,7 +91,7 @@ void PasteUpload::executeTask()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Hastebin: {
|
case Hastebin: {
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgentUncached().toUtf8());
|
||||||
rep = APPLICATION->network()->post(request, m_text);
|
rep = APPLICATION->network()->post(request, m_text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ namespace Net {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
|
||||||
if (request.url().host().contains("api.curseforge.com")) {
|
if (request.url().host().contains("api.curseforge.com")) {
|
||||||
request.setRawHeader("x-api-key", APPLICATION->getCurseKey().toUtf8());
|
request.setRawHeader("x-api-key", APPLICATION->getCurseKey().toUtf8());
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ void ImgurAlbumCreation::executeTask()
|
|||||||
{
|
{
|
||||||
m_state = State::Running;
|
m_state = State::Running;
|
||||||
QNetworkRequest request(m_url);
|
QNetworkRequest request(m_url);
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgentUncached().toUtf8());
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str());
|
request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str());
|
||||||
request.setRawHeader("Accept", "application/json");
|
request.setRawHeader("Accept", "application/json");
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include "ImgurUpload.h"
|
#include "ImgurUpload.h"
|
||||||
#include "BuildConfig.h"
|
#include "BuildConfig.h"
|
||||||
|
#include "Application.h"
|
||||||
|
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QHttpMultiPart>
|
#include <QHttpMultiPart>
|
||||||
@ -56,7 +57,7 @@ void ImgurUpload::executeTask()
|
|||||||
finished = false;
|
finished = false;
|
||||||
m_state = Task::State::Running;
|
m_state = Task::State::Running;
|
||||||
QNetworkRequest request(m_url);
|
QNetworkRequest request(m_url);
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, BuildConfig.USER_AGENT_UNCACHED);
|
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgentUncached().toUtf8());
|
||||||
request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str());
|
request.setRawHeader("Authorization", QString("Client-ID %1").arg(BuildConfig.IMGUR_CLIENT_ID).toStdString().c_str());
|
||||||
request.setRawHeader("Accept", "application/json");
|
request.setRawHeader("Accept", "application/json");
|
||||||
|
|
||||||
|
@ -75,9 +75,9 @@ APIPage::APIPage(QWidget *parent) :
|
|||||||
// This function needs to be called even when the ComboBox's index is still in its default state.
|
// This function needs to be called even when the ComboBox's index is still in its default state.
|
||||||
updateBaseURLPlaceholder(ui->pasteTypeComboBox->currentIndex());
|
updateBaseURLPlaceholder(ui->pasteTypeComboBox->currentIndex());
|
||||||
ui->baseURLEntry->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->baseURLEntry));
|
ui->baseURLEntry->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->baseURLEntry));
|
||||||
ui->tabWidget->tabBar()->hide();
|
|
||||||
|
|
||||||
ui->metaURL->setPlaceholderText(BuildConfig.META_URL);
|
ui->metaURL->setPlaceholderText(BuildConfig.META_URL);
|
||||||
|
ui->userAgentLineEdit->setPlaceholderText(BuildConfig.USER_AGENT);
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
@ -139,6 +139,8 @@ void APIPage::loadSettings()
|
|||||||
ui->metaURL->setText(metaURL);
|
ui->metaURL->setText(metaURL);
|
||||||
QString curseKey = s->get("CFKeyOverride").toString();
|
QString curseKey = s->get("CFKeyOverride").toString();
|
||||||
ui->curseKey->setText(curseKey);
|
ui->curseKey->setText(curseKey);
|
||||||
|
QString customUserAgent = s->get("UserAgentOverride").toString();
|
||||||
|
ui->userAgentLineEdit->setText(customUserAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIPage::applySettings()
|
void APIPage::applySettings()
|
||||||
@ -167,6 +169,7 @@ void APIPage::applySettings()
|
|||||||
s->set("MetaURLOverride", metaURL);
|
s->set("MetaURLOverride", metaURL);
|
||||||
QString curseKey = ui->curseKey->text();
|
QString curseKey = ui->curseKey->text();
|
||||||
s->set("CFKeyOverride", curseKey);
|
s->set("CFKeyOverride", curseKey);
|
||||||
|
s->set("UserAgentOverride", ui->userAgentLineEdit->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool APIPage::apply()
|
bool APIPage::apply()
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab">
|
<widget class="QWidget" name="tab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string notr="true">Tab 1</string>
|
<string notr="true">Services</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
@ -85,51 +85,6 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QGroupBox" name="groupBox_msa">
|
|
||||||
<property name="title">
|
|
||||||
<string>&Microsoft Authentication</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="text">
|
|
||||||
<string>Note: you probably don't need to set this if logging in via Microsoft Authentication already works.</string>
|
|
||||||
</property>
|
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::RichText</enum>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="msaClientID">
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>(Default)</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_4">
|
|
||||||
<property name="text">
|
|
||||||
<string>Enter a custom client ID for Microsoft Authentication here. </string>
|
|
||||||
</property>
|
|
||||||
<property name="textFormat">
|
|
||||||
<enum>Qt::RichText</enum>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="openExternalLinks">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_meta">
|
<widget class="QGroupBox" name="groupBox_meta">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
@ -175,6 +130,71 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_2">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>API Keys</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_msa">
|
||||||
|
<property name="title">
|
||||||
|
<string>&Microsoft Authentication</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Note: you probably don't need to set this if logging in via Microsoft Authentication already works.</string>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::RichText</enum>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="msaClientID">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>(Default)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enter a custom client ID for Microsoft Authentication here. </string>
|
||||||
|
</property>
|
||||||
|
<property name="textFormat">
|
||||||
|
<enum>Qt::RichText</enum>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="openExternalLinks">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_curse">
|
<widget class="QGroupBox" name="groupBox_curse">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
@ -183,25 +203,15 @@
|
|||||||
<property name="title">
|
<property name="title">
|
||||||
<string>&CurseForge Core API</string>
|
<string>&CurseForge Core API</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item>
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_8">
|
<widget class="QLabel" name="label_8">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Note: you probably don't need to set this if CurseForge already works.</string>
|
<string>Note: you probably don't need to set this if CurseForge already works.</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="2" column="0">
|
||||||
<widget class="QLineEdit" name="curseKey">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>(Default)</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_7">
|
<widget class="QLabel" name="label_7">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Enter a custom API Key for CurseForge here. </string>
|
<string>Enter a custom API Key for CurseForge here. </string>
|
||||||
@ -217,6 +227,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLineEdit" name="curseKey">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>(Default)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -235,6 +255,51 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_3">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Miscellaneous</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_ua">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="title">
|
||||||
|
<string>User Agent</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="userAgentLineEdit"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="userAgentLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enter a custom User Agent here. The special string $LAUNCHER_VER will be replaced with the version of the launcher.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
Loading…
Reference in New Issue
Block a user