diff --git a/SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp b/SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp index e52397d02..bde8e1137 100644 --- a/SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp +++ b/SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp @@ -6,6 +6,7 @@ #include #include +#include #include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/Json/JsonArray.h" #include "Common/Cpp/Json/JsonObject.h" @@ -13,6 +14,7 @@ #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" @@ -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( + "When to Send Error Reports:", + { + {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( "Include Screenshots:", LockMode::UNLOCK_WHILE_RUNNING, @@ -48,7 +62,7 @@ ErrorReportOption::ErrorReportOption() true ) , DUMPS( - "Include Dumps:
This saves stack-trace and related information.", + "Include Dumps:
Include stack-trace and related information.", LockMode::UNLOCK_WHILE_RUNNING, true ) @@ -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); @@ -233,7 +248,10 @@ std::vector SendableErrorReport::get_pending_reports(){ } return ret; } -void SendableErrorReport::send_reports(Logger& logger, const std::vector& reports){ + + + +void send_reports(Logger& logger, const std::vector& reports){ for (const std::string& path : reports){ try{ SendableErrorReport report(path); @@ -245,13 +263,50 @@ void SendableErrorReport::send_reports(Logger& logger, const std::vector 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 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.

" + "Would you like to help make this program better by sending it to the developers?

" + : "There are " + tostr_u_commas(reports.size()) + " error reports.

" + "Would you like to help make this program better by sending them to the developers?

" + ) + + make_text_url(ERROR_PATH_UNSENT, "View unsent error reports.")// + "

" +// "(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 } @@ -284,7 +339,7 @@ void report_error( report.save(logger); } - SendableErrorReport::send_all_unsent_reports(*logger); + send_all_unsent_reports(*logger, false); } diff --git a/SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.h b/SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.h index 136024bf0..f8c895f4d 100644 --- a/SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.h +++ b/SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.h @@ -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" @@ -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 SEND_MODE; + BooleanCheckBoxOption SCREENSHOT; BooleanCheckBoxOption LOGS; BooleanCheckBoxOption DUMPS; @@ -65,8 +74,6 @@ class SendableErrorReport{ void move_to_sent(); static std::vector get_pending_reports(); - static void send_reports(Logger& logger, const std::vector& reports); - static void send_all_unsent_reports(Logger& logger); private: std::string m_timestamp; @@ -82,6 +89,9 @@ class SendableErrorReport{ }; +void send_reports(Logger& logger, const std::vector& reports); +void send_all_unsent_reports(Logger& logger, bool allow_prompt); + void report_error( Logger* logger = nullptr, @@ -93,6 +103,11 @@ void report_error( ); + + + + + } #endif diff --git a/SerialPrograms/Source/CommonFramework/Globals.cpp b/SerialPrograms/Source/CommonFramework/Globals.cpp index ed60f18f2..e1a0a2f88 100644 --- a/SerialPrograms/Source/CommonFramework/Globals.cpp +++ b/SerialPrograms/Source/CommonFramework/Globals.cpp @@ -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) + diff --git a/SerialPrograms/Source/CommonFramework/Main.cpp b/SerialPrograms/Source/CommonFramework/Main.cpp index 1987bc3e8..00a6efb55 100644 --- a/SerialPrograms/Source/CommonFramework/Main.cpp +++ b/SerialPrograms/Source/CommonFramework/Main.cpp @@ -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; {