feat: Ask the users if they want to check for updates (#803)

* ask the users for updates

* Only treat 1 as enabled

* Fix formatting

* update locales

* comment to document value
This commit is contained in:
iTrooz_
2022-10-29 23:43:40 +02:00
committed by GitHub
parent 2826e6f325
commit bececff9e5
11 changed files with 71 additions and 12 deletions

View File

@@ -25,23 +25,27 @@ namespace hex::init {
using namespace std::literals::string_literals;
static bool checkForUpdates() {
hex::Net net;
// documentation of the value above the setting definition
int showCheckForUpdates = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.check_for_updates", 2);
if (showCheckForUpdates == 1){
hex::Net net;
auto releases = net.getJson(GitHubApiURL + "/releases/latest"s, 2000).get();
if (releases.code != 200)
return false;
auto releases = net.getJson(GitHubApiURL + "/releases/latest"s, 2000).get();
if (releases.code != 200)
return false;
if (!releases.body.contains("tag_name") || !releases.body["tag_name"].is_string())
return false;
if (!releases.body.contains("tag_name") || !releases.body["tag_name"].is_string())
return false;
auto versionString = std::string(IMHEX_VERSION);
size_t versionLength = std::min(versionString.find_first_of('-'), versionString.length());
auto currVersion = "v" + versionString.substr(0, versionLength);
auto latestVersion = releases.body["tag_name"].get<std::string_view>();
auto versionString = std::string(IMHEX_VERSION);
size_t versionLength = std::min(versionString.find_first_of('-'), versionString.length());
auto currVersion = "v" + versionString.substr(0, versionLength);
auto latestVersion = releases.body["tag_name"].get<std::string_view>();
if (latestVersion != currVersion)
ImHexApi::System::impl::addInitArgument("update-available", latestVersion.data());
if (latestVersion != currVersion)
ImHexApi::System::impl::addInitArgument("update-available", latestVersion.data());
}
return true;
}