Skip to content

Commit

Permalink
Implement error reporting prompt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Nov 29, 2024
1 parent ec036e7 commit c4c8f0b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

#include <iostream>
#include <QDir>
#include <QMessageBox>
#include "Common/Cpp/PrettyPrint.h"
#include "Common/Cpp/Json/JsonArray.h"
#include "Common/Cpp/Json/JsonObject.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Logging/Logger.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
#include "ProgramDumper.h"
#include "ErrorReports.h"

Expand All @@ -33,10 +35,22 @@ const std::string& ERROR_PATH_SENT = "ErrorReportsSent";


ErrorReportOption::ErrorReportOption()
: GroupOption("Error Reports", LockMode::UNLOCK_WHILE_RUNNING, true)
: GroupOption("Error Reports", LockMode::UNLOCK_WHILE_RUNNING, false)
, DESCRIPTION(
"Send error reports to the " + PROGRAM_NAME + " server to help them resolve issues and improve the program."
)
, SEND_MODE(
"<b>When to Send Error Reports:</b>",
{
{ErrorReportSendMode::SEND_AUTOMATICALLY, "automatic", "Send automatically."},
{ErrorReportSendMode::PROMPT_WHEN_CONVENIENT, "prompt", "Prompt when convenient."},
{ErrorReportSendMode::NEVER_SEND_ANYTHING, "never", "Never send error reports."},
},
LockMode::UNLOCK_WHILE_RUNNING,
IS_BETA_VERSION
? ErrorReportSendMode::SEND_AUTOMATICALLY
: ErrorReportSendMode::PROMPT_WHEN_CONVENIENT
)
, SCREENSHOT(
"<b>Include Screenshots:</b>",
LockMode::UNLOCK_WHILE_RUNNING,
Expand All @@ -48,7 +62,7 @@ ErrorReportOption::ErrorReportOption()
true
)
, DUMPS(
"<b>Include Dumps:</b><br>This saves stack-trace and related information.",
"<b>Include Dumps:</b><br>Include stack-trace and related information.",
LockMode::UNLOCK_WHILE_RUNNING,
true
)
Expand All @@ -61,6 +75,7 @@ ErrorReportOption::ErrorReportOption()
#endif
{
PA_ADD_STATIC(DESCRIPTION);
PA_ADD_OPTION(SEND_MODE);
PA_ADD_OPTION(SCREENSHOT);
PA_ADD_OPTION(LOGS);
PA_ADD_OPTION(DUMPS);
Expand Down Expand Up @@ -233,7 +248,10 @@ std::vector<std::string> SendableErrorReport::get_pending_reports(){
}
return ret;
}
void SendableErrorReport::send_reports(Logger& logger, const std::vector<std::string>& reports){



void send_reports(Logger& logger, const std::vector<std::string>& reports){
for (const std::string& path : reports){
try{
SendableErrorReport report(path);
Expand All @@ -245,13 +263,50 @@ void SendableErrorReport::send_reports(Logger& logger, const std::vector<std::st
}
}
}
void SendableErrorReport::send_all_unsent_reports(Logger& logger){
void send_all_unsent_reports(Logger& logger, bool allow_prompt){
#ifdef PA_OFFICIAL
if (GlobalSettings::instance().ERROR_REPORTS.enabled()){
std::vector<std::string> reports = SendableErrorReport::get_pending_reports();
global_logger_tagged().log("Found " + std::to_string(reports.size()) + " unsent error reports. Attempting to send...", COLOR_PURPLE);
SendableErrorReport::send_reports(global_logger_tagged(), reports);
ErrorReportSendMode mode = GlobalSettings::instance().ERROR_REPORTS.SEND_MODE;
if (mode == ErrorReportSendMode::NEVER_SEND_ANYTHING){
return;
}

std::vector<std::string> reports = SendableErrorReport::get_pending_reports();
global_logger_tagged().log("Found " + std::to_string(reports.size()) + " unsent error reports.", COLOR_PURPLE);

if (reports.empty()){
return;
}

if (mode == ErrorReportSendMode::PROMPT_WHEN_CONVENIENT){
if (!allow_prompt){
return;
}
QMessageBox box;
QMessageBox::StandardButton button = box.information(
nullptr,
"Error Reporting",
QString::fromStdString(
(reports.size() == 1
? "There is " + tostr_u_commas(reports.size()) + " error report.<br><br>"
"Would you like to help make this program better by sending it to the developers?<br><br>"
: "There are " + tostr_u_commas(reports.size()) + " error reports.<br><br>"
"Would you like to help make this program better by sending them to the developers?<br><br>"
) +
make_text_url(ERROR_PATH_UNSENT, "View unsent error reports.")// + "<br><br>"
// "(You can change )"
),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::StandardButton::Yes
);
if (button != QMessageBox::StandardButton::Yes){
return;
}
// cout << "asdfasdf" << button_yes << " : " << button_no << " : " << &button << endl; // REMOVE
}

global_logger_tagged().log("Attempting to send " + std::to_string(reports.size()) + " error reports.", COLOR_PURPLE);
send_reports(global_logger_tagged(), reports);

#endif
}

Expand Down Expand Up @@ -284,7 +339,7 @@ void report_error(
report.save(logger);
}

SendableErrorReport::send_all_unsent_reports(*logger);
send_all_unsent_reports(*logger, false);
}


Expand Down
19 changes: 17 additions & 2 deletions SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Common/Cpp/Options/GroupOption.h"
#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/EnumDropdownOption.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/Notifications/ProgramInfo.h"
Expand All @@ -24,12 +25,20 @@ extern const std::string& ERROR_PATH_UNSENT;
extern const std::string& ERROR_PATH_SENT;


enum class ErrorReportSendMode{
SEND_AUTOMATICALLY,
PROMPT_WHEN_CONVENIENT,
NEVER_SEND_ANYTHING,
};

class ErrorReportOption : public GroupOption{
public:
ErrorReportOption();

StaticTextOption DESCRIPTION;

EnumDropdownOption<ErrorReportSendMode> SEND_MODE;

BooleanCheckBoxOption SCREENSHOT;
BooleanCheckBoxOption LOGS;
BooleanCheckBoxOption DUMPS;
Expand Down Expand Up @@ -65,8 +74,6 @@ class SendableErrorReport{
void move_to_sent();

static std::vector<std::string> get_pending_reports();
static void send_reports(Logger& logger, const std::vector<std::string>& reports);
static void send_all_unsent_reports(Logger& logger);

private:
std::string m_timestamp;
Expand All @@ -82,6 +89,9 @@ class SendableErrorReport{
};


void send_reports(Logger& logger, const std::vector<std::string>& reports);
void send_all_unsent_reports(Logger& logger, bool allow_prompt);


void report_error(
Logger* logger = nullptr,
Expand All @@ -93,6 +103,11 @@ void report_error(
);







}

#endif
2 changes: 1 addition & 1 deletion SerialPrograms/Source/CommonFramework/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace PokemonAutomation{
const bool IS_BETA_VERSION = true;
const int PROGRAM_VERSION_MAJOR = 0;
const int PROGRAM_VERSION_MINOR = 50;
const int PROGRAM_VERSION_PATCH = 6;
const int PROGRAM_VERSION_PATCH = 7;

const std::string PROGRAM_VERSION_BASE =
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +
Expand Down
2 changes: 1 addition & 1 deletion SerialPrograms/Source/CommonFramework/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int main(int argc, char *argv[]){
}

set_working_directory();
SendableErrorReport::send_all_unsent_reports(global_logger_tagged());
send_all_unsent_reports(global_logger_tagged(), true);

int ret = 0;
{
Expand Down

0 comments on commit c4c8f0b

Please sign in to comment.