Show feedback when the compatibility is submitted.

This commit is contained in:
Unknown W. Brackets 2016-06-27 22:59:09 -07:00
parent 45218be5e3
commit 42fd4aeb12
4 changed files with 73 additions and 6 deletions

View File

@ -62,6 +62,8 @@ namespace Reporting
static bool everUnsupported = false;
// Support is cached here to avoid checking it on every single request.
static bool currentSupported = false;
// Whether the most recent server request seemed successful.
static bool serverWorking = true;
enum class RequestType
{
@ -227,9 +229,10 @@ namespace Reporting
if (http.Resolve(serverHost, ServerPort())) {
http.Connect();
http.POST(uri, data, mimeType, output);
int result = http.POST(uri, data, mimeType, output);
http.Disconnect();
return true;
return result >= 200 && result < 300;
} else {
return false;
}
@ -392,6 +395,7 @@ namespace Reporting
setCurrentThreadName("Report");
Payload &payload = payloadBuffer[pos];
Buffer output;
MultipartFormDataEncoder postdata;
AddSystemInfo(postdata);
@ -411,7 +415,8 @@ namespace Reporting
payload.string2.clear();
postdata.Finish();
SendReportRequest("/report/message", postdata.ToString(), postdata.GetMimeType());
if (!SendReportRequest("/report/message", postdata.ToString(), postdata.GetMimeType()))
serverWorking = false;
break;
case RequestType::COMPAT:
@ -427,7 +432,16 @@ namespace Reporting
payload.string2.clear();
postdata.Finish();
SendReportRequest("/report/compat", postdata.ToString(), postdata.GetMimeType());
if (!SendReportRequest("/report/compat", postdata.ToString(), postdata.GetMimeType(), &output)) {
serverWorking = false;
} else {
char res = 0;
if (!output.empty()) {
output.Take(1, &res);
}
if (res == 0)
serverWorking = false;
}
break;
case RequestType::NONE:
@ -496,6 +510,20 @@ namespace Reporting
g_Config.sReportHost = "default";
}
Status GetStatus()
{
if (!serverWorking)
return Status::FAILING;
for (int pos = 0; pos < PAYLOAD_BUFFER_SIZE; ++pos)
{
if (payloadBuffer[pos].type != RequestType::NONE)
return Status::BUSY;
}
return Status::WORKING;
}
int NextFreePos()
{
int start = payloadBufferPos % PAYLOAD_BUFFER_SIZE;

View File

@ -15,6 +15,8 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#pragma once
#include "Common/CommonTypes.h"
#include "Common/Log.h"
#include <string>
@ -75,6 +77,15 @@ namespace Reporting
// Returns true if that identifier has not been logged yet.
bool ShouldLogOnce(const char *identifier);
enum class Status {
WORKING,
BUSY,
FAILING,
};
// Whether server requests appear to be working.
Status GetStatus();
// Return the currently active host (or blank if not active.)
std::string ServerHost();

View File

@ -294,7 +294,7 @@ EventReturn ReportScreen::HandleBrowser(EventParams &e) {
}
ReportFinishScreen::ReportFinishScreen(const std::string &gamePath)
: UIScreenWithGameBackground(gamePath) {
: UIScreenWithGameBackground(gamePath), resultNotice_(nullptr), setStatus_(false) {
}
void ReportFinishScreen::CreateViews() {
@ -309,7 +309,7 @@ void ReportFinishScreen::CreateViews() {
LinearLayout *rightColumnItems = new LinearLayout(ORIENT_VERTICAL);
leftColumnItems->Add(new TextView(rp->T("FeedbackThanks", "Thanks for your feedback."), new LinearLayoutParams(Margins(12, 5, 0, 5))));
leftColumnItems->Add(new TextView(rp->T("FeedbackDelayInfo", "Your data is being submitted in the background."), new LinearLayoutParams(Margins(12, 5, 0, 5))));
resultNotice_ = leftColumnItems->Add(new TextView(rp->T("FeedbackDelayInfo", "Your data is being submitted in the background."), new LinearLayoutParams(Margins(12, 5, 0, 5))));
rightColumnItems->SetSpacing(0.0f);
rightColumnItems->Add(new Choice(rp->T("View Feedback")))->OnClick.Handle(this, &ReportFinishScreen::HandleViewFeedback);
@ -325,6 +325,30 @@ void ReportFinishScreen::CreateViews() {
rightColumn->Add(rightColumnItems);
}
void ReportFinishScreen::update(InputState &input) {
I18NCategory *rp = GetI18NCategory("Reporting");
if (!setStatus_) {
Reporting::Status status = Reporting::GetStatus();
switch (status) {
case Reporting::Status::WORKING:
resultNotice_->SetText(rp->T("FeedbackSubmitDone", "Your data has been submitted."));
break;
case Reporting::Status::FAILING:
resultNotice_->SetText(rp->T("FeedbackSubmitFail", "Could not submit data to server. Try updating PPSSPP."));
break;
case Reporting::Status::BUSY:
default:
// Can't update yet.
break;
}
}
UIScreenWithGameBackground::update(input);
}
UI::EventReturn ReportFinishScreen::HandleViewFeedback(UI::EventParams &e) {
const std::string url = "http://" + Reporting::ServerHost() + "/game/" + Reporting::CurrentGameID();
LaunchBrowser(url.c_str());

View File

@ -55,7 +55,11 @@ public:
ReportFinishScreen(const std::string &gamePath);
protected:
void update(InputState &input) override;
void CreateViews() override;
UI::EventReturn HandleViewFeedback(UI::EventParams &e);
UI::TextView *resultNotice_;
bool setStatus_;
};