Skip to content

Commit

Permalink
update user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Oct 14, 2023
1 parent 2cd04de commit 05bf2b6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion main/HTTPRequestHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace NekoGui_network {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
#endif
request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoGui::dataStore->user_agent);
request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoGui::dataStore->GetUserAgent());
if (NekoGui::dataStore->sub_insecure) {
QSslConfiguration c;
c.setPeerVerifyMode(QSslSocket::PeerVerifyMode::VerifyNone);
Expand Down
18 changes: 17 additions & 1 deletion main/NekoGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace NekoGui {
_add(new configItem("extraCore", dynamic_cast<JsonStore *>(extraCore), itemType::jsonStore));
_add(new configItem("inbound_auth", dynamic_cast<JsonStore *>(inbound_auth), itemType::jsonStore));

_add(new configItem("user_agent", &user_agent, itemType::string));
_add(new configItem("user_agent2", &user_agent, itemType::string));
_add(new configItem("test_url", &test_latency_url, itemType::string));
_add(new configItem("test_url_dl", &test_download_url, itemType::string));
_add(new configItem("test_dl_timeout", &test_download_timeout, itemType::integer));
Expand Down Expand Up @@ -304,6 +304,22 @@ namespace NekoGui {
}
}

QString DataStore::GetUserAgent(bool isDefault) const {
if (user_agent.isEmpty()) {
isDefault = true;
}
if (isDefault) {
QString version = SubStrBefore(NKR_VERSION, "-");
if (!version.contains(".")) version = "2.0";
if (IS_NEKO_BOX) {
return "NekoBox/PC/" + version + " (Prefer ClashMeta Format)";
} else {
return "NekoRay/PC/" + version + " (Prefer ClashMeta Format)";
}
}
return user_agent;
}

// preset routing
Routing::Routing(int preset) : JsonStore() {
if (preset == 1) {
Expand Down
2 changes: 2 additions & 0 deletions main/NekoGui_DataStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ namespace NekoGui {
DataStore();

void UpdateStartedId(int id);

QString GetUserAgent(bool isDefault = false) const;
};

extern DataStore *dataStore;
Expand Down
10 changes: 0 additions & 10 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,6 @@ int main(int argc, char* argv[]) {
MW_dialog_message("", "Raise");
});

// Do preset update
if (NekoGui::dataStore->user_agent.isEmpty() || NekoGui::dataStore->user_agent.startsWith("Nekoray/1.0") || NekoGui::dataStore->user_agent.startsWith("ClashForAndroid")) {
if (IS_NEKO_BOX) {
NekoGui::dataStore->user_agent = "NekoBox/PC/2.0 (Prefer ClashMeta Format)";
} else {
NekoGui::dataStore->user_agent = "NekoRay/PC/2.0 (Prefer ClashMeta Format)";
}
NekoGui::dataStore->Save();
}

UI_InitMainWindow();
return QApplication::exec();
}
1 change: 1 addition & 0 deletions ui/dialog_basic_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
// Subscription

ui->user_agent->setText(NekoGui::dataStore->user_agent);
ui->user_agent->setPlaceholderText(NekoGui::dataStore->GetUserAgent(true));
D_LOAD_BOOL(sub_use_proxy)
D_LOAD_BOOL(sub_clear)
D_LOAD_BOOL(sub_insecure)
Expand Down

0 comments on commit 05bf2b6

Please sign in to comment.