Skip to content

Commit c4c8f0b

Browse files
committed
Implement error reporting prompt.
1 parent ec036e7 commit c4c8f0b

File tree

4 files changed

+83
-13
lines changed

4 files changed

+83
-13
lines changed

SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.cpp

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
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

3537
ErrorReportOption::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

SerialPrograms/Source/CommonFramework/ErrorReports/ErrorReports.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Common/Cpp/Options/GroupOption.h"
1212
#include "Common/Cpp/Options/StaticTextOption.h"
1313
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
14+
#include "Common/Cpp/Options/EnumDropdownOption.h"
1415
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
1516
#include "CommonFramework/ImageTypes/ImageRGB32.h"
1617
#include "CommonFramework/Notifications/ProgramInfo.h"
@@ -24,12 +25,20 @@ extern const std::string& ERROR_PATH_UNSENT;
2425
extern const std::string& ERROR_PATH_SENT;
2526

2627

28+
enum class ErrorReportSendMode{
29+
SEND_AUTOMATICALLY,
30+
PROMPT_WHEN_CONVENIENT,
31+
NEVER_SEND_ANYTHING,
32+
};
2733

2834
class ErrorReportOption : public GroupOption{
2935
public:
3036
ErrorReportOption();
3137

3238
StaticTextOption DESCRIPTION;
39+
40+
EnumDropdownOption<ErrorReportSendMode> SEND_MODE;
41+
3342
BooleanCheckBoxOption SCREENSHOT;
3443
BooleanCheckBoxOption LOGS;
3544
BooleanCheckBoxOption DUMPS;
@@ -65,8 +74,6 @@ class SendableErrorReport{
6574
void move_to_sent();
6675

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

7178
private:
7279
std::string m_timestamp;
@@ -82,6 +89,9 @@ class SendableErrorReport{
8289
};
8390

8491

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

8696
void report_error(
8797
Logger* logger = nullptr,
@@ -93,6 +103,11 @@ void report_error(
93103
);
94104

95105

106+
107+
108+
109+
110+
96111
}
97112

98113
#endif

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace PokemonAutomation{
2525
const bool IS_BETA_VERSION = true;
2626
const int PROGRAM_VERSION_MAJOR = 0;
2727
const int PROGRAM_VERSION_MINOR = 50;
28-
const int PROGRAM_VERSION_PATCH = 6;
28+
const int PROGRAM_VERSION_PATCH = 7;
2929

3030
const std::string PROGRAM_VERSION_BASE =
3131
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +

SerialPrograms/Source/CommonFramework/Main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int main(int argc, char *argv[]){
109109
}
110110

111111
set_working_directory();
112-
SendableErrorReport::send_all_unsent_reports(global_logger_tagged());
112+
send_all_unsent_reports(global_logger_tagged(), true);
113113

114114
int ret = 0;
115115
{

0 commit comments

Comments
 (0)