Skip to content

Commit 4e14d4f

Browse files
committed
Split up the check for update categories.
1 parent 750dc0d commit 4e14d4f

File tree

7 files changed

+123
-46
lines changed

7 files changed

+123
-46
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ file(GLOB MAIN_SOURCES
375375
Source/CommonFramework/Options/Environment/SleepSuppressOption.h
376376
Source/CommonFramework/Options/Environment/ThemeSelectorOption.cpp
377377
Source/CommonFramework/Options/Environment/ThemeSelectorOption.h
378+
Source/CommonFramework/Options/CheckForUpdatesOption.h
378379
Source/CommonFramework/Options/LabelCellOption.cpp
379380
Source/CommonFramework/Options/LabelCellOption.h
380381
Source/CommonFramework/Options/ResolutionOption.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,7 @@ HEADERS += \
13151315
Source/CommonFramework/Notifications/ProgramInfo.h \
13161316
Source/CommonFramework/Notifications/ProgramNotifications.h \
13171317
Source/CommonFramework/Notifications/SenderNotificationTable.h \
1318+
Source/CommonFramework/Options/CheckForUpdatesOption.h \
13181319
Source/CommonFramework/Options/Environment/PerformanceOptions.h \
13191320
Source/CommonFramework/Options/Environment/ProcessPriorityOption.h \
13201321
Source/CommonFramework/Options/Environment/ProcessorLevelOption.h \

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Common/Cpp/Json/JsonArray.h"
1414
#include "Common/Cpp/Json/JsonObject.h"
1515
#include "CommonFramework/Globals.h"
16+
#include "CommonFramework/Options/CheckForUpdatesOption.h"
1617
#include "CommonFramework/Options/ResolutionOption.h"
1718
#include "CommonFramework/Options/Environment/SleepSuppressOption.h"
1819
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
@@ -100,11 +101,7 @@ GlobalSettings::~GlobalSettings(){
100101
}
101102
GlobalSettings::GlobalSettings()
102103
: BatchOption(LockMode::LOCK_WHILE_RUNNING)
103-
, CHECK_FOR_UPDATES(
104-
"<b>Check for Updates:</b><br>Automatically check for updates.",
105-
LockMode::UNLOCK_WHILE_RUNNING,
106-
true
107-
)
104+
, CHECK_FOR_UPDATES(CONSTRUCT_TOKEN)
108105
, STATS_FILE(
109106
false,
110107
"<b>Stats File:</b><br>Use the stats file here. Multiple instances of the program can use the same file.",

SerialPrograms/Source/CommonFramework/GlobalSettingsPanel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace PokemonAutomation{
2525

26-
26+
class CheckForUpdatesOption;
2727
class ThemeSelectorOption;
2828
class ResolutionOption;
2929
class StreamHistoryOption;
@@ -37,6 +37,8 @@ class VideoPipelineOptions;
3737
class ErrorReportOption;
3838

3939

40+
41+
4042
class FolderInputOption : public StringOption{
4143
public:
4244
using StringOption::StringOption;
@@ -49,8 +51,6 @@ class FolderInputOption : public StringOption{
4951
};
5052

5153

52-
53-
5454
struct DebugSettings{
5555
bool COLOR_CHECK = false;
5656
bool IMAGE_TEMPLATE_MATCHING = false;
@@ -89,7 +89,7 @@ class GlobalSettings : public BatchOption, private ConfigOption::Listener{
8989
virtual void value_changed(void* object) override;
9090

9191
public:
92-
BooleanCheckBoxOption CHECK_FOR_UPDATES;
92+
Pimpl<CheckForUpdatesOption> CHECK_FOR_UPDATES;
9393

9494
StringOption STATS_FILE;
9595
FolderInputOption TEMP_FOLDER;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* Check for Updates Option
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_Options_CheckForUpdatesOption_H
8+
#define PokemonAutomation_Options_CheckForUpdatesOption_H
9+
10+
#include "Common/Cpp/Options/GroupOption.h"
11+
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
12+
#include "CommonFramework/Globals.h"
13+
14+
namespace PokemonAutomation{
15+
16+
17+
class CheckForUpdatesOption : public GroupOption{
18+
public:
19+
CheckForUpdatesOption()
20+
: GroupOption(
21+
"Check for Updates",
22+
LockMode::UNLOCK_WHILE_RUNNING,
23+
EnableMode::ALWAYS_ENABLED,
24+
false
25+
)
26+
, RELEASE(
27+
"<b>New Releases:</b><br>Automatically check for new stable releases.",
28+
LockMode::UNLOCK_WHILE_RUNNING,
29+
true
30+
)
31+
, BETA(
32+
"<b>Public Betas:</b><br>Automatically check for new public betas.",
33+
LockMode::UNLOCK_WHILE_RUNNING,
34+
IS_BETA_VERSION
35+
)
36+
, PRIVATE_BETA(
37+
"<b>Private Betas:</b><br>Automatically check for new private betas.",
38+
LockMode::UNLOCK_WHILE_RUNNING,
39+
IS_BETA_VERSION
40+
)
41+
{
42+
PA_ADD_OPTION(RELEASE);
43+
PA_ADD_OPTION(BETA);
44+
if (IS_BETA_VERSION){
45+
PA_ADD_OPTION(PRIVATE_BETA);
46+
}
47+
}
48+
49+
public:
50+
BooleanCheckBoxOption RELEASE;
51+
BooleanCheckBoxOption BETA;
52+
BooleanCheckBoxOption PRIVATE_BETA;
53+
};
54+
55+
56+
}
57+
#endif

SerialPrograms/Source/CommonFramework/Options/LabelCellOption.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "Common/Cpp/Containers/Pimpl.h"
1212
#include "Common/Cpp/Options/ConfigOption.h"
1313
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
14-
#include "CommonFramework/ImageTypes/ImageRGB32.h"
14+
//#include "CommonFramework/ImageTypes/ImageRGB32.h"
1515

1616
namespace PokemonAutomation{
1717

SerialPrograms/Source/CommonFramework/Startup/NewVersionCheck.cpp

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Common/Cpp/Time.h"
99
#include "Common/Cpp/Json/JsonObject.h"
1010
#include "CommonFramework/Exceptions/OperationFailedException.h"
11+
#include "CommonFramework/Options/CheckForUpdatesOption.h"
1112
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
1213
#include "CommonFramework/Tools/FileDownloader.h"
1314
#include "CommonFramework/Globals.h"
@@ -66,18 +67,24 @@ bool compare_version(Logger& logger, const JsonObject* json){
6667
return false;
6768
}
6869
void check_new_version(Logger& logger){
69-
if (!GlobalSettings::instance().CHECK_FOR_UPDATES){
70+
bool check_release = GlobalSettings::instance().CHECK_FOR_UPDATES->RELEASE;
71+
bool check_beta = GlobalSettings::instance().CHECK_FOR_UPDATES->BETA;
72+
bool check_private_beta = GlobalSettings::instance().CHECK_FOR_UPDATES->PRIVATE_BETA;
73+
bool updates_enabled = false;
74+
updates_enabled |= check_release;
75+
updates_enabled |= check_beta;
76+
updates_enabled |= check_private_beta;
77+
78+
if (!updates_enabled){
7079
return;
7180
}
7281

7382
static WallClock last_version_check = WallClock::min();
74-
// static size_t check_count = 0;
7583
WallClock now = current_time();
7684
if (last_version_check != WallClock::min() && now - last_version_check < CHECK_FOR_UPDATES_PERIOD){
7785
return;
7886
}
7987
last_version_check = now;
80-
// check_count++;
8188

8289
logger.log("Checking for new version...");
8390
JsonValue json;
@@ -89,48 +96,62 @@ void check_new_version(Logger& logger){
8996
}catch (OperationFailedException&){
9097
return;
9198
}
92-
93-
// cout << json.dump() << endl;
94-
9599
const JsonObject* obj = json.to_object();
96100
if (obj == nullptr){
97101
logger.log("Invalid version JSON.", COLOR_RED);
98102
return;
99103
}
100104

101-
const JsonObject* release = obj->get_object("Release");
102-
if (compare_version(logger, release)){
103-
QMessageBox box;
104-
box.setTextFormat(Qt::RichText);
105-
box.information(
106-
nullptr,
107-
"New Version Available!",
108-
QString::fromStdString(
109-
"A new version is available!<br>" +
110-
make_text_url("https://github.com/PokemonAutomation/ComputerControl/releases", "Download here.")
111-
)
112-
);
113-
return;
114-
}
115105

116-
if (!IS_BETA_VERSION){
117-
return;
106+
if (check_private_beta){
107+
const JsonObject* node = obj->get_object("PrivateBeta");
108+
if (compare_version(logger, node)){
109+
QMessageBox box;
110+
box.setTextFormat(Qt::RichText);
111+
box.information(
112+
nullptr,
113+
"A new private beta is available!",
114+
QString::fromStdString(
115+
"A new private beta is available!<br>" +
116+
make_text_url("https://discord.com/channels/695809740428673034/732736538965704726", "Download from our Discord!")
117+
)
118+
);
119+
return;
120+
}
121+
}
122+
if (check_beta){
123+
const JsonObject* node = obj->get_object("Beta");
124+
if (compare_version(logger, node)){
125+
QMessageBox box;
126+
box.setTextFormat(Qt::RichText);
127+
box.information(
128+
nullptr,
129+
"A new beta is available!",
130+
QString::fromStdString(
131+
"A new beta is available!<br>" +
132+
make_text_url("https://github.com/PokemonAutomation/ComputerControl/releases", "Download here.")
133+
)
134+
);
135+
return;
136+
}
137+
}
138+
if (check_release){
139+
const JsonObject* node = obj->get_object("Release");
140+
if (compare_version(logger, node)){
141+
QMessageBox box;
142+
box.setTextFormat(Qt::RichText);
143+
box.information(
144+
nullptr,
145+
"New Version Available!",
146+
QString::fromStdString(
147+
"A new version is available!<br>" +
148+
make_text_url("https://github.com/PokemonAutomation/ComputerControl/releases", "Download here.")
149+
)
150+
);
151+
return;
152+
}
118153
}
119154

120-
const JsonObject* beta = obj->get_object("Beta");
121-
if (compare_version(logger, beta)){
122-
QMessageBox box;
123-
box.setTextFormat(Qt::RichText);
124-
box.information(
125-
nullptr,
126-
"New Beta Available!",
127-
QString::fromStdString(
128-
"A new beta is available!<br>" +
129-
make_text_url("https://discord.com/channels/695809740428673034/732736538965704726", "Download from our Discord!")
130-
)
131-
);
132-
return;
133-
}
134155
}
135156

136157

0 commit comments

Comments
 (0)