@@ -25,75 +25,77 @@ namespace hex::plugin::builtin {
2525
2626 using namespace std ::literals::string_literals;
2727
28- bool checkForUpdatesSync () {
29- int checkForUpdates = ContentRegistry::Settings::read<int >(" hex.builtin.setting.general" , " hex.builtin.setting.general.server_contact" , 2 );
30- if (checkForUpdates != 1 )
31- return true ;
28+ #if defined(IMHEX_ENABLE_UPDATER)
29+ bool checkForUpdatesSync () {
30+ int checkForUpdates = ContentRegistry::Settings::read<int >(" hex.builtin.setting.general" , " hex.builtin.setting.general.server_contact" , 2 );
31+ if (checkForUpdates != 1 )
32+ return true ;
33+
34+ // Check if we should check for updates
35+ TaskManager::createBackgroundTask (" Update Check" , [] {
36+ const auto updateString = ImHexApi::System::checkForUpdate ();
3237
33- // Check if we should check for updates
34- TaskManager::createBackgroundTask (" Update Check" , [] {
35- const auto updateString = ImHexApi::System::checkForUpdate ();
38+ if (!updateString.has_value ())
39+ return ;
3640
37- if (!updateString.has_value ())
38- return ;
41+ TaskManager::doLater ([updateString] {
42+ ContentRegistry::UserInterface::addTitleBarButton (ICON_TA_DOWNLOAD, ImGuiCustomCol_ToolbarGreen, " hex.builtin.welcome.update.title" , [] {
43+ ImHexApi::System::updateImHex (ImHexApi::System::isNightlyBuild () ? ImHexApi::System::UpdateType::Nightly : ImHexApi::System::UpdateType::Stable);
44+ });
3945
40- TaskManager::doLater ([updateString] {
41- ContentRegistry::UserInterface::addTitleBarButton (ICON_TA_DOWNLOAD, ImGuiCustomCol_ToolbarGreen, " hex.builtin.welcome.update.title" , [] {
42- ImHexApi::System::updateImHex (ImHexApi::System::isNightlyBuild () ? ImHexApi::System::UpdateType::Nightly : ImHexApi::System::UpdateType::Stable);
46+ ui::ToastInfo::open (fmt::format (" hex.builtin.welcome.update.desc" _lang, *updateString));
4347 });
48+ });
4449
45- ui::ToastInfo::open (fmt::format (" hex.builtin.welcome.update.desc" _lang, *updateString));
50+ // Check if there is a telemetry uuid
51+ auto uuid = ContentRegistry::Settings::read<std::string>(" hex.builtin.setting.general" , " hex.builtin.setting.general.uuid" , " " );
52+ if (uuid.empty ()) {
53+ // Generate a new uuid
54+ uuid = wolv::hash::generateUUID ();
55+ // Save
56+ ContentRegistry::Settings::write<std::string>(" hex.builtin.setting.general" , " hex.builtin.setting.general.uuid" , uuid);
57+ }
58+
59+ TaskManager::createBackgroundTask (" hex.builtin.task.sending_statistics" , [uuid](auto &) {
60+ // To avoid potentially flooding our database with lots of dead users
61+ // from people just visiting the website, don't send telemetry data from
62+ // the web version
63+ #if defined(OS_WEB)
64+ return ;
65+ #endif
66+
67+ // Make telemetry request
68+ nlohmann::json telemetry = {
69+ { " uuid" , uuid },
70+ { " format_version" , " 1" },
71+ { " imhex_version" , ImHexApi::System::getImHexVersion ().get (false ) },
72+ { " imhex_commit" , fmt::format (" {}@{}" , ImHexApi::System::getCommitHash (true ), ImHexApi::System::getCommitBranch ()) },
73+ { " install_type" , ImHexApi::System::isPortableVersion () ? " Portable" : " Installed" },
74+ { " os" , ImHexApi::System::getOSName () },
75+ { " os_version" , ImHexApi::System::getOSVersion () },
76+ { " arch" , ImHexApi::System::getArchitecture () },
77+ { " gpu_vendor" , ImHexApi::System::getGPUVendor () },
78+ { " corporate_env" , ImHexApi::System::isCorporateEnvironment () }
79+ };
80+
81+ HttpRequest telemetryRequest (" POST" , ImHexApiURL + " /telemetry" s);
82+ telemetryRequest.setTimeout (500 );
83+
84+ telemetryRequest.setBody (telemetry.dump ());
85+ telemetryRequest.addHeader (" Content-Type" , " application/json" );
86+
87+ // Execute request
88+ telemetryRequest.execute ();
4689 });
47- });
4890
49- // Check if there is a telemetry uuid
50- auto uuid = ContentRegistry::Settings::read<std::string>(" hex.builtin.setting.general" , " hex.builtin.setting.general.uuid" , " " );
51- if (uuid.empty ()) {
52- // Generate a new uuid
53- uuid = wolv::hash::generateUUID ();
54- // Save
55- ContentRegistry::Settings::write<std::string>(" hex.builtin.setting.general" , " hex.builtin.setting.general.uuid" , uuid);
91+ return true ;
5692 }
5793
58- TaskManager::createBackgroundTask (" hex.builtin.task.sending_statistics" , [uuid](auto &) {
59- // To avoid potentially flooding our database with lots of dead users
60- // from people just visiting the website, don't send telemetry data from
61- // the web version
62- #if defined(OS_WEB)
63- return ;
64- #endif
65-
66- // Make telemetry request
67- nlohmann::json telemetry = {
68- { " uuid" , uuid },
69- { " format_version" , " 1" },
70- { " imhex_version" , ImHexApi::System::getImHexVersion ().get (false ) },
71- { " imhex_commit" , fmt::format (" {}@{}" , ImHexApi::System::getCommitHash (true ), ImHexApi::System::getCommitBranch ()) },
72- { " install_type" , ImHexApi::System::isPortableVersion () ? " Portable" : " Installed" },
73- { " os" , ImHexApi::System::getOSName () },
74- { " os_version" , ImHexApi::System::getOSVersion () },
75- { " arch" , ImHexApi::System::getArchitecture () },
76- { " gpu_vendor" , ImHexApi::System::getGPUVendor () },
77- { " corporate_env" , ImHexApi::System::isCorporateEnvironment () }
78- };
79-
80- HttpRequest telemetryRequest (" POST" , ImHexApiURL + " /telemetry" s);
81- telemetryRequest.setTimeout (500 );
82-
83- telemetryRequest.setBody (telemetry.dump ());
84- telemetryRequest.addHeader (" Content-Type" , " application/json" );
85-
86- // Execute request
87- telemetryRequest.execute ();
88- });
89-
90- return true ;
91- }
92-
93- bool checkForUpdates () {
94- TaskManager::createBackgroundTask (" hex.builtin.task.check_updates" , [](auto &) { checkForUpdatesSync (); });
95- return true ;
96- }
94+ bool checkForUpdates () {
95+ TaskManager::createBackgroundTask (" hex.builtin.task.check_updates" , [](auto &) { checkForUpdatesSync (); });
96+ return true ;
97+ }
98+ #endif
9799
98100 bool configureUIScale () {
99101 EventDPIChanged::subscribe ([](float , float newScaling) {
@@ -140,6 +142,8 @@ namespace hex::plugin::builtin {
140142 void addInitTasks () {
141143 ImHexApi::System::addStartupTask (" Load Window Settings" , false , loadWindowSettings);
142144 ImHexApi::System::addStartupTask (" Configuring UI scale" , false , configureUIScale);
143- ImHexApi::System::addStartupTask (" Checking for updates" , true , checkForUpdates);
145+ #if defined(IMHEX_ENABLE_UPDATER)
146+ ImHexApi::System::addStartupTask (" Checking for updates" , true , checkForUpdates);
147+ #endif
144148 }
145149}
0 commit comments