66
77#include < iostream>
88#include < QDir>
9+ #include < QMessageBox>
910#include " Common/Cpp/PrettyPrint.h"
1011#include " Common/Cpp/Json/JsonArray.h"
1112#include " Common/Cpp/Json/JsonObject.h"
1213#include " CommonFramework/Globals.h"
1314#include " CommonFramework/GlobalSettingsPanel.h"
1415#include " CommonFramework/Logging/Logger.h"
1516#include " CommonFramework/Notifications/ProgramNotifications.h"
17+ #include " CommonFramework/Options/Environment/ThemeSelectorOption.h"
1618#include " ProgramDumper.h"
1719#include " ErrorReports.h"
1820
@@ -33,10 +35,22 @@ const std::string& ERROR_PATH_SENT = "ErrorReportsSent";
3335
3436
3537ErrorReportOption::ErrorReportOption ()
36- : GroupOption(" Error Reports" , LockMode::UNLOCK_WHILE_RUNNING, true )
38+ : GroupOption(" Error Reports" , LockMode::UNLOCK_WHILE_RUNNING, false )
3739 , DESCRIPTION(
3840 " Send error reports to the " + PROGRAM_NAME + " server to help them resolve issues and improve the program."
3941 )
42+ , SEND_MODE(
43+ " <b>When to Send Error Reports:</b>" ,
44+ {
45+ {ErrorReportSendMode::SEND_AUTOMATICALLY, " automatic" , " Send automatically." },
46+ {ErrorReportSendMode::PROMPT_WHEN_CONVENIENT, " prompt" , " Prompt when convenient." },
47+ {ErrorReportSendMode::NEVER_SEND_ANYTHING, " never" , " Never send error reports." },
48+ },
49+ LockMode::UNLOCK_WHILE_RUNNING,
50+ IS_BETA_VERSION
51+ ? ErrorReportSendMode::SEND_AUTOMATICALLY
52+ : ErrorReportSendMode::PROMPT_WHEN_CONVENIENT
53+ )
4054 , SCREENSHOT(
4155 " <b>Include Screenshots:</b>" ,
4256 LockMode::UNLOCK_WHILE_RUNNING,
@@ -48,7 +62,7 @@ ErrorReportOption::ErrorReportOption()
4862 true
4963 )
5064 , DUMPS(
51- " <b>Include Dumps:</b><br>This saves stack-trace and related information." ,
65+ " <b>Include Dumps:</b><br>Include stack-trace and related information." ,
5266 LockMode::UNLOCK_WHILE_RUNNING,
5367 true
5468 )
@@ -61,6 +75,7 @@ ErrorReportOption::ErrorReportOption()
6175#endif
6276{
6377 PA_ADD_STATIC (DESCRIPTION);
78+ PA_ADD_OPTION (SEND_MODE);
6479 PA_ADD_OPTION (SCREENSHOT);
6580 PA_ADD_OPTION (LOGS);
6681 PA_ADD_OPTION (DUMPS);
@@ -233,7 +248,10 @@ std::vector<std::string> SendableErrorReport::get_pending_reports(){
233248 }
234249 return ret;
235250}
236- void SendableErrorReport::send_reports (Logger& logger, const std::vector<std::string>& reports){
251+
252+
253+
254+ void send_reports (Logger& logger, const std::vector<std::string>& reports){
237255 for (const std::string& path : reports){
238256 try {
239257 SendableErrorReport report (path);
@@ -245,13 +263,50 @@ void SendableErrorReport::send_reports(Logger& logger, const std::vector<std::st
245263 }
246264 }
247265}
248- void SendableErrorReport:: send_all_unsent_reports (Logger& logger){
266+ void send_all_unsent_reports (Logger& logger, bool allow_prompt ){
249267#ifdef PA_OFFICIAL
250- if (GlobalSettings::instance ().ERROR_REPORTS .enabled ()){
251- std::vector<std::string> reports = SendableErrorReport::get_pending_reports ();
252- global_logger_tagged ().log (" Found " + std::to_string (reports.size ()) + " unsent error reports. Attempting to send..." , COLOR_PURPLE);
253- SendableErrorReport::send_reports (global_logger_tagged (), reports);
268+ ErrorReportSendMode mode = GlobalSettings::instance ().ERROR_REPORTS .SEND_MODE ;
269+ if (mode == ErrorReportSendMode::NEVER_SEND_ANYTHING){
270+ return ;
271+ }
272+
273+ std::vector<std::string> reports = SendableErrorReport::get_pending_reports ();
274+ global_logger_tagged ().log (" Found " + std::to_string (reports.size ()) + " unsent error reports." , COLOR_PURPLE);
275+
276+ if (reports.empty ()){
277+ return ;
254278 }
279+
280+ if (mode == ErrorReportSendMode::PROMPT_WHEN_CONVENIENT){
281+ if (!allow_prompt){
282+ return ;
283+ }
284+ QMessageBox box;
285+ QMessageBox::StandardButton button = box.information (
286+ nullptr ,
287+ " Error Reporting" ,
288+ QString::fromStdString (
289+ (reports.size () == 1
290+ ? " There is " + tostr_u_commas (reports.size ()) + " error report.<br><br>"
291+ " Would you like to help make this program better by sending it to the developers?<br><br>"
292+ : " There are " + tostr_u_commas (reports.size ()) + " error reports.<br><br>"
293+ " Would you like to help make this program better by sending them to the developers?<br><br>"
294+ ) +
295+ make_text_url (ERROR_PATH_UNSENT, " View unsent error reports." )// + "<br><br>"
296+ // "(You can change )"
297+ ),
298+ QMessageBox::Yes | QMessageBox::No,
299+ QMessageBox::StandardButton::Yes
300+ );
301+ if (button != QMessageBox::StandardButton::Yes){
302+ return ;
303+ }
304+ // cout << "asdfasdf" << button_yes << " : " << button_no << " : " << &button << endl; // REMOVE
305+ }
306+
307+ global_logger_tagged ().log (" Attempting to send " + std::to_string (reports.size ()) + " error reports." , COLOR_PURPLE);
308+ send_reports (global_logger_tagged (), reports);
309+
255310#endif
256311}
257312
@@ -284,7 +339,7 @@ void report_error(
284339 report.save (logger);
285340 }
286341
287- SendableErrorReport:: send_all_unsent_reports (*logger);
342+ send_all_unsent_reports (*logger, false );
288343}
289344
290345
0 commit comments