Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ option(IMHEX_ENABLE_PRECOMPILED_HEADERS "Enable precompiled headers"
option(IMHEX_ENABLE_CXX_MODULES "Enable C++20 Module compilation. Testing only!" OFF)
option(IMHEX_ENABLE_CPPCHECK "Enable cppcheck static analysis" OFF)
option(IMHEX_BUNDLE_PLUGIN_SDK "Enable bundling of Plugin SDK into install package" ON )
option(IMHEX_ENABLE_UPDATER "Enable automatic updater" ON )
## Testing
option(IMHEX_ENABLE_UNIT_TESTS "Enable building unit tests" ON )
option(IMHEX_ENABLE_IMGUI_TEST_ENGINE "Enable the ImGui Test Engine" OFF)
Expand Down
4 changes: 4 additions & 0 deletions cmake/build_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ macro(addDefines)
if (IMHEX_STATIC_LINK_PLUGINS)
add_compile_definitions(IMHEX_STATIC_LINK_PLUGINS)
endif ()

if (IMHEX_ENABLE_UPDATER)
add_compile_definitions(IMHEX_ENABLE_UPDATER)
endif()
endmacro()

function(addDefineToSource SOURCE DEFINE)
Expand Down
6 changes: 4 additions & 2 deletions lib/libimhex/source/api/imhex_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ namespace hex {
}

std::optional<std::string> checkForUpdate() {
#if defined(OS_WEB)
#if defined(OS_WEB) || !defined(IMHEX_ENABLE_UPDATER)
return std::nullopt;
#else
if (ImHexApi::System::isNightlyBuild()) {
Expand Down Expand Up @@ -1034,7 +1034,9 @@ namespace hex {
}

bool updateImHex(UpdateType updateType) {
#if defined(OS_WEB)
#if !defined(IMHEX_ENABLE_UPDATER)
return false;
#elif defined(OS_WEB)
switch (updateType) {
case UpdateType::Stable:
EM_ASM({ window.location.href = window.location.origin; });
Expand Down
2 changes: 1 addition & 1 deletion main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ if (WIN32)
add_subdirectory(forwarder)
endif ()

if (NOT EMSCRIPTEN)
if (IMHEX_ENABLE_UPDATER AND NOT EMSCRIPTEN)
add_subdirectory(updater)
endif ()
382 changes: 197 additions & 185 deletions main/updater/source/main.cpp

Large diffs are not rendered by default.

126 changes: 65 additions & 61 deletions plugins/builtin/source/content/init_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,75 +25,77 @@ namespace hex::plugin::builtin {

using namespace std::literals::string_literals;

bool checkForUpdatesSync() {
int checkForUpdates = ContentRegistry::Settings::read<int>("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 2);
if (checkForUpdates != 1)
return true;
#if defined(IMHEX_ENABLE_UPDATER)
bool checkForUpdatesSync() {
int checkForUpdates = ContentRegistry::Settings::read<int>("hex.builtin.setting.general", "hex.builtin.setting.general.server_contact", 2);
if (checkForUpdates != 1)
return true;

// Check if we should check for updates
TaskManager::createBackgroundTask("Update Check", [] {
const auto updateString = ImHexApi::System::checkForUpdate();

// Check if we should check for updates
TaskManager::createBackgroundTask("Update Check", [] {
const auto updateString = ImHexApi::System::checkForUpdate();
if (!updateString.has_value())
return;

if (!updateString.has_value())
return;
TaskManager::doLater([updateString] {
ContentRegistry::UserInterface::addTitleBarButton(ICON_TA_DOWNLOAD, ImGuiCustomCol_ToolbarGreen, "hex.builtin.welcome.update.title", [] {
ImHexApi::System::updateImHex(ImHexApi::System::isNightlyBuild() ? ImHexApi::System::UpdateType::Nightly : ImHexApi::System::UpdateType::Stable);
});

TaskManager::doLater([updateString] {
ContentRegistry::UserInterface::addTitleBarButton(ICON_TA_DOWNLOAD, ImGuiCustomCol_ToolbarGreen, "hex.builtin.welcome.update.title", [] {
ImHexApi::System::updateImHex(ImHexApi::System::isNightlyBuild() ? ImHexApi::System::UpdateType::Nightly : ImHexApi::System::UpdateType::Stable);
ui::ToastInfo::open(fmt::format("hex.builtin.welcome.update.desc"_lang, *updateString));
});
});

ui::ToastInfo::open(fmt::format("hex.builtin.welcome.update.desc"_lang, *updateString));
// Check if there is a telemetry uuid
auto uuid = ContentRegistry::Settings::read<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.uuid", "");
if (uuid.empty()) {
// Generate a new uuid
uuid = wolv::hash::generateUUID();
// Save
ContentRegistry::Settings::write<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.uuid", uuid);
}

TaskManager::createBackgroundTask("hex.builtin.task.sending_statistics", [uuid](auto&) {
// To avoid potentially flooding our database with lots of dead users
// from people just visiting the website, don't send telemetry data from
// the web version
#if defined(OS_WEB)
return;
#endif

// Make telemetry request
nlohmann::json telemetry = {
{ "uuid", uuid },
{ "format_version", "1" },
{ "imhex_version", ImHexApi::System::getImHexVersion().get(false) },
{ "imhex_commit", fmt::format("{}@{}", ImHexApi::System::getCommitHash(true), ImHexApi::System::getCommitBranch()) },
{ "install_type", ImHexApi::System::isPortableVersion() ? "Portable" : "Installed" },
{ "os", ImHexApi::System::getOSName() },
{ "os_version", ImHexApi::System::getOSVersion() },
{ "arch", ImHexApi::System::getArchitecture() },
{ "gpu_vendor", ImHexApi::System::getGPUVendor() },
{ "corporate_env", ImHexApi::System::isCorporateEnvironment() }
};

HttpRequest telemetryRequest("POST", ImHexApiURL + "/telemetry"s);
telemetryRequest.setTimeout(500);

telemetryRequest.setBody(telemetry.dump());
telemetryRequest.addHeader("Content-Type", "application/json");

// Execute request
telemetryRequest.execute();
});
});

// Check if there is a telemetry uuid
auto uuid = ContentRegistry::Settings::read<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.uuid", "");
if (uuid.empty()) {
// Generate a new uuid
uuid = wolv::hash::generateUUID();
// Save
ContentRegistry::Settings::write<std::string>("hex.builtin.setting.general", "hex.builtin.setting.general.uuid", uuid);
return true;
}

TaskManager::createBackgroundTask("hex.builtin.task.sending_statistics", [uuid](auto&) {
// To avoid potentially flooding our database with lots of dead users
// from people just visiting the website, don't send telemetry data from
// the web version
#if defined(OS_WEB)
return;
#endif

// Make telemetry request
nlohmann::json telemetry = {
{ "uuid", uuid },
{ "format_version", "1" },
{ "imhex_version", ImHexApi::System::getImHexVersion().get(false) },
{ "imhex_commit", fmt::format("{}@{}", ImHexApi::System::getCommitHash(true), ImHexApi::System::getCommitBranch()) },
{ "install_type", ImHexApi::System::isPortableVersion() ? "Portable" : "Installed" },
{ "os", ImHexApi::System::getOSName() },
{ "os_version", ImHexApi::System::getOSVersion() },
{ "arch", ImHexApi::System::getArchitecture() },
{ "gpu_vendor", ImHexApi::System::getGPUVendor() },
{ "corporate_env", ImHexApi::System::isCorporateEnvironment() }
};

HttpRequest telemetryRequest("POST", ImHexApiURL + "/telemetry"s);
telemetryRequest.setTimeout(500);

telemetryRequest.setBody(telemetry.dump());
telemetryRequest.addHeader("Content-Type", "application/json");

// Execute request
telemetryRequest.execute();
});

return true;
}

bool checkForUpdates() {
TaskManager::createBackgroundTask("hex.builtin.task.check_updates", [](auto&) { checkForUpdatesSync(); });
return true;
}
bool checkForUpdates() {
TaskManager::createBackgroundTask("hex.builtin.task.check_updates", [](auto&) { checkForUpdatesSync(); });
return true;
}
#endif

bool configureUIScale() {
EventDPIChanged::subscribe([](float, float newScaling) {
Expand Down Expand Up @@ -140,6 +142,8 @@ namespace hex::plugin::builtin {
void addInitTasks() {
ImHexApi::System::addStartupTask("Load Window Settings", false, loadWindowSettings);
ImHexApi::System::addStartupTask("Configuring UI scale", false, configureUIScale);
ImHexApi::System::addStartupTask("Checking for updates", true, checkForUpdates);
#if defined(IMHEX_ENABLE_UPDATER)
ImHexApi::System::addStartupTask("Checking for updates", true, checkForUpdates);
#endif
}
}
42 changes: 22 additions & 20 deletions plugins/builtin/source/content/main_menu_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,29 +670,31 @@ namespace hex::plugin::builtin {

ContentRegistry::UserInterface::addMenuItemSeparator({ "hex.builtin.menu.extras" }, 2600);

ContentRegistry::UserInterface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.menu.extras.check_for_update" }, ICON_VS_SYNC, 2700, Shortcut::None, [] {
TaskManager::createBackgroundTask("Checking for updates", [] {
auto versionString = ImHexApi::System::checkForUpdate();
if (!versionString.has_value()) {
ui::ToastInfo::open("hex.builtin.popup.no_update_available"_lang);
return;
}
#if defined(IMHEX_ENABLE_UPDATER)
ContentRegistry::UserInterface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.menu.extras.check_for_update" }, ICON_VS_SYNC, 2700, Shortcut::None, [] {
TaskManager::createBackgroundTask("Checking for updates", [] {
auto versionString = ImHexApi::System::checkForUpdate();
if (!versionString.has_value()) {
ui::ToastInfo::open("hex.builtin.popup.no_update_available"_lang);
return;
}

ui::PopupQuestion::open(fmt::format(fmt::runtime("hex.builtin.popup.update_available"_lang.get()), versionString.value()), [] {
ImHexApi::System::updateImHex(ImHexApi::System::isNightlyBuild() ? ImHexApi::System::UpdateType::Nightly : ImHexApi::System::UpdateType::Stable);
}, [] { });
ui::PopupQuestion::open(fmt::format(fmt::runtime("hex.builtin.popup.update_available"_lang.get()), versionString.value()), [] {
ImHexApi::System::updateImHex(ImHexApi::System::isNightlyBuild() ? ImHexApi::System::UpdateType::Nightly : ImHexApi::System::UpdateType::Stable);
}, [] { });
});
});
});

if (ImHexApi::System::isNightlyBuild()) {
ContentRegistry::UserInterface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.menu.extras.switch_to_stable" }, ICON_VS_ROCKET, 2750, Shortcut::None, [] {
ImHexApi::System::updateImHex(ImHexApi::System::UpdateType::Stable);
});
} else {
ContentRegistry::UserInterface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.menu.extras.switch_to_nightly" }, ICON_VS_ROCKET, 2750, Shortcut::None, [] {
ImHexApi::System::updateImHex(ImHexApi::System::UpdateType::Nightly);
});
}
if (ImHexApi::System::isNightlyBuild()) {
ContentRegistry::UserInterface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.menu.extras.switch_to_stable" }, ICON_VS_ROCKET, 2750, Shortcut::None, [] {
ImHexApi::System::updateImHex(ImHexApi::System::UpdateType::Stable);
});
} else {
ContentRegistry::UserInterface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.menu.extras.switch_to_nightly" }, ICON_VS_ROCKET, 2750, Shortcut::None, [] {
ImHexApi::System::updateImHex(ImHexApi::System::UpdateType::Nightly);
});
}
#endif
}

static void createHelpMenu() {
Expand Down